Skip to content

Clean up server side code before placing chat messages to Vuex store

Tomas Vik requested to merge 2190-clean-up-serialize-chats into develop

Originally I thought that the restful.serializeChatsForTroupe is going to be called from mixin-vue-left-menu-data.js and so I found its usages and cleaned up the interfaces.

Then I realized that the mixin should be route agnostic and the chat messages serialization doesn't have to be extracted from chat-internal.js. Still, this refactoring should provide valuable insight to the logic of serializing messages.

Used options in restful.serializeChatsForTroupe

I was trying to understand how the serializeChatsForTroupe is used. We were passing down options object that contains mixed options for querying mongoose model and building serialization strategy. After further investigation I found that most likely only a handful of options is used and I would found useful to explicitly enumerate allowed options so further change of the code has to be only concerned by the limited number of options.

graph RL;
A[getChatSnapshotOptions] --limit,aroundId,unread--> B[chatInternal.renderChat]
B --> C[restful.serializeChatsForTroupe]
D[authorisor.populateSubTroupeCollection] --> C
E(bayeux message.ext.snapshot) --> D
F(collections/chat.getSnapshotExtras) --lookups--> E
G(infinite-mixin.getSnapshotState) --limit,beforeInclId--> E
H(non-webapp bayeux client) --???--> E

restful.serializeChatsForTroupe option summary

Used

  • chatService.findChatMessagesForTroupe - limit, aroundId, beforeInclId
  • restSerializer.ChatStrategy - unread, lookups

Available but currently not used by webapp

  • chatService.findChatMessagesForTroupe - skip, marker, userId, beforeId, afterId, sort, readPreference
  • restSerializer.ChatStrategy - lean

Taking a safer approach to restricting options

After further consideration and MR feedback, this MR is not going to limit the possible options, instead this MR only logs unexpected options and prepares the code for easy and informed restriction of possible options in the future.

Testing strategy

  • initial message load is working
  • loading users by clicking Details in the right toolbar is working
Edited by Tomas Vik

Merge request reports