Spaces:
Running
Running
Commit
·
1f88998
1
Parent(s):
269021e
fyp
Browse files
app/services/conversation_service.py
CHANGED
|
@@ -59,10 +59,11 @@ class ConversationService:
|
|
| 59 |
|
| 60 |
# 2. Check if user is trying to message themselves
|
| 61 |
if owner_id == current_user_id:
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
| 66 |
|
| 67 |
# 3. Prepare property card data (always needed for frontend prompt)
|
| 68 |
property_card = {
|
|
@@ -176,16 +177,14 @@ class ConversationService:
|
|
| 176 |
if before_id and ObjectId.is_valid(before_id):
|
| 177 |
query["_id"] = {"$lt": ObjectId(before_id)}
|
| 178 |
|
| 179 |
-
# Get messages
|
| 180 |
-
|
|
|
|
| 181 |
|
| 182 |
messages = []
|
| 183 |
async for doc in cursor:
|
| 184 |
messages.append(Message.format_response(doc))
|
| 185 |
|
| 186 |
-
# Reverse to get chronological order
|
| 187 |
-
messages.reverse()
|
| 188 |
-
|
| 189 |
logger.info(f"Found {len(messages)} messages for conversation {conversation_id}")
|
| 190 |
|
| 191 |
return messages
|
|
|
|
| 59 |
|
| 60 |
# 2. Check if user is trying to message themselves
|
| 61 |
if owner_id == current_user_id:
|
| 62 |
+
return {
|
| 63 |
+
"success": False,
|
| 64 |
+
"error": "self_chat",
|
| 65 |
+
"message": "Oops! You can't chat with yourself. This is your own listing! 😊",
|
| 66 |
+
}
|
| 67 |
|
| 68 |
# 3. Prepare property card data (always needed for frontend prompt)
|
| 69 |
property_card = {
|
|
|
|
| 177 |
if before_id and ObjectId.is_valid(before_id):
|
| 178 |
query["_id"] = {"$lt": ObjectId(before_id)}
|
| 179 |
|
| 180 |
+
# Get messages - sort ascending (oldest first, newest last)
|
| 181 |
+
# This gives chronological order: oldest at top, newest at bottom
|
| 182 |
+
cursor = db.messages.find(query).sort("created_at", 1).limit(limit)
|
| 183 |
|
| 184 |
messages = []
|
| 185 |
async for doc in cursor:
|
| 186 |
messages.append(Message.format_response(doc))
|
| 187 |
|
|
|
|
|
|
|
|
|
|
| 188 |
logger.info(f"Found {len(messages)} messages for conversation {conversation_id}")
|
| 189 |
|
| 190 |
return messages
|