putting in check if there is activity in a chat which I haven't viewed
This commit is contained in:
@@ -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>>({
|
||||
|
||||
Reference in New Issue
Block a user