|
|
@ -1,4 +1,4 @@
|
|
|
|
import { uniq } from 'lodash';
|
|
|
|
import { isEmpty, uniq } from 'lodash';
|
|
|
|
import { BaseConvoInfoVolatile, ConvoVolatileType } from 'session_util_wrapper';
|
|
|
|
import { BaseConvoInfoVolatile, ConvoVolatileType } from 'session_util_wrapper';
|
|
|
|
import { Data } from '../../../data/data';
|
|
|
|
import { Data } from '../../../data/data';
|
|
|
|
import { OpenGroupData } from '../../../data/opengroups';
|
|
|
|
import { OpenGroupData } from '../../../data/opengroups';
|
|
|
@ -87,12 +87,12 @@ async function insertConvoFromDBIntoWrapperAndRefresh(convoId: string): Promise<
|
|
|
|
if (!foundConvo || !isConvoToStoreInWrapper(foundConvo)) {
|
|
|
|
if (!foundConvo || !isConvoToStoreInWrapper(foundConvo)) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const isForcedUnread = foundConvo.isMarkedUnread();
|
|
|
|
const isForcedUnread = foundConvo.isMarkedUnread();
|
|
|
|
const lastReadTimestampMessage = foundConvo.getCachedLastReadTimestampMessage() || 0;
|
|
|
|
const lastReadMessageTimestamp =
|
|
|
|
|
|
|
|
(await Data.fetchConvoMemoryDetails(convoId))?.lastReadTimestampMessage || 0;
|
|
|
|
|
|
|
|
|
|
|
|
console.info(
|
|
|
|
console.info(
|
|
|
|
`convoInfoVolatile:insert "${convoId}";lastMessageReadTimestamp:${lastReadTimestampMessage};forcedUnread:${isForcedUnread}...`
|
|
|
|
`convoInfoVolatile:insert "${convoId}";lastMessageReadTimestamp:${lastReadMessageTimestamp};forcedUnread:${isForcedUnread}...`
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
const convoType = getConvoType(foundConvo);
|
|
|
|
const convoType = getConvoType(foundConvo);
|
|
|
@ -102,7 +102,7 @@ async function insertConvoFromDBIntoWrapperAndRefresh(convoId: string): Promise<
|
|
|
|
// this saves the details for contacts and `Note To Self`
|
|
|
|
// this saves the details for contacts and `Note To Self`
|
|
|
|
await ConvoInfoVolatileWrapperActions.set1o1(
|
|
|
|
await ConvoInfoVolatileWrapperActions.set1o1(
|
|
|
|
convoId,
|
|
|
|
convoId,
|
|
|
|
lastReadTimestampMessage,
|
|
|
|
lastReadMessageTimestamp,
|
|
|
|
isForcedUnread
|
|
|
|
isForcedUnread
|
|
|
|
);
|
|
|
|
);
|
|
|
|
await refreshConvoVolatileCached(convoId, false, false);
|
|
|
|
await refreshConvoVolatileCached(convoId, false, false);
|
|
|
@ -116,7 +116,7 @@ async function insertConvoFromDBIntoWrapperAndRefresh(convoId: string): Promise<
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
await ConvoInfoVolatileWrapperActions.setLegacyGroup(
|
|
|
|
await ConvoInfoVolatileWrapperActions.setLegacyGroup(
|
|
|
|
convoId,
|
|
|
|
convoId,
|
|
|
|
lastReadTimestampMessage,
|
|
|
|
lastReadMessageTimestamp,
|
|
|
|
isForcedUnread
|
|
|
|
isForcedUnread
|
|
|
|
);
|
|
|
|
);
|
|
|
|
await refreshConvoVolatileCached(convoId, true, false);
|
|
|
|
await refreshConvoVolatileCached(convoId, true, false);
|
|
|
@ -124,14 +124,13 @@ async function insertConvoFromDBIntoWrapperAndRefresh(convoId: string): Promise<
|
|
|
|
window.log.warn(
|
|
|
|
window.log.warn(
|
|
|
|
`ConvoInfoVolatileWrapperActions.setLegacyGroup of ${convoId} failed with ${e.message}`
|
|
|
|
`ConvoInfoVolatileWrapperActions.setLegacyGroup of ${convoId} failed with ${e.message}`
|
|
|
|
);
|
|
|
|
);
|
|
|
|
// we stil let this go through
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'Community':
|
|
|
|
case 'Community':
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const asOpengroup = foundConvo.toOpenGroupV2();
|
|
|
|
const asOpengroup = foundConvo.toOpenGroupV2();
|
|
|
|
const roomDetails = OpenGroupData.getV2OpenGroupRoomByRoomId(asOpengroup);
|
|
|
|
const roomDetails = OpenGroupData.getV2OpenGroupRoomByRoomId(asOpengroup);
|
|
|
|
if (!roomDetails) {
|
|
|
|
if (!roomDetails || isEmpty(roomDetails.serverPublicKey)) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -141,18 +140,19 @@ async function insertConvoFromDBIntoWrapperAndRefresh(convoId: string): Promise<
|
|
|
|
roomDetails.roomId,
|
|
|
|
roomDetails.roomId,
|
|
|
|
roomDetails.serverPublicKey
|
|
|
|
roomDetails.serverPublicKey
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// this does the create or the update of the matching existing community
|
|
|
|
// this does the create or the update of the matching existing community
|
|
|
|
await ConvoInfoVolatileWrapperActions.setCommunityByFullUrl(
|
|
|
|
await ConvoInfoVolatileWrapperActions.setCommunityByFullUrl(
|
|
|
|
fullUrlWithPubkey,
|
|
|
|
fullUrlWithPubkey,
|
|
|
|
lastReadTimestampMessage,
|
|
|
|
lastReadMessageTimestamp,
|
|
|
|
isForcedUnread
|
|
|
|
isForcedUnread
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
await refreshConvoVolatileCached(convoId, false, false);
|
|
|
|
await refreshConvoVolatileCached(convoId, false, false);
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
window.log.warn(
|
|
|
|
window.log.warn(
|
|
|
|
`ConvoInfoVolatileWrapperActions.setCommunityByFullUrl of ${convoId} failed with ${e.message}`
|
|
|
|
`ConvoInfoVolatileWrapperActions.setCommunityByFullUrl of ${convoId} failed with ${e.message}`
|
|
|
|
);
|
|
|
|
);
|
|
|
|
// we still let this go through
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
@ -173,29 +173,46 @@ async function refreshConvoVolatileCached(
|
|
|
|
duringAppStart: boolean
|
|
|
|
duringAppStart: boolean
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
let convoType: ConvoVolatileType = '1o1';
|
|
|
|
let refreshed = false;
|
|
|
|
let refreshed = false;
|
|
|
|
|
|
|
|
|
|
|
|
if (OpenGroupUtils.isOpenGroupV2(convoId)) {
|
|
|
|
if (OpenGroupUtils.isOpenGroupV2(convoId)) {
|
|
|
|
const fromWrapper = await ConvoInfoVolatileWrapperActions.getCommunity(convoId);
|
|
|
|
convoType = 'Community';
|
|
|
|
if (fromWrapper && fromWrapper.fullUrlWithPubkey) {
|
|
|
|
|
|
|
|
mappedCommunityWrapperValues.set(convoId, fromWrapper);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshed = true;
|
|
|
|
|
|
|
|
} else if (convoId.startsWith('05') && isLegacyGroup) {
|
|
|
|
} else if (convoId.startsWith('05') && isLegacyGroup) {
|
|
|
|
const fromWrapper = await ConvoInfoVolatileWrapperActions.getLegacyGroup(convoId);
|
|
|
|
convoType = 'LegacyGroup';
|
|
|
|
if (fromWrapper) {
|
|
|
|
|
|
|
|
mappedLegacyGroupWrapperValues.set(convoId, fromWrapper);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshed = true;
|
|
|
|
|
|
|
|
} else if (convoId.startsWith('05')) {
|
|
|
|
} else if (convoId.startsWith('05')) {
|
|
|
|
const fromWrapper = await ConvoInfoVolatileWrapperActions.get1o1(convoId);
|
|
|
|
convoType = '1o1';
|
|
|
|
console.warn(
|
|
|
|
}
|
|
|
|
`refreshConvoVolatileCached from get1o1 ${fromWrapper?.pubkeyHex} : ${fromWrapper?.unread}`
|
|
|
|
|
|
|
|
);
|
|
|
|
switch (convoType) {
|
|
|
|
if (fromWrapper) {
|
|
|
|
case '1o1':
|
|
|
|
mapped1o1WrapperValues.set(convoId, fromWrapper);
|
|
|
|
const fromWrapper1o1 = await ConvoInfoVolatileWrapperActions.get1o1(convoId);
|
|
|
|
}
|
|
|
|
if (fromWrapper1o1) {
|
|
|
|
refreshed = true;
|
|
|
|
mapped1o1WrapperValues.set(convoId, fromWrapper1o1);
|
|
|
|
} // TODO handle the new closed groups once we got them ready
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshed = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'LegacyGroup':
|
|
|
|
|
|
|
|
const fromWrapperLegacyGroup = await ConvoInfoVolatileWrapperActions.getLegacyGroup(
|
|
|
|
|
|
|
|
convoId
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
if (fromWrapperLegacyGroup) {
|
|
|
|
|
|
|
|
mappedLegacyGroupWrapperValues.set(convoId, fromWrapperLegacyGroup);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshed = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'Community':
|
|
|
|
|
|
|
|
const fromWrapperCommunity = await ConvoInfoVolatileWrapperActions.getCommunity(convoId);
|
|
|
|
|
|
|
|
if (fromWrapperCommunity && fromWrapperCommunity.fullUrlWithPubkey) {
|
|
|
|
|
|
|
|
mappedCommunityWrapperValues.set(convoId, fromWrapperCommunity);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshed = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
assertUnreachable(convoType, `refreshConvoVolatileCached unhandled case "${convoType}"`);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO handle the new closed groups once we got them ready
|
|
|
|
|
|
|
|
|
|
|
|
if (refreshed && !duringAppStart) {
|
|
|
|
if (refreshed && !duringAppStart) {
|
|
|
|
getConversationController()
|
|
|
|
getConversationController()
|
|
|
|