Update routes/sendnotifications.py
Browse files- routes/sendnotifications.py +12 -6
routes/sendnotifications.py
CHANGED
@@ -70,7 +70,8 @@ async def get_post_info(feed_id: str):
|
|
70 |
feed = feeds[0]
|
71 |
description = feed.get("description", "")
|
72 |
portfolio_ids = feed.get("portfolios") or []
|
73 |
-
|
|
|
74 |
image_url = None
|
75 |
if portfolio_ids:
|
76 |
portfolio_data = await fetch_supabase("Portfolio", "image_url", {"id": portfolio_ids[0]})
|
@@ -79,7 +80,8 @@ async def get_post_info(feed_id: str):
|
|
79 |
|
80 |
return {
|
81 |
"description": description,
|
82 |
-
"image_url": image_url
|
|
|
83 |
}
|
84 |
|
85 |
async def fetch_supabase(table: str, select: str, filters: dict, headers=SUPABASE_ROLE_HEADERS):
|
@@ -150,11 +152,17 @@ async def send_notification(
|
|
150 |
user_token: str = Header(..., alias="User-key")
|
151 |
):
|
152 |
follower_id = await verify_user_token(user_token)
|
153 |
-
target_user_id = data.target_user_id
|
154 |
|
155 |
if data.keyword not in ("follow", "like"):
|
156 |
raise HTTPException(status_code=400, detail="Unsupported keyword")
|
157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
# Verifica se relação de follow existe
|
159 |
if data.keyword == "follow":
|
160 |
follow_exists = await check_follow_exists(follower_id, target_user_id)
|
@@ -180,10 +188,8 @@ async def send_notification(
|
|
180 |
body = f"{actor_name} started following you."
|
181 |
image_url = None
|
182 |
elif data.keyword == "like":
|
183 |
-
# Pega dados do post
|
184 |
-
post_info = await get_post_info(data.reference)
|
185 |
-
title = "❤️ New Like!"
|
186 |
desc = post_info["description"]
|
|
|
187 |
body = f"{actor_name} liked your post" + (f": \"{desc}\"" if desc else ".")
|
188 |
image_url = post_info["image_url"]
|
189 |
else:
|
|
|
70 |
feed = feeds[0]
|
71 |
description = feed.get("description", "")
|
72 |
portfolio_ids = feed.get("portfolios") or []
|
73 |
+
user_id = feed.get("user_id")
|
74 |
+
|
75 |
image_url = None
|
76 |
if portfolio_ids:
|
77 |
portfolio_data = await fetch_supabase("Portfolio", "image_url", {"id": portfolio_ids[0]})
|
|
|
80 |
|
81 |
return {
|
82 |
"description": description,
|
83 |
+
"image_url": image_url,
|
84 |
+
"user_id": user_id # <-- importante
|
85 |
}
|
86 |
|
87 |
async def fetch_supabase(table: str, select: str, filters: dict, headers=SUPABASE_ROLE_HEADERS):
|
|
|
152 |
user_token: str = Header(..., alias="User-key")
|
153 |
):
|
154 |
follower_id = await verify_user_token(user_token)
|
|
|
155 |
|
156 |
if data.keyword not in ("follow", "like"):
|
157 |
raise HTTPException(status_code=400, detail="Unsupported keyword")
|
158 |
|
159 |
+
# Determina o usuário de destino
|
160 |
+
if data.keyword == "like":
|
161 |
+
post_info = await get_post_info(data.reference)
|
162 |
+
target_user_id = post_info["user_id"]
|
163 |
+
else:
|
164 |
+
target_user_id = data.target_user_id
|
165 |
+
|
166 |
# Verifica se relação de follow existe
|
167 |
if data.keyword == "follow":
|
168 |
follow_exists = await check_follow_exists(follower_id, target_user_id)
|
|
|
188 |
body = f"{actor_name} started following you."
|
189 |
image_url = None
|
190 |
elif data.keyword == "like":
|
|
|
|
|
|
|
191 |
desc = post_info["description"]
|
192 |
+
title = "❤️ New Like!"
|
193 |
body = f"{actor_name} liked your post" + (f": \"{desc}\"" if desc else ".")
|
194 |
image_url = post_info["image_url"]
|
195 |
else:
|