fix(messages): add message to existing 1:1 conversation from compose modal
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions

When composing a new message to someone you already have a conversation
with, the dedup logic returned the existing conversation without adding
the message. Now it creates the message and publishes SSE notification.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Maciej Pienczyn 2026-04-08 16:25:06 +02:00
parent 7402f3dc52
commit 0c9ea2e69f

View File

@ -271,7 +271,33 @@ def api_conversations_create():
for conv in existing: for conv in existing:
conv_member_ids = {m.user_id for m in conv.members} conv_member_ids = {m.user_id for m in conv.members}
if conv_member_ids == {current_user.id, other_id}: if conv_member_ids == {current_user.id, other_id}:
# Return existing conversation # Existing 1:1 — add message if provided
if message_text:
now = datetime.now()
msg = ConvMessage(
conversation_id=conv.id,
sender_id=current_user.id,
content=message_text,
created_at=now,
)
db.add(msg)
db.flush()
conv.last_message_id = msg.id
conv.updated_at = now
db.commit()
db.refresh(conv)
sender_name = current_user.name or current_user.email.split('@')[0]
_publish_to_conv(db, conv.id, 'new_message', {
'conversation_id': conv.id,
'message': {
'id': msg.id,
'content_preview': strip_html(message_text)[:100],
'sender_name': sender_name,
'sender_id': current_user.id,
},
}, exclude_user_id=current_user.id)
membership = db.query(ConversationMember).filter_by( membership = db.query(ConversationMember).filter_by(
conversation_id=conv.id, conversation_id=conv.id,
user_id=current_user.id, user_id=current_user.id,