Skip to content

Commit f418f02

Browse files
feat: add conversation created ws event
1 parent 1a1b0b2 commit f418f02

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

services/web/server/src/simcore_service_webserver/conversations/_conversation_message_service.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,82 @@
1111
ConversationMessagePatchDB,
1212
ConversationMessageType,
1313
)
14+
from models_library.groups import GroupID
15+
from models_library.projects import ProjectID
1416
from models_library.rest_ordering import OrderBy, OrderDirection
1517
from models_library.rest_pagination import PageTotalCount
1618
from models_library.users import UserID
1719

20+
from ..projects._groups_repository import list_project_groups
21+
22+
# Import or define SocketMessageDict
23+
from ..socketio.messages import (
24+
SOCKET_IO_PROJECT_CONVERSATION_MESSAGE_CREATED_EVENT,
25+
SocketMessageDict,
26+
send_message_to_standard_group,
27+
)
1828
from ..users.api import get_user_primary_group_id
1929
from . import _conversation_message_repository
2030

2131
_logger = logging.getLogger(__name__)
2232

2333

34+
async def notify_project_conversation_message_created(
35+
app: web.Application,
36+
project_id: ProjectID,
37+
conversation_message: ConversationMessageGetDB,
38+
recipients: list[GroupID],
39+
) -> None:
40+
message = SocketMessageDict(
41+
event_type=SOCKET_IO_PROJECT_CONVERSATION_MESSAGE_CREATED_EVENT,
42+
data={
43+
"project_id": project_id,
44+
"conversation_id": conversation_message.conversation_id,
45+
"message_id": conversation_message.message_id,
46+
"user_group_id": conversation_message.user_group_id,
47+
"content": conversation_message.content,
48+
"type": conversation_message.type,
49+
"created": conversation_message.created.isoformat(),
50+
"modified": conversation_message.modified.isoformat(),
51+
},
52+
)
53+
54+
for recipient in recipients:
55+
await send_message_to_standard_group(app, recipient, message)
56+
57+
2458
async def create_message(
2559
app: web.Application,
2660
*,
2761
user_id: UserID,
62+
project_id: ProjectID,
2863
conversation_id: ConversationID,
2964
# Creation attributes
3065
content: str,
3166
type_: ConversationMessageType,
3267
) -> ConversationMessageGetDB:
3368
_user_group_id = await get_user_primary_group_id(app, user_id=user_id)
3469

35-
return await _conversation_message_repository.create(
70+
created_message = await _conversation_message_repository.create(
3671
app,
3772
conversation_id=conversation_id,
3873
user_group_id=_user_group_id,
3974
content=content,
4075
type_=type_,
4176
)
4277

78+
recipients = [
79+
project_to_group.gid
80+
for project_to_group in await list_project_groups(app, project_id=project_id)
81+
if project_to_group.read
82+
]
83+
84+
await notify_project_conversation_message_created(
85+
app, project_id, created_message, recipients
86+
)
87+
88+
return created_message
89+
4390

4491
async def get_message(
4592
app: web.Application,

services/web/server/src/simcore_service_webserver/projects/_conversations_service.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ async def create_project_conversation_message(
169169
return await conversations_service.create_message(
170170
app,
171171
user_id=user_id,
172+
project_id=project_uuid,
172173
conversation_id=conversation_id,
173174
content=content,
174175
type_=message_type,

services/web/server/src/simcore_service_webserver/socketio/messages.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727
SOCKET_IO_LOG_EVENT: Final[str] = "logger"
2828

2929
SOCKET_IO_NODE_UPDATED_EVENT: Final[str] = "nodeUpdated"
30+
31+
SOCKET_IO_PROJECT_CONVERSATION_MESSAGE_CREATED_EVENT: Final[str] = (
32+
"projectConversationMessageCreated"
33+
)
3034
SOCKET_IO_PROJECT_UPDATED_EVENT: Final[str] = "projectStateUpdated"
35+
3136
SOCKET_IO_WALLET_OSPARC_CREDITS_UPDATED_EVENT: Final[str] = "walletOsparcCreditsUpdated"
3237

3338

0 commit comments

Comments
 (0)