From e6914bf61d3eca44de3880c84d641c0b309cc6d6 Mon Sep 17 00:00:00 2001 From: Arjun Patel Date: Sun, 16 Jan 2022 14:18:39 -0800 Subject: [PATCH] fixing dat not updating with sent messages --- contexts/audioContext.tsx | 3 +++ contexts/teamDashboardContext.tsx | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/contexts/audioContext.tsx b/contexts/audioContext.tsx index 67de7b1..748422f 100644 --- a/contexts/audioContext.tsx +++ b/contexts/audioContext.tsx @@ -350,6 +350,9 @@ export default function AudioContextProvider({ children }) { messagesByTeamMate[selectedTeammate] && messagesByTeamMate[selectedTeammate].length > 0 ) { + console.log("playing from this cache"); + + console.log(messagesByTeamMate); setPlayerSrc(messagesByTeamMate[selectedTeammate][0].audioDataUrl); } else { toast("nothing to play"); diff --git a/contexts/teamDashboardContext.tsx b/contexts/teamDashboardContext.tsx index d572f33..3035bd1 100644 --- a/contexts/teamDashboardContext.tsx +++ b/contexts/teamDashboardContext.tsx @@ -208,6 +208,7 @@ export function TeamDashboardContextProvider({ children }) { // if the map contains the teammate userid already, then cool, just unshift to that array const newMap = { ...prevMap }; if (newMessage.receiverUserId in prevMap) { + // won't be in map if I am the receiver newMap[newMessage.receiverUserId] = [ newMessage, ...prevMap[newMessage.receiverUserId], @@ -218,6 +219,18 @@ export function TeamDashboardContextProvider({ children }) { newMap[newMessage.receiverUserId] = [newMessage]; } + // todo: if I am the receiver, still want to put it in the right conversation + if (newMessage.receiverUserId == currUser.uid) { + if (newMessage.senderUserId in prevMap) { + newMap[newMessage.senderUserId] = [ + newMessage, + ...prevMap[newMessage.senderUserId], + ]; + } else { + newMap[newMessage.senderUserId] = [newMessage]; + } + } + return newMap; }); }