pub async fn store_server_message<B, F>(
backend: &B,
caller: &B::CallerCtx,
account_id: &Id,
chat_id: &Id,
sender_msg_id: &Id,
build: F,
) -> Result<StoreOutcome, BackendSetError<B::Error>>Expand description
Store a Message that the server, not a client, creates: for example a
MIMI fanout Message (draft-atwood-jmap-chat-mimi-00
§application/mimi-fanout) or a federation Peer/deliver Message.
build makes the Message for the id the backend assigns, as for
ChatStore::create_object. It sets every other field, including
the server-set senderMsgId, senderId, sentAt and receivedAt and
a body type that ChatLimits::server_reserved_body_types keeps out
of Message/set. Its chatId and senderMsgId are then overwritten
with chat_id and sender_msg_id, so the stored Message always matches
the duplicate check. None of the Message/set client-input checks run.
Before storing, chat_id is searched for sender_msg_id with
find_message_by_sender_msg_id. A hit returns
StoreOutcome::Duplicate and writes nothing. The mimi draft
requires this: “The server MUST NOT store a FanoutMessage whose
senderMsgId it has already stored in the Chat”. After a store, the
owner’s ReadPosition for the Chat is created if missing and the
Chat’s unreadCount is recomputed, as for Message/set
(draft-atwood-jmap-chat-00 §ReadPosition: “For direct and group
Chats, a ReadPosition is created when the first message is
delivered.”).
ponytail: the duplicate check and the create are separate backend
calls. Two concurrent calls with one senderMsgId can both store, so
a caller that can race (such as parallel /notify deliveries)
serializes calls per Chat.
§Errors
Returns the backend’s error from the lookup (as
BackendSetError::Other) or from
ChatStore::create_object, unchanged.