Fix DM losing conversation list

This commit is contained in:
Bojan Mojsilovic 2024-03-18 16:31:02 +01:00
parent a885a3d513
commit 4e8cae5191
2 changed files with 9 additions and 5 deletions

View File

@ -77,6 +77,7 @@ export type MessagesContextStore = {
getNextConversationPage: () => void, getNextConversationPage: () => void,
addUserReference: (user: PrimalUser) => void, addUserReference: (user: PrimalUser) => void,
clearAllMessages: () => void, clearAllMessages: () => void,
clearReceiver: () => void,
} }
} }
@ -232,6 +233,11 @@ export const MessagesProvider = (props: { children: ContextChildren }) => {
updateStore('senders', reconcile({})); updateStore('senders', reconcile({}));
}; };
const clearReceiver = () => {
updateStore('activePubkey', () => undefined);
currentSender = '';
};
const getConversationWithSender = (sender: string | null, until = 0) => { const getConversationWithSender = (sender: string | null, until = 0) => {
if (!account?.isKeyLookupDone || !account.hasPublicKey() || !sender) { if (!account?.isKeyLookupDone || !account.hasPublicKey() || !sender) {
return; return;
@ -891,6 +897,7 @@ export const MessagesProvider = (props: { children: ContextChildren }) => {
getNextConversationPage, getNextConversationPage,
addUserReference, addUserReference,
clearAllMessages, clearAllMessages,
clearReceiver,
}, },
}); });

View File

@ -195,13 +195,9 @@ const Messages: Component = () => {
npubToHex(params.sender) : npubToHex(params.sender) :
params.sender; params.sender;
const url = currentUrl.startsWith('npub') ?
npubToHex(currentUrl) :
currentUrl;
if(currentUrl !== sender) { if(currentUrl !== sender) {
currentUrl = sender; currentUrl = sender;
messages?.actions.selectSender(sender); selectSender(sender);
} }
}); });
@ -622,6 +618,7 @@ const Messages: Component = () => {
newMessageInput && newMessageInput.removeEventListener('keydown', onKeyDown); newMessageInput && newMessageInput.removeEventListener('keydown', onKeyDown);
messages?.actions.clearAllMessages(); messages?.actions.clearAllMessages();
messages?.actions.selectSender(); messages?.actions.selectSender();
messages?.actions.clearReceiver();
}); });
const sendMessage = async () => { const sendMessage = async () => {