putting in check if there is activity in a chat which I haven't viewed
This commit is contained in:
@@ -6,7 +6,7 @@ export default class Conversation {
|
|||||||
|
|
||||||
name: string; // engineering, general, arjun, jacob and rachel...
|
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
|
activeMembers: string[]; // userIds
|
||||||
membersInLiveRoom: string[] = [] as string[]; // all members in a live call right now for this convo
|
membersInLiveRoom: string[] = [] as string[]; // all members in a live call right now for this convo
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ import {
|
|||||||
FaCheck,
|
FaCheck,
|
||||||
FaAngleRight,
|
FaAngleRight,
|
||||||
} from "react-icons/fa";
|
} from "react-icons/fa";
|
||||||
|
import { useRecoilValue } from "recoil";
|
||||||
|
import {
|
||||||
|
allRelevantConversationsAtom,
|
||||||
|
checkIncomingMessageSelector,
|
||||||
|
} from "../../recoil/main";
|
||||||
import { MasterAvatarGroupWithUserFetch } from "../UserDetails/MasterAvatarGroup";
|
import { MasterAvatarGroupWithUserFetch } from "../UserDetails/MasterAvatarGroup";
|
||||||
|
|
||||||
export default function ConversationFullRow(props: {
|
export default function ConversationFullRow(props: {
|
||||||
@@ -19,12 +24,19 @@ export default function ConversationFullRow(props: {
|
|||||||
quickUpdateText = `${props.conversation.cachedAudioClips[0].senderUserId} spoke just now...`;
|
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 (
|
return (
|
||||||
<span
|
<span
|
||||||
className="py-5 px-4 border-t border-t-slate-200 flex flex-row hover:bg-slate-50 transition-all
|
className="py-5 px-4 border-t border-t-slate-200 flex flex-row
|
||||||
items-center"
|
hover:bg-slate-50 transition-all items-center"
|
||||||
>
|
>
|
||||||
<FaCircle className="text-orange-500 mr-2 animate-pulse text-[0.75rem]" />
|
{isNewIncoming && (
|
||||||
|
<FaCircle className="text-orange-500 mr-2 animate-pulse text-[0.75rem]" />
|
||||||
|
)}
|
||||||
|
|
||||||
<span className="w-[15rem] flex flex-row items-center">
|
<span className="w-[15rem] flex flex-row items-center">
|
||||||
<MasterAvatarGroupWithUserFetch
|
<MasterAvatarGroupWithUserFetch
|
||||||
|
|||||||
@@ -107,14 +107,11 @@ export function MasterAvatarGroupWithUserFetch(props: {
|
|||||||
|
|
||||||
const resultUsers: User[] = [] as User[];
|
const resultUsers: User[] = [] as User[];
|
||||||
|
|
||||||
console.log(listOfOtherUsers);
|
|
||||||
listOfOtherUsers.forEach((oUser) => {
|
listOfOtherUsers.forEach((oUser) => {
|
||||||
if (relContactsMap.has(oUser)) {
|
if (relContactsMap.has(oUser)) {
|
||||||
resultUsers.push(relContactsMap.get(oUser)!);
|
resultUsers.push(relContactsMap.get(oUser)!);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("fetched users for frontend: ", resultUsers);
|
|
||||||
|
|
||||||
return <MasterAvatarGroup listOfUsers={resultUsers} {...props} />;
|
return <MasterAvatarGroup listOfUsers={resultUsers} {...props} />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ export enum RecoilActions {
|
|||||||
LIVE_ROOMS = "LIVE_ROOMS",
|
LIVE_ROOMS = "LIVE_ROOMS",
|
||||||
RELATIVE_TIME_SECTIONS_CONVOS = "RELATIVE_TIME_SECTIONS_CONVOS",
|
RELATIVE_TIME_SECTIONS_CONVOS = "RELATIVE_TIME_SECTIONS_CONVOS",
|
||||||
|
|
||||||
|
CHECK_INCOMING_MESSAGE = "CHECK_INCOMING_MESSAGE",
|
||||||
|
|
||||||
ALL_RELEVANT_CONTACTS = "ALL_RELEVANT_CONTACTS",
|
ALL_RELEVANT_CONTACTS = "ALL_RELEVANT_CONTACTS",
|
||||||
RELEVANT_CONTACTS_SELECTOR_CACHE = "RELEVANT_CONTACTS_SELECTOR_CACHE",
|
RELEVANT_CONTACTS_SELECTOR_CACHE = "RELEVANT_CONTACTS_SELECTOR_CACHE",
|
||||||
|
|
||||||
@@ -62,12 +64,12 @@ export const allRelevantConversationsAtom = atom({
|
|||||||
key: RecoilActions.ALL_RELEVANT_CONVERSATIONS,
|
key: RecoilActions.ALL_RELEVANT_CONVERSATIONS,
|
||||||
default: new Map<string, Conversation>(),
|
default: new Map<string, Conversation>(),
|
||||||
effects: [
|
effects: [
|
||||||
({ onSet }) => {
|
// ({ onSet }) => {
|
||||||
onSet((newMap) => {
|
// onSet((newMap) => {
|
||||||
//go through and make sure that our relevant user's cache is up to date
|
// //go through and make sure that our relevant user's cache is up to date
|
||||||
// const allUsersInConvos = newMap.values()
|
// // 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
|
// map cache of all relevant users
|
||||||
// get all of the users in all of the conversations, once through a simple service call
|
// get all of the users in all of the conversations, once through a simple service call
|
||||||
export const allRelevantContactsAtom = atom<Map<string, NirvanaUser>>({
|
export const allRelevantContactsAtom = atom<Map<string, NirvanaUser>>({
|
||||||
|
|||||||
Reference in New Issue
Block a user