forked from Ivasoft/mattermost-mobile
[Gekidou MM-3972] Websocket Events - Reaction and emojis (#5920)
* Wip
* update name so it references changing the reaction on a post
* handleAddEmoji -> handleAddCustomEmoji
* add remove reaction logic
* sanitizeReactions
* use skipSync to return early if not deleting any records that are
not in the server db
* return the filtered delete results and have the handler destroy the
records
* fix lint
* use forEach instead of map.
* PR feedback
* PR feedback
* Update app/actions/websocket/reactions.ts
* remove console.log
Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
This commit is contained in:
@@ -19,7 +19,7 @@ const {REACTION} = MM_TABLES.SERVER;
|
||||
* @param {RawReaction[]} sanitizeReactions.rawReactions
|
||||
* @returns {Promise<{createReactions: RawReaction[], deleteReactions: Reaction[]}>}
|
||||
*/
|
||||
export const sanitizeReactions = async ({database, post_id, rawReactions}: SanitizeReactionsArgs) => {
|
||||
export const sanitizeReactions = async ({database, post_id, rawReactions, skipSync}: SanitizeReactionsArgs) => {
|
||||
const reactions = (await database.collections.
|
||||
get(REACTION).
|
||||
query(Q.where('post_id', post_id)).
|
||||
@@ -45,10 +45,13 @@ export const sanitizeReactions = async ({database, post_id, rawReactions}: Sanit
|
||||
}
|
||||
}
|
||||
|
||||
if (skipSync) {
|
||||
return {createReactions, deleteReactions: []};
|
||||
}
|
||||
|
||||
// finding out elements to delete using array subtract
|
||||
const deleteReactions = reactions.
|
||||
filter((reaction) => !similarObjects.includes(reaction)).
|
||||
map((outCast) => outCast.prepareDestroyPermanently());
|
||||
filter((reaction) => !similarObjects.includes(reaction));
|
||||
|
||||
return {createReactions, deleteReactions};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user