From f7497292122aee01332973f14a04e9f4f0716a09 Mon Sep 17 00:00:00 2001 From: Arjun Patel Date: Fri, 4 Feb 2022 00:20:35 -0800 Subject: [PATCH] putting in check if there is activity in a chat which I haven't viewed --- packages/common/models/conversation.ts | 2 +- .../Conversations/ConversationFullRow.tsx | 18 +++++-- .../UserDetails/MasterAvatarGroup.tsx | 3 -- packages/web/recoil/main.tsx | 50 ++++++++++++++++--- 4 files changed, 60 insertions(+), 13 deletions(-) diff --git a/packages/common/models/conversation.ts b/packages/common/models/conversation.ts index 890f596..7002c31 100644 --- a/packages/common/models/conversation.ts +++ b/packages/common/models/conversation.ts @@ -6,7 +6,7 @@ export default class Conversation { name: string; // engineering, general, arjun, jacob and rachel... - lastActivityDate?: Timestamp; // caching this for purpose of saving on listeners + lastActivityDate: Timestamp = Timestamp.now(); // caching this for purpose of saving on listeners activeMembers: string[]; // userIds membersInLiveRoom: string[] = [] as string[]; // all members in a live call right now for this convo diff --git a/packages/web/components/Conversations/ConversationFullRow.tsx b/packages/web/components/Conversations/ConversationFullRow.tsx index af7052c..94c237b 100644 --- a/packages/web/components/Conversations/ConversationFullRow.tsx +++ b/packages/web/components/Conversations/ConversationFullRow.tsx @@ -8,6 +8,11 @@ import { FaCheck, FaAngleRight, } from "react-icons/fa"; +import { useRecoilValue } from "recoil"; +import { + allRelevantConversationsAtom, + checkIncomingMessageSelector, +} from "../../recoil/main"; import { MasterAvatarGroupWithUserFetch } from "../UserDetails/MasterAvatarGroup"; export default function ConversationFullRow(props: { @@ -19,12 +24,19 @@ export default function ConversationFullRow(props: { quickUpdateText = `${props.conversation.cachedAudioClips[0].senderUserId} spoke just now...`; } + // check if I am outdate on a certain conversation + const isNewIncoming = useRecoilValue( + checkIncomingMessageSelector(props.conversation.id) + ); + return ( - + {isNewIncoming && ( + + )} { if (relContactsMap.has(oUser)) { resultUsers.push(relContactsMap.get(oUser)!); } }); - console.log("fetched users for frontend: ", resultUsers); - return ; } diff --git a/packages/web/recoil/main.tsx b/packages/web/recoil/main.tsx index c949432..6966be3 100644 --- a/packages/web/recoil/main.tsx +++ b/packages/web/recoil/main.tsx @@ -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(), 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 = 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>({