Skip to content

Commit 42e45e9

Browse files
committed
Added notification blocks
1 parent 0fe529e commit 42e45e9

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

backend/PyMatcha/models/notification.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from datetime import datetime
2323
from typing import Optional
2424

25+
from PyMatcha.models.user import User
2526
from PyMatcha.utils import create_notifications_table
2627
from PyMatcha.utils.orm import Field
2728
from PyMatcha.utils.orm import Model
@@ -40,17 +41,21 @@ class Notification(Model):
4041

4142
@staticmethod
4243
def create(
44+
trigger_id: int,
4345
user_id: int,
4446
content: str,
4547
type: str,
4648
link_to: Optional[str],
4749
is_seen: bool = False,
4850
dt_received: datetime = datetime.utcnow(),
49-
) -> Notification:
51+
) -> Optional[Notification]:
5052
if type not in ["match", "like", "superlike", "unlike", "view", "message", "message_like"]:
5153
raise ValueError(
5254
"type must be one of ['match', 'like', 'superlike', 'unlike', 'view', 'message', 'message_like']"
5355
)
56+
blocked_ids = [block.blocked_id for block in User.get(id=user_id).get_blocks()]
57+
if trigger_id in blocked_ids:
58+
return None
5459
new_notif = Notification(
5560
user_id=user_id, content=content, type=type, link_to=link_to, is_seen=is_seen, dt_received=dt_received
5661
)

backend/PyMatcha/routes/api/like.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,21 @@ def like_profile(uid):
5555
if u.already_likes(current_user.id):
5656
Match.create(user_1=current_user.id, user_2=u.id)
5757
Notification.create(
58-
user_id=u.id, content=f"{u.first_name} liked you! Go check them out!", type="like", link_to=f"users/{u.id}"
58+
trigger_id=current_user.id,
59+
user_id=u.id,
60+
content=f"{current_user.first_name} liked you! Go check them out!",
61+
type="like",
62+
link_to=f"users/{current_user.id}",
5963
)
6064
Notification.create(
65+
trigger_id=current_user.id,
6166
user_id=u.id,
6267
content=f"You and {current_user.first_name} matched!",
6368
type="match",
6469
link_to=f"conversation/{current_user.id}",
6570
)
6671
Notification.create(
72+
trigger_id=u.id,
6773
user_id=current_user.id,
6874
content=f"You and {u.first_name} matched!",
6975
type="match",
@@ -73,15 +79,20 @@ def like_profile(uid):
7379

7480
if is_superlike:
7581
Notification.create(
82+
trigger_id=current_user.id,
7683
user_id=u.id,
77-
content=f"{u.first_name} superliked you 😏! Go check them out!",
84+
content=f"{current_user.first_name} superliked you 😏! Go check them out!",
7885
type="superlike",
79-
link_to=f"users/{u.id}",
86+
link_to=f"users/{current_user.id}",
8087
)
8188
return Success("Superliked user.")
8289
else:
8390
Notification.create(
84-
user_id=u.id, content=f"{u.first_name} liked you! Go check them out!", type="like", link_to=f"users/{u.id}"
91+
trigger_id=current_user.id,
92+
user_id=u.id,
93+
content=f"{current_user.first_name} liked you! Go check them out!",
94+
type="like",
95+
link_to=f"users/{current_user.id}",
8596
)
8697
return Success("Liked user.")
8798

@@ -99,6 +110,12 @@ def unlike_profile(uid):
99110
raise BadRequestError("You never liked this person in the first place.")
100111
Like.get_multi(liked_id=u.id, liker_id=current_user.id).delete()
101112

102-
Notification.create(user_id=u.id, content=f"{u.first_name} unliked you.", type="unlike", link_to=None)
113+
Notification.create(
114+
trigger_id=current_user.id,
115+
user_id=u.id,
116+
content=f"{current_user.first_name} unliked you.",
117+
type="unlike",
118+
link_to=None,
119+
)
103120

104121
return Success(f"Unliked user {u.id}.")

backend/PyMatcha/routes/api/messages.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def send_message():
7373
current_user.send_message(to_id=to_user.id, content=content)
7474
current_app.logger.debug("/messages -> Message successfully sent to {}.".format(to_uid))
7575
Notification.create(
76+
trigger_id=current_user.id,
7677
user_id=to_user.id,
7778
content=f"{current_user.first_name} said: {content}",
7879
type="message",
@@ -127,6 +128,7 @@ def like_message(message_id):
127128
message.is_liked = True
128129
message.save()
129130
Notification.create(
131+
trigger_id=current_user.id,
130132
user_id=message.from_id,
131133
content=f"{current_user.first_name} liked you message!",
132134
type="message_like",

backend/PyMatcha/routes/api/profile/view.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def view_profile(uid):
4747
user_dict["distance"] = _get_distance(current_user.geohash, u.geohash)
4848

4949
Notification.create(
50+
trigger_id=current_user.id,
5051
user_id=u.id,
5152
content=f"{current_user.first_name} just viewed your profile! Go check their profile out!",
5253
type="view",

0 commit comments

Comments
 (0)