@@ -70,8 +70,13 @@ def list_messages(
7070
7171 messages : List [MessageItem ] = []
7272 for m in rows :
73- is_mine = m .sender_id == me .user_id
74- read = db .query (ChatRead ).filter (ChatRead .message_id == m .id ).count () > 0
73+ if m .type == "SYSTEM" :
74+ is_mine = False
75+ read = True # 시스템 메세지는 그냥 항상 읽은 걸로 취급
76+ else :
77+ is_mine = (m .sender_id == me .user_id )
78+ read = db .query (ChatRead ).filter (ChatRead .message_id == m .id ).count () > 0
79+
7580 messages .append (
7681 MessageItem (
7782 messageId = m .id ,
@@ -151,19 +156,34 @@ async def update_deal_status(
151156 db .refresh (posting )
152157
153158 nick = me .nickname or "사용자"
154- if new_status == "RESERVED" :
159+
160+ if prev_status == "RESERVED" and new_status == "ACTIVE" :
161+ msg_text = f"{ nick } 님이 예약을 취소했습니다"
162+ elif new_status == "RESERVED" :
155163 msg_text = f"{ nick } 님이 예약을 요청했습니다"
156164 elif new_status == "COMPLETED" :
157165 msg_text = f"{ nick } 님이 거래를 완료했습니다"
158166 else :
159167 msg_text = f"{ nick } 님이 거래 상태를 변경했습니다"
160168
161- # ✅ 여기! 이제는 그냥 await로 보내기
169+ # ✅ 시스템 메시지를 ChatMessage 로 저장
170+ system_msg = ChatMessage (
171+ room_id = room .id ,
172+ sender_id = None , # 시스템이라서 보낸 사람 없음
173+ type = "SYSTEM" ,
174+ content = msg_text ,
175+ )
176+ db .add (system_msg )
177+ db .commit ()
178+ db .refresh (system_msg )
179+
180+ # ✅ 기존처럼 브로드캐스트 (필요하면 messageId도 같이 넘겨도 됨)
162181 await chat_ws .broadcast_deal_update (
163182 chat_id = room .id ,
164183 deal_status = new_status ,
165184 post_status = posting .status ,
166185 system_message = msg_text ,
186+ # 필요하면 system_message_id=system_msg.id 이런 식으로 확장
167187 )
168188
169189 return DealStatusOut (
@@ -175,4 +195,4 @@ async def update_deal_status(
175195 postStatus = posting .status ,
176196 changedBy = me .user_id ,
177197 changedAt = changed_at ,
178- )
198+ )
0 commit comments