Skip to content

Commit 11a183a

Browse files
authored
Merge pull request #393 from Seluj78/387-notifications
387 notifications
2 parents 1a6442a + 321f571 commit 11a183a

26 files changed

+466
-222
lines changed

PyMatchaV2.postman_collection.json

Lines changed: 46 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4884,28 +4884,22 @@
48844884
}
48854885
}
48864886
],
4887-
"protocolProfileBehavior": {
4888-
"disableBodyPruning": true
4889-
},
48904887
"request": {
48914888
"method": "GET",
48924889
"header": [],
4893-
"body": {
4894-
"mode": "raw",
4895-
"raw": "{\n \"force\": true\n}",
4896-
"options": {
4897-
"raw": {
4898-
"language": "json"
4899-
}
4900-
}
4901-
},
49024890
"url": {
4903-
"raw": "{{host}}/recommendations",
4891+
"raw": "{{host}}/recommendations?force=True",
49044892
"host": [
49054893
"{{host}}"
49064894
],
49074895
"path": [
49084896
"recommendations"
4897+
],
4898+
"query": [
4899+
{
4900+
"key": "force",
4901+
"value": "True"
4902+
}
49094903
]
49104904
}
49114905
},
@@ -5125,28 +5119,22 @@
51255119
}
51265120
}
51275121
],
5128-
"protocolProfileBehavior": {
5129-
"disableBodyPruning": true
5130-
},
51315122
"request": {
51325123
"method": "GET",
51335124
"header": [],
5134-
"body": {
5135-
"mode": "raw",
5136-
"raw": "{\n \"force\": true\n}",
5137-
"options": {
5138-
"raw": {
5139-
"language": "json"
5140-
}
5141-
}
5142-
},
51435125
"url": {
5144-
"raw": "{{host}}/recommendations",
5126+
"raw": "{{host}}/recommendations?force=True",
51455127
"host": [
51465128
"{{host}}"
51475129
],
51485130
"path": [
51495131
"recommendations"
5132+
],
5133+
"query": [
5134+
{
5135+
"key": "force",
5136+
"value": "True"
5137+
}
51505138
]
51515139
}
51525140
},
@@ -7254,162 +7242,162 @@
72547242
],
72557243
"variable": [
72567244
{
7257-
"id": "47260898-0119-4788-89b6-a52b48930a7a",
7245+
"id": "de9d17be-f7ca-4a75-af2e-dcfd5d60609a",
72587246
"key": "host",
72597247
"value": "http://127.0.0.1:5000"
72607248
},
72617249
{
7262-
"id": "6af9f454-6d0c-4283-98a8-b6a3e0c97626",
7250+
"id": "0cd6ffc1-1c75-47c2-8d8d-f5125648afac",
72637251
"key": "access_token",
72647252
"value": ""
72657253
},
72667254
{
7267-
"id": "ded3e3a3-bf44-4ef9-a8b2-9560c813108d",
7255+
"id": "ed3db240-4fad-45f5-8a7a-095a337c5816",
72687256
"key": "refresh_token",
72697257
"value": ""
72707258
},
72717259
{
7272-
"id": "6aa13788-a429-4915-9422-b373b52521a4",
7260+
"id": "821388fc-d8c6-4bbe-8646-2ab446976be9",
72737261
"key": "debug_token",
72747262
"value": "xX69jules69Xx"
72757263
},
72767264
{
7277-
"id": "9c6a6a27-5258-495a-997f-ea269fc738f0",
7265+
"id": "a10bcfc0-96f5-4e8e-84c4-076155ac6fbc",
72787266
"key": "id",
72797267
"value": "1541"
72807268
},
72817269
{
7282-
"id": "e789f83c-9116-4cba-9431-fa3a29aa8991",
7270+
"id": "47865117-86d5-457d-ab4b-be67216a58a7",
72837271
"key": "first_name",
72847272
"value": "Jules"
72857273
},
72867274
{
7287-
"id": "9a4ea950-8015-4b65-ab6b-e8cb9d185271",
7275+
"id": "01bb833b-a658-48d5-a2cc-b76e1016bb90",
72887276
"key": "last_name",
72897277
"value": "Lasne"
72907278
},
72917279
{
7292-
"id": "4b1bb76b-f41d-42ad-8716-327aa05c2b5e",
7280+
"id": "daa86e8b-d927-4bae-a05a-6b4b28f43712",
72937281
"key": "email",
72947282
"value": "jules.lasne@example.org"
72957283
},
72967284
{
7297-
"id": "54979fe4-d4ff-4535-9cc1-0893f3eee1b7",
7285+
"id": "192efd3a-7603-421c-be59-1fa2d8a9a0bb",
72987286
"key": "username",
72997287
"value": "seluj78"
73007288
},
73017289
{
7302-
"id": "255ad113-0fb8-4896-a144-fec8139654c2",
7290+
"id": "a78f5409-bfb0-45db-aa9c-b28d771ed2de",
73037291
"key": "password",
73047292
"value": "dolphin"
73057293
},
73067294
{
7307-
"id": "4c8ae2b2-855e-4c8c-990a-dd1959518ebd",
7295+
"id": "bfcf2884-20c9-4ad9-b14f-82c6df4d248e",
73087296
"key": "orientation",
73097297
"value": "heterosexual"
73107298
},
73117299
{
7312-
"id": "ddb7fc8a-d559-4a83-bb15-faa3553c4351",
7300+
"id": "db6ac697-a874-44a1-9157-e9d522bce9bc",
73137301
"key": "gender",
73147302
"value": "male"
73157303
},
73167304
{
7317-
"id": "8b174ed5-7393-4f00-8e5f-f97306aac6bd",
7305+
"id": "6e9c5155-e56d-408a-8211-8cdb37083737",
73187306
"key": "bio",
73197307
"value": "Phasellus vel tortor vel elit scelerisque accumsan vel nec nunc. Ut condimentum vestibulum sapien non dictum. Vestibulum ac eleifend mi. Curabitur dictum vestibulum ex at placerat. Pellentesque odio mi, condimentum et sollicitudin at, finibus non leo. Aenean sed pulvinar nulla, nec tincidunt felis. Aenean nibh elit, aliquam sit amet lobortis et, pellentesque ut orci. Curabitur placerat sem id ex laoreet imperdiet. Curabitur dictum ac urna feugiat viverra. Vivamus nec pulvinar urna. Suspendisse vel ultrices est. Sed malesuada est vel orci venenatis scelerisque. Phasellus ultrices dignissim sapien, at mattis tellus mattis pulvinar. Sed ut euismod velit, id fermentum leo."
73207308
},
73217309
{
7322-
"id": "987a790c-5a8f-4b91-9df0-3153aa98be67",
7310+
"id": "2de8e81c-9179-406d-8873-5aff4b739f54",
73237311
"key": "birthdate",
73247312
"value": "06/04/1998"
73257313
},
73267314
{
7327-
"id": "52b12993-612e-4f9f-af33-9309d110d6eb",
7315+
"id": "7e1d9f45-350f-4d91-8a16-0eaa1abf8685",
73287316
"key": "first_name2",
73297317
"value": "Félix"
73307318
},
73317319
{
7332-
"id": "14298d39-6b97-4480-9372-337be3dee725",
7320+
"id": "a19f2e27-d89a-443d-8d5f-b18dfa38a298",
73337321
"key": "last_name2",
73347322
"value": "Ensal"
73357323
},
73367324
{
7337-
"id": "81be5b1d-aa61-4ede-a828-77fc2b4d01a3",
7325+
"id": "db1dfa44-09c4-4e85-9568-15ddfb78d7e7",
73387326
"key": "username2",
73397327
"value": "Ufree"
73407328
},
73417329
{
7342-
"id": "8f9d3da5-5a4b-4299-9294-4c08caa8fb22",
7330+
"id": "bba960c3-9465-4b1c-90b2-8c0bba49091b",
73437331
"key": "bio2",
73447332
"value": "Donec quis porttitor ante, ac pulvinar nulla. Vivamus dignissim, ipsum ultricies interdum suscipit, risus tellus auctor mi, eu auctor metus sem quis urna. In maximus placerat ipsum, nec sodales elit aliquet sed. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Phasellus malesuada velit felis, non volutpat ex bibendum at. Maecenas aliquet sodales quam at consequat. Sed faucibus consequat tempor. Fusce consequat eu sem non tempus. Duis dapibus nunc vel tempus semper. Pellentesque dignissim tellus odio, vel luctus ipsum suscipit quis. Curabitur id erat at quam varius fermentum non in massa."
73457333
},
73467334
{
7347-
"id": "8873940b-6d9f-424c-9de8-8078e40c7a3b",
7335+
"id": "ebc5791e-9317-409b-9195-0c869829de4b",
73487336
"key": "gender2",
73497337
"value": "other"
73507338
},
73517339
{
7352-
"id": "d584ba79-0a76-4ccb-ad8b-dde82b751450",
7340+
"id": "7ffd0db7-a926-4c8e-bfb5-3efb4ffa81ac",
73537341
"key": "orientation2",
73547342
"value": "bisexual"
73557343
},
73567344
{
7357-
"id": "a1c35569-b32b-4270-a088-d10690dbce65",
7345+
"id": "75392ec7-f738-441d-af69-671b36a89b67",
73587346
"key": "birthdate2",
73597347
"value": "25/06/2000"
73607348
},
73617349
{
7362-
"id": "27a9b0e4-0820-459f-b80b-50a16ebf63e7",
7350+
"id": "5f247ade-3d4f-4b66-8e66-4949a809835a",
73637351
"key": "email2",
73647352
"value": "felix.ensal@example.org"
73657353
},
73667354
{
7367-
"id": "427927f9-950a-4b48-96af-3b193dbf09a7",
7355+
"id": "79fbeabd-8711-4b7e-a3ce-a2fff88216aa",
73687356
"key": "password2",
73697357
"value": "dolphin2"
73707358
},
73717359
{
7372-
"id": "c81312a4-4813-49d5-abaf-95b0b23636a3",
7360+
"id": "010ca345-c7b8-4443-8996-5a0d1ddffa40",
73737361
"key": "ip",
73747362
"value": "90.108.46.63"
73757363
},
73767364
{
7377-
"id": "43556024-37c9-44c6-a975-e834af8d1e69",
7365+
"id": "dcc0c64a-7c6d-48da-ad72-8f1259b12c70",
73787366
"key": "lat",
73797367
"value": "49.5271"
73807368
},
73817369
{
7382-
"id": "3fcf977a-7491-4035-80e3-7002dcd536b5",
7370+
"id": "a1f10ead-5858-4820-b474-93b50f9d7b59",
73837371
"key": "lng",
73847372
"value": "1.1885"
73857373
},
73867374
{
7387-
"id": "d4368742-3888-452e-a72a-c0c73d84369d",
7375+
"id": "ad61ddc7-cb2a-4fc7-ba25-ddb68a83a7a8",
73887376
"key": "my_msg_id",
73897377
"value": "-1"
73907378
},
73917379
{
7392-
"id": "69455489-9556-4f4a-ac9a-9a7052b4d733",
7380+
"id": "cf98244b-d9b5-4f6b-969a-dea0bf631e93",
73937381
"key": "to_me_msg_id",
73947382
"value": "-1"
73957383
},
73967384
{
7397-
"id": "31c3a4ae-cb35-49a2-9f03-388e21304c02",
7385+
"id": "bcd2370c-fee5-4f5c-aad8-ff80ccec2c8c",
73987386
"key": "other_msg_id",
73997387
"value": "-1"
74007388
},
74017389
{
7402-
"id": "a986e223-6946-40bb-bfa8-f540dfed458f",
7390+
"id": "c3fef2db-d89f-4cab-8e93-9aa0f7746395",
74037391
"key": "user_access_token",
74047392
"value": ""
74057393
},
74067394
{
7407-
"id": "2d248ea3-6d54-4429-872c-d6f4c5f2d47d",
7395+
"id": "0e10a01a-fe4d-4d3b-865c-3e34bfb98003",
74087396
"key": "user_refresh_token",
74097397
"value": ""
74107398
},
74117399
{
7412-
"id": "1be795f6-bc59-4264-b657-6722c2e4ffcf",
7400+
"id": "45055d3a-d126-443d-9c60-b41b65109fe7",
74137401
"key": "notif_id",
74147402
"value": ""
74157403
}

backend/PyMatcha/routes/api/recommendations.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from flask_jwt_extended import current_user
2424
from flask_jwt_extended import jwt_required
2525
from PyMatcha import redis
26-
from PyMatcha.utils.decorators import validate_params
2726
from PyMatcha.utils.errors import BadRequestError
2827
from PyMatcha.utils.recommendations import create_user_recommendations
2928
from PyMatcha.utils.success import SuccessOutput
@@ -32,10 +31,9 @@
3231

3332

3433
@recommendations_bp.route("/recommendations", methods=["GET"])
35-
@validate_params({"force": bool})
3634
@jwt_required
3735
def get_recommendations():
38-
force = request.get_json()["force"]
36+
force = request.args.get("force", default=False, type=bool)
3937
recommendations = redis.get(f"user_recommendations:{str(current_user.id)}")
4038
if force or not recommendations:
4139
create_user_recommendations(current_user)

backend/PyMatcha/utils/bot_actions.py

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from PyMatcha.models.like import Like
1111
from PyMatcha.models.match import Match
1212
from PyMatcha.models.message import Message
13+
from PyMatcha.models.notification import Notification
1314
from PyMatcha.models.user import User
1415
from PyMatcha.models.view import View
1516
from PyMatcha.utils.recommendations import create_user_recommendations
@@ -60,10 +61,30 @@ def _botaction_like(bot_user: User, recommendations):
6061
return
6162
user_to_like = User.get(id=user_to_like["id"])
6263
View.create(profile_id=user_to_like.id, viewer_id=bot_user.id)
64+
Notification.create(
65+
trigger_id=bot_user.id,
66+
user_id=user_to_like["id"],
67+
content=f"{bot_user.first_name} just viewed your profile! Go check their profile out!",
68+
type="view",
69+
link_to=f"users/{bot_user.id}",
70+
)
6371
Like.create(liker_id=bot_user.id, liked_id=user_to_like.id)
64-
72+
Notification.create(
73+
trigger_id=bot_user.id,
74+
user_id=user_to_like.id,
75+
content=f"{bot_user.first_name} liked you! Go check them out!",
76+
type="like",
77+
link_to=f"users/{bot_user.id}",
78+
)
6579
if user_to_like.already_likes(bot_user.id):
6680
Match.create(user_1=bot_user.id, user_2=user_to_like.id)
81+
Notification.create(
82+
trigger_id=bot_user.id,
83+
user_id=user_to_like.id,
84+
content=f"You and {bot_user.first_name} matched!",
85+
type="match",
86+
link_to=f"conversation/{bot_user.id}",
87+
)
6788

6889

6990
def botaction_unlike(bot_user: User):
@@ -81,6 +102,13 @@ def _botaction_view(bot_user: User, recommendations):
81102
except IndexError:
82103
return
83104
View.create(profile_id=user_to_view["id"], viewer_id=bot_user.id)
105+
Notification.create(
106+
trigger_id=bot_user.id,
107+
user_id=user_to_view["id"],
108+
content=f"{bot_user.first_name} just viewed your profile! Go check their profile out!",
109+
type="view",
110+
link_to=f"users/{bot_user.id}",
111+
)
84112

85113

86114
def _botaction_message_new_conversation(bot_user: User):
@@ -102,7 +130,15 @@ def _botaction_message_new_conversation(bot_user: User):
102130
else:
103131
other_user = match_to_open_conv.user_1
104132

105-
bot_user.send_message(to_id=other_user, content=choice(BOT_CONV_OPENERS))
133+
content = choice(BOT_CONV_OPENERS)
134+
bot_user.send_message(to_id=other_user, content=content)
135+
Notification.create(
136+
trigger_id=bot_user.id,
137+
user_id=other_user,
138+
content=f"{bot_user.first_name} said: {content}",
139+
type="message",
140+
link_to=f"conversation/{bot_user.id}",
141+
)
106142

107143

108144
def _botaction_respond_to_unread(bot_user: User, chatbot):
@@ -118,6 +154,13 @@ def _botaction_respond_to_unread(bot_user: User, chatbot):
118154
return
119155
bot_reply = chatbot.get_response(message_to_reply.content)
120156
bot_user.send_message(to_id=message_to_reply.from_id, content=bot_reply.text)
157+
Notification.create(
158+
trigger_id=bot_user.id,
159+
user_id=message_to_reply.from_id,
160+
content=f"{bot_user.first_name} said: {bot_reply.text}",
161+
type="message",
162+
link_to=f"conversation/{bot_user.id}",
163+
)
121164

122165

123166
def _botaction_send_message_over_old_one(bot_user: User, chatbot):
@@ -133,6 +176,13 @@ def _botaction_send_message_over_old_one(bot_user: User, chatbot):
133176

134177
bot_reply = chatbot.get_response(".")
135178
bot_user.send_message(to_id=other_user, content=bot_reply.text)
179+
Notification.create(
180+
trigger_id=bot_user.id,
181+
user_id=message_to_reply.from_id,
182+
content=f"{bot_user.first_name} said: {bot_reply.text}",
183+
type="message",
184+
link_to=f"conversation/{bot_user.id}",
185+
)
136186

137187

138188
def decide_bot_action(bot_user: User):

0 commit comments

Comments
 (0)