fixing bugs when it comes to selecting and tuning into the conversations
This commit is contained in:
@@ -158,12 +158,13 @@ export function ConversationProvider({ children }: { children: React.ReactNode }
|
|||||||
// add the conversation to the conversation map/client side cache
|
// add the conversation to the conversation map/client side cache
|
||||||
// has implications on realtime listening and also the ui on whether or not it's shown
|
// has implications on realtime listening and also the ui on whether or not it's shown
|
||||||
const handleAddConversationCache = useCallback(
|
const handleAddConversationCache = useCallback(
|
||||||
(conversation: Conversation) => {
|
(conversation: Conversation, temporaryOverrideSort = false) => {
|
||||||
setConversationMap((draft) => {
|
setConversationMap((draft) => {
|
||||||
draft[conversation._id.toString()] = {
|
draft[conversation._id.toString()] = {
|
||||||
...conversation,
|
...conversation,
|
||||||
tunedInUsers: [],
|
tunedInUsers: [],
|
||||||
connectedUserIds: [],
|
connectedUserIds: [],
|
||||||
|
temporaryOverrideSort,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -194,6 +195,7 @@ export function ConversationProvider({ children }: { children: React.ReactNode }
|
|||||||
* temporaryOverrideSort: tell me if you want to temporarily prioritize this conversation above all others
|
* temporaryOverrideSort: tell me if you want to temporarily prioritize this conversation above all others
|
||||||
*/
|
*/
|
||||||
// selecting an id and making sure that it's in the map and the views just use the id to access from map
|
// selecting an id and making sure that it's in the map and the views just use the id to access from map
|
||||||
|
// get conversation from universe...hit if it's local, miss and fetch if not here
|
||||||
const selectConversation = useCallback(
|
const selectConversation = useCallback(
|
||||||
async (conversationId: string, temporaryOverrideSort = false) => {
|
async (conversationId: string, temporaryOverrideSort = false) => {
|
||||||
/**
|
/**
|
||||||
@@ -210,7 +212,9 @@ export function ConversationProvider({ children }: { children: React.ReactNode }
|
|||||||
|
|
||||||
conversationToSelect = conversationMap[conversationId];
|
conversationToSelect = conversationMap[conversationId];
|
||||||
} else {
|
} else {
|
||||||
// fetch and add to conversation map
|
// TODO: somehow use handleAddToCache instead of this duplicated code
|
||||||
|
|
||||||
|
// fetch and add to master conversation cache
|
||||||
const retrieveConversationResult = await getConversationById(conversationId);
|
const retrieveConversationResult = await getConversationById(conversationId);
|
||||||
if (!retrieveConversationResult.data) {
|
if (!retrieveConversationResult.data) {
|
||||||
toast.error('unable to find conversation');
|
toast.error('unable to find conversation');
|
||||||
@@ -224,16 +228,19 @@ export function ConversationProvider({ children }: { children: React.ReactNode }
|
|||||||
temporaryOverrideSort,
|
temporaryOverrideSort,
|
||||||
};
|
};
|
||||||
|
|
||||||
conversationToSelect = newMasterConversation;
|
|
||||||
|
|
||||||
setConversationMap((draft) => {
|
setConversationMap((draft) => {
|
||||||
draft[conversationId] = newMasterConversation;
|
draft[conversationId] = newMasterConversation;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
conversationToSelect = newMasterConversation;
|
||||||
|
|
||||||
|
// connect to line so that we can listen in to changes
|
||||||
|
handleConnectToLine(newMasterConversation._id.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set selected conversation with full master conversation now that we have it
|
||||||
setSelectedConversation((prevConversation) => {
|
setSelectedConversation((prevConversation) => {
|
||||||
// only untune if it was an inbox conversation
|
// untune if it was an inbox conversation and we are going away from this conversation
|
||||||
|
|
||||||
if (prevConversation) {
|
if (prevConversation) {
|
||||||
const currMemberForConversation = prevConversation.members.find(
|
const currMemberForConversation = prevConversation.members.find(
|
||||||
(mem) => mem.email === user.email,
|
(mem) => mem.email === user.email,
|
||||||
@@ -256,6 +263,7 @@ export function ConversationProvider({ children }: { children: React.ReactNode }
|
|||||||
setConversationMap,
|
setConversationMap,
|
||||||
handleUntuneFromLine,
|
handleUntuneFromLine,
|
||||||
handleTuneIntoLine,
|
handleTuneIntoLine,
|
||||||
|
handleConnectToLine,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
// !temporary fix for updated conversation content not being surfaced
|
// !temporary fix for updated conversation content not being surfaced
|
||||||
|
|||||||
Reference in New Issue
Block a user