Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

MessageDict: Add a bit of docstring documentation.

Tim Abbott99396b25a6de
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py
index d87ee60c74f..f75b233638f 100644
--- a/zerver/lib/actions.py
+++ b/zerver/lib/actions.py
@@ -1525,6 +1525,13 @@ def do_send_messages(messages_maybe_none: Sequence[Optional[MutableMapping[str,
for message in messages:
do_widget_post_save_actions(message)
+ # This next loop is responsible for notifying other parts of the
+ # Zulip system about the messages we just committed to the database:
+ # * Notifying clients via send_event
+ # * Triggering outgoing webhooks via the service event queue.
+ # * Updating the `first_message_id` field for streams without any message history.
+ # * Implementing the Welcome Bot reply hack
+ # * Adding links to the embed_links queue for open graph processing.
for message in messages:
realm_id: Optional[int] = None
if message['message'].is_stream_message():
diff --git a/zerver/lib/message.py b/zerver/lib/message.py
index 5df4898c9c8..f699da554eb 100644
--- a/zerver/lib/message.py
+++ b/zerver/lib/message.py
@@ -171,6 +171,26 @@ def save_message_rendered_content(message: Message, content: str) -> str:
return rendered_content
class MessageDict:
+ """MessageDict is the core class responsible for marshalling Message
+ objects obtained from the database into a format that can be sent
+ to clients via the Zulip API, whether via `GET /messages`,
+ outgoing webhooks, or other code paths. There are two core flows through
+ which this class is used:
+
+ * For just-sent messages, we construct a single `wide_dict` object
+ containing all the data for the message and the related
+ UserProfile models (sender_info and recipient_info); this object
+ can be stored in queues, caches, etc., and then later turned
+ into an API-format JSONable dictionary via finalize_payload.
+
+ * When fetching messages from the database, we fetch their data in
+ bulk using messages_for_ids, which makes use of caching, bulk
+ fetches that skip the Django ORM, etc., to provide an optimized
+ interface for fetching hundreds of thousands of messages from
+ the database and then turning them into API-format JSON
+ dictionaries.
+
+ """
@staticmethod
def wide_dict(message: Message, realm_id: Optional[int]=None) -> Dict[str, Any]:
'''