putting in check if there is activity in a chat which I haven't viewed

This commit is contained in:
Arjun Patel
2022-02-04 00:20:35 -08:00
parent 322df9211d
commit f749729212
4 changed files with 60 additions and 13 deletions
+44 -6
View File
@@ -29,6 +29,8 @@ export enum RecoilActions {
LIVE_ROOMS = "LIVE_ROOMS",
RELATIVE_TIME_SECTIONS_CONVOS = "RELATIVE_TIME_SECTIONS_CONVOS",
CHECK_INCOMING_MESSAGE = "CHECK_INCOMING_MESSAGE",
ALL_RELEVANT_CONTACTS = "ALL_RELEVANT_CONTACTS",
RELEVANT_CONTACTS_SELECTOR_CACHE = "RELEVANT_CONTACTS_SELECTOR_CACHE",
@@ -62,12 +64,12 @@ export const allRelevantConversationsAtom = atom({
key: RecoilActions.ALL_RELEVANT_CONVERSATIONS,
default: new Map<string, Conversation>(),
effects: [
({ onSet }) => {
onSet((newMap) => {
//go through and make sure that our relevant user's cache is up to date
// const allUsersInConvos = newMap.values()
});
},
// ({ onSet }) => {
// onSet((newMap) => {
// //go through and make sure that our relevant user's cache is up to date
// // const allUsersInConvos = newMap.values()
// });
// },
],
});
@@ -196,6 +198,42 @@ export const RelativeTimeSeparatedConvosSelector = selector<
},
});
export const checkIncomingMessageSelector = selectorFamily({
key: RecoilActions.CHECK_INCOMING_MESSAGE,
get:
(convoId: string) =>
({ get }) => {
const currConvosMap: Map<string, Conversation> = get(
allRelevantConversationsAtom
);
const currUserConvoMembersMap = get(allUsersConversationsAtom);
// true if our last interaction date is < lastActivityDate
const currConvo = currConvosMap.get(convoId);
const currUserConvoAssoc = currUserConvoMembersMap.get(convoId);
if (!currConvo || !currUserConvoAssoc) {
return false;
}
if (!currUserConvoAssoc?.lastInteractionDate) {
return true;
}
if (
currConvo.lastActivityDate.toDate() >
currUserConvoAssoc.lastInteractionDate?.toDate()
) {
return true;
}
return false;
// todo: if it's incoming and it's in done/archive, then move it into the inbox by updating userConvoMember relationship
},
});
// map cache of all relevant users
// get all of the users in all of the conversations, once through a simple service call
export const allRelevantContactsAtom = atom<Map<string, NirvanaUser>>({