andykr1k commited on
Commit
c67b004
·
1 Parent(s): 4ca084f

Adding Notif Service Docker Container

Browse files
Files changed (4) hide show
  1. .gitignore +436 -0
  2. Dockerfile +5 -0
  3. main.py +334 -0
  4. requirements.txt +25 -0
.gitignore ADDED
@@ -0,0 +1,436 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Python ###
2
+ # Byte-compiled / optimized / DLL files
3
+ __pycache__/
4
+ *.py[cod]
5
+ *$py.class
6
+
7
+ # C extensions
8
+ *.so
9
+
10
+ # Distribution / packaging
11
+ .Python
12
+ build/
13
+ develop-eggs/
14
+ dist/
15
+ downloads/
16
+ eggs/
17
+ .eggs/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ #.idea/
161
+
162
+ ### Python Patch ###
163
+ # Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
164
+ poetry.toml
165
+
166
+ # ruff
167
+ .ruff_cache/
168
+
169
+ # LSP config files
170
+ pyrightconfig.json
171
+
172
+ ### react ###
173
+ .DS_*
174
+ logs
175
+ **/*.backup.*
176
+ **/*.back.*
177
+
178
+ node_modules
179
+ bower_components
180
+
181
+ *.sublime*
182
+
183
+ psd
184
+ thumb
185
+ sketch
186
+
187
+ ### ReactNative ###
188
+ # React Native Stack Base
189
+
190
+ .expo
191
+ __generated__
192
+
193
+ ### ReactNative.Xcode Stack ###
194
+ ## User settings
195
+ xcuserdata/
196
+
197
+ ## Xcode 8 and earlier
198
+ *.xcscmblueprint
199
+ *.xccheckout
200
+
201
+ ### ReactNative.Gradle Stack ###
202
+ .gradle
203
+ **/build/
204
+ !src/**/build/
205
+
206
+ # Ignore Gradle GUI config
207
+ gradle-app.setting
208
+
209
+ # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
210
+ !gradle-wrapper.jar
211
+
212
+ # Avoid ignore Gradle wrappper properties
213
+ !gradle-wrapper.properties
214
+
215
+ # Cache of project
216
+ .gradletasknamecache
217
+
218
+ # Eclipse Gradle plugin generated files
219
+ # Eclipse Core
220
+ .project
221
+ # JDT-specific (Eclipse Java Development Tools)
222
+ .classpath
223
+
224
+ ### ReactNative.macOS Stack ###
225
+ # General
226
+ .DS_Store
227
+ .AppleDouble
228
+ .LSOverride
229
+
230
+ # Icon must end with two \r
231
+ Icon
232
+
233
+
234
+ # Thumbnails
235
+ ._*
236
+
237
+ # Files that might appear in the root of a volume
238
+ .DocumentRevisions-V100
239
+ .fseventsd
240
+ .Spotlight-V100
241
+ .TemporaryItems
242
+ .Trashes
243
+ .VolumeIcon.icns
244
+ .com.apple.timemachine.donotpresent
245
+
246
+ # Directories potentially created on remote AFP share
247
+ .AppleDB
248
+ .AppleDesktop
249
+ Network Trash Folder
250
+ Temporary Items
251
+ .apdisk
252
+
253
+ ### ReactNative.Linux Stack ###
254
+ *~
255
+
256
+ # temporary files which can be created if a process still has a handle open of a deleted file
257
+ .fuse_hidden*
258
+
259
+ # KDE directory preferences
260
+ .directory
261
+
262
+ # Linux trash folder which might appear on any partition or disk
263
+ .Trash-*
264
+
265
+ # .nfs files are created when an open file is removed but is still being accessed
266
+ .nfs*
267
+
268
+ ### ReactNative.Node Stack ###
269
+ # Logs
270
+ npm-debug.log*
271
+ yarn-debug.log*
272
+ yarn-error.log*
273
+ lerna-debug.log*
274
+ .pnpm-debug.log*
275
+
276
+ # Diagnostic reports (https://nodejs.org/api/report.html)
277
+ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
278
+
279
+ # Runtime data
280
+ pids
281
+ *.pid
282
+ *.seed
283
+ *.pid.lock
284
+
285
+ # Directory for instrumented libs generated by jscoverage/JSCover
286
+ lib-cov
287
+
288
+ # Coverage directory used by tools like istanbul
289
+ coverage
290
+ *.lcov
291
+
292
+ # nyc test coverage
293
+ .nyc_output
294
+
295
+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
296
+ .grunt
297
+
298
+ # Bower dependency directory (https://bower.io/)
299
+
300
+ # node-waf configuration
301
+ .lock-wscript
302
+
303
+ # Compiled binary addons (https://nodejs.org/api/addons.html)
304
+ build/Release
305
+
306
+ # Dependency directories
307
+ node_modules/
308
+ jspm_packages/
309
+
310
+ # Snowpack dependency directory (https://snowpack.dev/)
311
+ web_modules/
312
+
313
+ # TypeScript cache
314
+ *.tsbuildinfo
315
+
316
+ # Optional npm cache directory
317
+ .npm
318
+
319
+ # Optional eslint cache
320
+ .eslintcache
321
+
322
+ # Optional stylelint cache
323
+ .stylelintcache
324
+
325
+ # Microbundle cache
326
+ .rpt2_cache/
327
+ .rts2_cache_cjs/
328
+ .rts2_cache_es/
329
+ .rts2_cache_umd/
330
+
331
+ # Optional REPL history
332
+ .node_repl_history
333
+
334
+ # Output of 'npm pack'
335
+ *.tgz
336
+
337
+ # Yarn Integrity file
338
+ .yarn-integrity
339
+
340
+ # dotenv environment variable files
341
+ .env.development.local
342
+ .env.test.local
343
+ .env.production.local
344
+ .env.local
345
+
346
+ # parcel-bundler cache (https://parceljs.org/)
347
+ .parcel-cache
348
+
349
+ # Next.js build output
350
+ .next
351
+ out
352
+
353
+ # Nuxt.js build / generate output
354
+ .nuxt
355
+ dist
356
+
357
+ # Gatsby files
358
+ .cache/
359
+ # Comment in the public line in if your project uses Gatsby and not Next.js
360
+ # https://nextjs.org/blog/next-9-1#public-directory-support
361
+ # public
362
+
363
+ # vuepress build output
364
+ .vuepress/dist
365
+
366
+ # vuepress v2.x temp and cache directory
367
+ .temp
368
+
369
+ # Docusaurus cache and generated files
370
+ .docusaurus
371
+
372
+ # Serverless directories
373
+ .serverless/
374
+
375
+ # FuseBox cache
376
+ .fusebox/
377
+
378
+ # DynamoDB Local files
379
+ .dynamodb/
380
+
381
+ # TernJS port file
382
+ .tern-port
383
+
384
+ # Stores VSCode versions used for testing VSCode extensions
385
+ .vscode-test
386
+
387
+ # yarn v2
388
+ .yarn/cache
389
+ .yarn/unplugged
390
+ .yarn/build-state.yml
391
+ .yarn/install-state.gz
392
+ .pnp.*
393
+
394
+ ### ReactNative.Buck Stack ###
395
+ buck-out/
396
+ .buckconfig.local
397
+ .buckd/
398
+ .buckversion
399
+ .fakebuckversion
400
+
401
+ ### ReactNative.Android Stack ###
402
+ # Gradle files
403
+ .gradle/
404
+
405
+ # Local configuration file (sdk path, etc)
406
+ local.properties
407
+
408
+ # Log/OS Files
409
+
410
+ # Android Studio generated files and folders
411
+ captures/
412
+ .externalNativeBuild/
413
+ .cxx/
414
+ *.apk
415
+ output.json
416
+
417
+ # IntelliJ
418
+ *.iml
419
+ .idea/
420
+ misc.xml
421
+ deploymentTargetDropDown.xml
422
+ render.experimental.xml
423
+
424
+ # Keystore files
425
+ *.jks
426
+ *.keystore
427
+
428
+ # Google Services (e.g. APIs or Firebase)
429
+ google-services.json
430
+
431
+ # Android Profiling
432
+ *.hprof
433
+
434
+ # Personal
435
+ data
436
+ package-lock.json
Dockerfile ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ FROM python:3.10.9
2
+ COPY . .
3
+ WORKDIR /
4
+ RUN pip install --no-cache-dir --upgrade -r /requirements.txt
5
+ CMD ["python", "main.py"]
main.py ADDED
@@ -0,0 +1,334 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import subprocess
3
+ from concurrent.futures import ThreadPoolExecutor
4
+ from realtime.connection import Socket
5
+ import os
6
+ import time
7
+ from supabase import create_client
8
+ from dotenv import load_dotenv
9
+ import requests
10
+
11
+ load_dotenv()
12
+
13
+ SUPABASE_ID = os.getenv('supabaseID')
14
+ SUPABASE_URL = os.getenv('supabaseUrl')
15
+ SUPABASE_KEY = os.getenv('supabaseAnonKey')
16
+
17
+ # Supabase client creation for each function
18
+ def get_client():
19
+ return create_client(SUPABASE_URL, SUPABASE_KEY)
20
+
21
+ def getUsername(userid):
22
+ supabase = get_client()
23
+ response = supabase.table("profiles").select(
24
+ "*").eq("id", userid).execute()
25
+ data = response.data
26
+ username = data[0]['username']
27
+ return username
28
+
29
+ def getAuthorNotifToken(userid):
30
+ supabase = get_client()
31
+ response = supabase.table("profiles").select(
32
+ "*").eq("id", userid).execute()
33
+ data = response.data
34
+ token = data[0]['notifToken']
35
+ return token
36
+
37
+
38
+ # def send_notification(title, body, token, id, post_id, notif_type):
39
+ # print(token)
40
+ # notification_data = {
41
+ # 'to': token,
42
+ # 'title': title,
43
+ # 'body': body,
44
+ # 'data': {
45
+ # 'user_id': id,
46
+ # 'id': post_id,
47
+ # 'type': notif_type
48
+ # }
49
+ # }
50
+
51
+ # notification_json = json.dumps(notification_data)
52
+ # print(notification_json)
53
+ # curl_command = [
54
+ # 'curl',
55
+ # '-X', 'POST',
56
+ # '-H', 'Content-Type: application/json',
57
+ # '-d', notification_json,
58
+ # 'https://exp.host/--/api/v2/push/send'
59
+ # ]
60
+
61
+ # try:
62
+ # result = subprocess.run(
63
+ # curl_command, capture_output=True, text=True, check=True)
64
+ # print(f'Notification sent successfully: {result.stdout}')
65
+ # except subprocess.CalledProcessError as e:
66
+ # print(f'Failed to send notification: {e.stderr}')
67
+
68
+
69
+ def send_notification(title, body, token, id, post_id, notif_type):
70
+ print(token)
71
+ notification_data = {
72
+ 'to': token,
73
+ 'title': title,
74
+ 'body': body,
75
+ 'data': {
76
+ 'user_id': id,
77
+ 'id': post_id,
78
+ 'type': notif_type
79
+ }
80
+ }
81
+ try:
82
+ response = requests.post(
83
+ 'https://exp.host/--/api/v2/push/send', json=notification_data)
84
+ response.raise_for_status()
85
+ print(f'Notification sent successfully: {response.text}')
86
+ except requests.exceptions.RequestException as e:
87
+ print(f'Failed to send notification: {e}')
88
+
89
+
90
+ def handle_listlikes_update(event_payload):
91
+ print('Received update in listlikes:')
92
+ print(event_payload)
93
+ record = event_payload['record']
94
+ id = record['list_id']
95
+ author_id = record['author_id']
96
+ user_id = record['user_id']
97
+ token = getAuthorNotifToken(author_id)
98
+ username = getUsername(user_id).lower()
99
+ title = 'Picturelock'
100
+ body = f'@{username} liked your collection!'
101
+ if token and user_id != author_id:
102
+ send_notification(title, body, token, user_id, id, "list")
103
+
104
+ def handle_listcomments_update(event_payload):
105
+ print('Received update in listcomments:')
106
+ print(event_payload)
107
+ record = event_payload['record']
108
+ author_id = record['author_id']
109
+ user_id = record['user_id']
110
+ id = record['list_id']
111
+ token = getAuthorNotifToken(author_id)
112
+ username = getUsername(user_id).lower()
113
+ title = 'Picturelock'
114
+ body = f'@{username} commented on your collection!'
115
+ if token and user_id != author_id:
116
+ send_notification(title, body, token, user_id, id, "list")
117
+
118
+ def handle_likes_update(event_payload):
119
+ print('Received update in likes:')
120
+ print(event_payload)
121
+ record = event_payload['record']
122
+ author_id = record['author_id']
123
+ user_id = record['user_id']
124
+ id = record['post_id']
125
+ token = getAuthorNotifToken(author_id)
126
+ username = getUsername(user_id).lower()
127
+ title = 'Picturelock'
128
+ body = f'@{username} liked your post!'
129
+ if token and user_id != author_id:
130
+ send_notification(title, body, token, user_id, id, "post")
131
+
132
+ def handle_comments_update(event_payload):
133
+ print('Received update in comments:')
134
+ print(event_payload)
135
+ record = event_payload['record']
136
+ author_id = record['author_id']
137
+ user_id = record['user_id']
138
+ id = record['post_id']
139
+ token = getAuthorNotifToken(author_id)
140
+ username = getUsername(user_id).lower()
141
+ title = 'Picturelock'
142
+ body = f'@{username} commented on your post!'
143
+ if token and user_id != author_id:
144
+ send_notification(title, body, token, user_id, id, "post")
145
+
146
+ def handle_follow_update(event_payload):
147
+ print('Received update in followers:')
148
+ print(event_payload)
149
+ record = event_payload['record']
150
+ author_id = record['id']
151
+ user_id = record['following']
152
+ id = record['following']
153
+ token = getAuthorNotifToken(author_id)
154
+ username = getUsername(user_id).lower()
155
+ title = 'Picturelock'
156
+ body = f'@{username} followed you!'
157
+ if token and user_id != author_id:
158
+ send_notification(title, body, token, user_id, id, "follow")
159
+
160
+ def getConversationUser(author_id, conv_id):
161
+ supabase = create_client(SUPABASE_URL, SUPABASE_KEY)
162
+ response = supabase.table("conversations").select("*").eq("id", conv_id).execute()
163
+ data = response.data
164
+ user1 = data[0]['user1']
165
+ user2 = data[0]['user2']
166
+ if user1 == author_id:
167
+ return user2
168
+ else:
169
+ return user1
170
+
171
+ def handle_message_update(event_payload):
172
+ print('Received update in messages:')
173
+ print(event_payload)
174
+ record = event_payload['record']
175
+ author_id = record['user_id']
176
+ conv_id = record['conversation_id']
177
+ id = record['conversation_id']
178
+ user_id = getConversationUser(author_id, conv_id)
179
+ token = getAuthorNotifToken(user_id)
180
+ username = getUsername(author_id).lower()
181
+ title = 'Picturelock'
182
+ body = f'@{username} sent you a message!'
183
+ if token and user_id != author_id:
184
+ send_notification(title, body, token, user_id, id, "message")
185
+
186
+ def handle_listreply_update(event_payload):
187
+ print('Received update in listreplies:')
188
+ print(event_payload)
189
+ record = event_payload['record']
190
+ author_id = record['user_id']
191
+ user_id = record['to']
192
+ id = record['list_id']
193
+ token = getAuthorNotifToken(user_id)
194
+ username = getUsername(author_id).lower()
195
+ title = 'Picturelock'
196
+ body = f'@{username} replied to you!'
197
+ if token and user_id != author_id:
198
+ send_notification(title, body, token, user_id, id, "list")
199
+
200
+ def handle_reply_update(event_payload):
201
+ print('Received update in replies:')
202
+ print(event_payload)
203
+ record = event_payload['record']
204
+ author_id = record['user_id']
205
+ user_id = record['to']
206
+ id = record['post_id']
207
+ token = getAuthorNotifToken(user_id)
208
+ username = getUsername(author_id).lower()
209
+ body = f'@{username} replied to you!'
210
+ title = 'Picturelock'
211
+ if token and user_id != author_id:
212
+ send_notification(title, body, token, user_id, id, "post")
213
+
214
+ def handle_commentlikes_update(event_payload):
215
+ print('Received update in commentlikes:')
216
+ print(event_payload)
217
+ record = event_payload['record']
218
+ author_id = record['author_id']
219
+ user_id = record['user_id']
220
+ if record['post_id'] == None:
221
+ id = record['list_id']
222
+ post_type = "list"
223
+ else:
224
+ id = record['post_id']
225
+ post_type = "post"
226
+ token = getAuthorNotifToken(author_id)
227
+ username = getUsername(user_id).lower()
228
+ title = 'Picturelock'
229
+ body = f'@{username} liked your comment!'
230
+ if token and user_id != author_id:
231
+ send_notification(title, body, token, user_id, id, post_type)
232
+
233
+ def handle_replylikes_update(event_payload):
234
+ print('Received update in replylikes:')
235
+ print(event_payload)
236
+ record = event_payload['record']
237
+ author_id = record['author_id']
238
+ user_id = record['user_id']
239
+ if record['post_id'] == None:
240
+ id = record['list_id']
241
+ post_type = "list"
242
+ else:
243
+ id = record['post_id']
244
+ post_type = "post"
245
+ token = getAuthorNotifToken(author_id)
246
+ username = getUsername(user_id).lower()
247
+ title = 'Picturelock'
248
+ body = f'@{username} liked your reply!'
249
+ if token and user_id != author_id:
250
+ send_notification(title, body, token, user_id, id, post_type)
251
+
252
+ def handle_groupreviewrequests_update(event_payload):
253
+ print('Received update in posts:')
254
+ print(event_payload)
255
+ record = event_payload['record']
256
+ author_id = record['groupReviewLeader']
257
+ id = record['id']
258
+ user_id = record['author']
259
+ isGroupReview = record['isGroupReview']
260
+ token = getAuthorNotifToken(user_id)
261
+ username = getUsername(author_id).lower()
262
+ title = 'Picturelock'
263
+ body = f'@{username} sent you an invite to a group review!'
264
+ print(body)
265
+ if token and user_id != author_id and isGroupReview:
266
+ send_notification(title, body, token, author_id, id, "post")
267
+
268
+ def setup_likes_subscription(SUPABASE_ID, SUPABASE_KEY):
269
+ URL = f"wss://{SUPABASE_ID}.supabase.co/realtime/v1/websocket?apikey={SUPABASE_KEY}&vsn=1.0.0"
270
+
271
+ with ThreadPoolExecutor(max_workers=10) as executor:
272
+ while True:
273
+ try:
274
+ s = Socket(URL)
275
+ s.connect()
276
+
277
+ channel_listlikes = s.set_channel("realtime:public:listlikes")
278
+ channel_listlikes.join().on(
279
+ "INSERT", lambda payload: executor.submit(handle_listlikes_update, payload))
280
+
281
+ channel_listcomments = s.set_channel(
282
+ "realtime:public:listcomments")
283
+ channel_listcomments.join().on(
284
+ "INSERT", lambda payload: executor.submit(handle_listcomments_update, payload))
285
+
286
+ channel_likes = s.set_channel("realtime:public:likes")
287
+ channel_likes.join().on(
288
+ "INSERT", lambda payload: executor.submit(handle_likes_update, payload))
289
+
290
+ channel_replylikes = s.set_channel(
291
+ "realtime:public:replylikes")
292
+ channel_replylikes.join().on(
293
+ "INSERT", lambda payload: executor.submit(handle_replylikes_update, payload))
294
+
295
+ channel_commentlikes = s.set_channel(
296
+ "realtime:public:commentlikes")
297
+ channel_commentlikes.join().on(
298
+ "INSERT", lambda payload: executor.submit(handle_commentlikes_update, payload))
299
+
300
+ channel_comments = s.set_channel("realtime:public:comments")
301
+ channel_comments.join().on(
302
+ "INSERT", lambda payload: executor.submit(handle_comments_update, payload))
303
+
304
+ channel_followers = s.set_channel("realtime:public:followers")
305
+ channel_followers.join().on(
306
+ "INSERT", lambda payload: executor.submit(handle_follow_update, payload))
307
+
308
+ channel_replies = s.set_channel("realtime:public:replies")
309
+ channel_replies.join().on(
310
+ "INSERT", lambda payload: executor.submit(handle_reply_update, payload))
311
+
312
+ channel_listreplies = s.set_channel(
313
+ "realtime:public:listreplies")
314
+ channel_listreplies.join().on(
315
+ "INSERT", lambda payload: executor.submit(handle_listreply_update, payload))
316
+
317
+ channel_messages = s.set_channel("realtime:public:messages")
318
+ channel_messages.join().on(
319
+ "INSERT", lambda payload: executor.submit(handle_message_update, payload))
320
+
321
+ channel_posts = s.set_channel("realtime:public:posts")
322
+ channel_posts.join().on("INSERT", lambda payload: executor.submit(
323
+ handle_groupreviewrequests_update, payload))
324
+
325
+ s.listen()
326
+
327
+ except Exception as e:
328
+ print(f'Connection error: {e}')
329
+ print('Reconnecting in 5 seconds...')
330
+ time.sleep(5)
331
+
332
+
333
+ if __name__ == '__main__':
334
+ setup_likes_subscription(SUPABASE_ID, SUPABASE_KEY)
requirements.txt ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ annotated-types==0.7.0
2
+ anyio==4.4.0
3
+ certifi==2024.7.4
4
+ deprecation==2.1.0
5
+ exceptiongroup==1.2.1
6
+ gotrue==2.5.4
7
+ h11==0.14.0
8
+ httpcore==1.0.5
9
+ httpx==0.27.0
10
+ idna==3.7
11
+ packaging==24.1
12
+ postgrest==0.16.8
13
+ pydantic==2.8.2
14
+ pydantic_core==2.20.1
15
+ python-dateutil==2.9.0.post0
16
+ python-dotenv==1.0.1
17
+ realtime==1.0.2
18
+ six==1.16.0
19
+ sniffio==1.3.1
20
+ storage3==0.7.6
21
+ StrEnum==0.4.15
22
+ supabase==2.5.1
23
+ supafunc==0.4.6
24
+ typing_extensions==4.12.2
25
+ websockets==11.0.3