Update room list on new message
Goal
Have room list update live when a new message comes in or is sent, with the message text / timestamp. This change does not concern its self with moving of room position on receipt of a new message.
What needs to be done
Prototyping, I created the function below in the chat-messages
service and tested it by chaining it into the updateCacheWithNewMessage
hook. The problem with that approach is that that hook only fires when new messages are loaded into a chat room, so if you aren't in the room that receives the message, then the room list doesn't update.
We do not send the actual message through sockets currently - we said we would call the server to hydrate when it became neccesary, however I would argue that this is a superfluous call, so I suggest that in the chat-receipt
service's socket subscription (or perhaps somewhere else abstracted out in another socket listener), we either:
- Fire another request to load the latest message and patch over the room list with that (superfluous call).
- Send the last messages plain text and unix timestamp with the socket event to save the need for an extra call. We should be cautious to trim this string.
public updateRoomsListByLastChatMessage(lastChatMessage: ChatMessageEdge): void {
let newValue: GetChatRoomsListQuery = cloneDeep(
this.apollo.client.readQuery<GetChatRoomsListQuery>({
query: GetChatRoomsListDocument,
variables: {
first: PAGE_SIZE,
},
})
);
if (!newValue) return;
newValue.chatRoomList.edges.map(edge => {
if (edge.node.guid === lastChatMessage.node.roomGuid) {
edge.lastMessagePlainText = lastChatMessage.node.plainText;
edge.lastMessageCreatedTimestamp = parseInt(lastChatMessage.node.timeCreatedUnix);
}
return edge;
});
this.apollo.client.writeQuery<GetChatRoomsListQuery>({
query: GetChatRoomsListDocument,
variables: {
first: PAGE_SIZE,
},
data: newValue
})
}
Acceptance Criteria
-
Room list message and timestamp for room update when a new message comes in for sender and receiver.
QA
Test the AC.
UX/Design
N/A
Mobile
-
Is Mobile Required?
Personas
Chat users.
Experiments
All covered by epic feat flag.
Definition of Ready Checklist
-
Definition Of Done (DoD) -
Acceptance criteria -
Weighted -
QA -
UX/Design -
Personas -
Experiments