Spaces:
Running
Running
andykr1k commited on
Commit ·
4a8ece4
1
Parent(s): b701a8e
added tag notifications
Browse files
main.py
CHANGED
|
@@ -92,6 +92,30 @@ def send_notification(title, body, token, id, post_id, notif_type):
|
|
| 92 |
except requests.exceptions.RequestException as e:
|
| 93 |
print(f'Failed to send notification: {e}')
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
def handle_listlikes_update(event_payload):
|
| 97 |
print('Received update in listlikes:')
|
|
@@ -325,6 +349,10 @@ def setup_likes_subscription(SUPABASE_ID, SUPABASE_KEY):
|
|
| 325 |
channel_posts.join().on(
|
| 326 |
"INSERT", lambda payload: executor.submit(handle_groupreviewrequests_update, payload))
|
| 327 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
s.listen()
|
| 329 |
|
| 330 |
except Exception as e:
|
|
|
|
| 92 |
except requests.exceptions.RequestException as e:
|
| 93 |
print(f'Failed to send notification: {e}')
|
| 94 |
|
| 95 |
+
def handle_tags_update(event_payload):
|
| 96 |
+
print('Received update in post tags:')
|
| 97 |
+
print(event_payload)
|
| 98 |
+
|
| 99 |
+
record = event_payload['record']
|
| 100 |
+
tags_str = record.get('tags', '[]')
|
| 101 |
+
try:
|
| 102 |
+
tagged_user_ids = json.loads(tags_str)
|
| 103 |
+
except json.JSONDecodeError:
|
| 104 |
+
print('Failed to parse tags.')
|
| 105 |
+
return
|
| 106 |
+
|
| 107 |
+
author_id = record['author_id']
|
| 108 |
+
username = getUsername(author_id).lower()
|
| 109 |
+
title = 'Picturelock'
|
| 110 |
+
body = f'@{username} tagged you in a post!'
|
| 111 |
+
post_id = record['id']
|
| 112 |
+
|
| 113 |
+
for tagged_user_id in tagged_user_ids:
|
| 114 |
+
if tagged_user_id != author_id:
|
| 115 |
+
token = getAuthorNotifToken(tagged_user_id)
|
| 116 |
+
if token:
|
| 117 |
+
send_notification(title, body, token, author_id, post_id, "post")
|
| 118 |
+
|
| 119 |
|
| 120 |
def handle_listlikes_update(event_payload):
|
| 121 |
print('Received update in listlikes:')
|
|
|
|
| 349 |
channel_posts.join().on(
|
| 350 |
"INSERT", lambda payload: executor.submit(handle_groupreviewrequests_update, payload))
|
| 351 |
|
| 352 |
+
channel_posts_for_tags = s.set_channel("realtime:public:posts")
|
| 353 |
+
channel_posts_for_tags.join().on(
|
| 354 |
+
"INSERT", lambda payload: executor.submit(handle_tags_update, payload))
|
| 355 |
+
|
| 356 |
s.listen()
|
| 357 |
|
| 358 |
except Exception as e:
|