Allow searching calls with legacy conversation id as peerId

This commit is contained in:
Jamie Kyle 2023-08-09 09:48:55 -07:00 committed by GitHub
parent e78da67a51
commit af0beb6d8e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 8 deletions

View file

@ -3356,6 +3356,7 @@ function getCallHistoryGroupDataSync(
const [createTempTable] = sql` const [createTempTable] = sql`
CREATE TEMP TABLE temp_callHistory_filtered_conversations ( CREATE TEMP TABLE temp_callHistory_filtered_conversations (
id TEXT,
uuid TEXT, uuid TEXT,
groupId TEXT groupId TEXT
); );
@ -3365,14 +3366,14 @@ function getCallHistoryGroupDataSync(
batchMultiVarQuery(db, conversationIds, ids => { batchMultiVarQuery(db, conversationIds, ids => {
const idList = sqlJoin( const idList = sqlJoin(
ids.map(id => sqlFragment`(${id})`), ids.map(id => sqlFragment`${id}`),
',' ','
); );
const [insertQuery, insertParams] = sql` const [insertQuery, insertParams] = sql`
INSERT INTO temp_callHistory_filtered_conversations INSERT INTO temp_callHistory_filtered_conversations
(uuid, groupId) (id, uuid, groupId)
SELECT uuid, groupId SELECT id, uuid, groupId
FROM conversations FROM conversations
WHERE conversations.id IN (${idList}); WHERE conversations.id IN (${idList});
`; `;
@ -3383,9 +3384,11 @@ function getCallHistoryGroupDataSync(
const innerJoin = const innerJoin =
conversationIds != null conversationIds != null
? sqlFragment` ? // peerId can be a conversation id (legacy), a uuid, or a groupId
sqlFragment`
INNER JOIN temp_callHistory_filtered_conversations ON ( INNER JOIN temp_callHistory_filtered_conversations ON (
temp_callHistory_filtered_conversations.uuid IS c.peerId temp_callHistory_filtered_conversations.id IS c.peerId
OR temp_callHistory_filtered_conversations.uuid IS c.peerId
OR temp_callHistory_filtered_conversations.groupId IS c.peerId OR temp_callHistory_filtered_conversations.groupId IS c.peerId
) )
` `

View file

@ -36,7 +36,7 @@ export default function updateToSchemaVersion87(
CREATE TABLE callsHistory ( CREATE TABLE callsHistory (
callId TEXT PRIMARY KEY, callId TEXT PRIMARY KEY,
peerId TEXT NOT NULL, -- conversation uuid | groupId | roomId peerId TEXT NOT NULL, -- conversation id (legacy) | uuid | groupId | roomId
ringerId TEXT DEFAULT NULL, -- ringer uuid ringerId TEXT DEFAULT NULL, -- ringer uuid
mode TEXT NOT NULL, -- enum "Direct" | "Group" mode TEXT NOT NULL, -- enum "Direct" | "Group"
type TEXT NOT NULL, -- enum "Audio" | "Video" | "Group" type TEXT NOT NULL, -- enum "Audio" | "Video" | "Group"

View file

@ -177,11 +177,11 @@ describe('sql/getCallHistoryGroups', () => {
callId: string, callId: string,
timestamp: number, timestamp: number,
mode: CallMode, mode: CallMode,
conversationId: string | UUIDStringType peerId: string | UUIDStringType
) { ) {
return { return {
callId, callId,
peerId: conversationId, peerId,
ringerId: null, ringerId: null,
mode, mode,
type: CallType.Video, type: CallType.Video,
@ -221,4 +221,41 @@ describe('sql/getCallHistoryGroups', () => {
assert.deepEqual(groups, [toGroup([call2])]); assert.deepEqual(groups, [toGroup([call2])]);
} }
}); });
it('should support legacy call history with conversation.id', async () => {
const now = Date.now();
const conversationId = getUuid();
const conversation: ConversationAttributesType = {
type: 'private',
version: 0,
id: conversationId,
};
await saveConversation(conversation);
const call = {
callId: '1',
peerId: conversationId,
ringerId: null,
mode: CallMode.Direct,
type: CallType.Video,
direction: CallDirection.Incoming,
timestamp: now,
status: DirectCallStatus.Accepted,
};
await saveCallHistory(call);
const groups = await getCallHistoryGroups(
{
status: CallHistoryFilterStatus.All,
conversationIds: [conversation.id],
},
{ offset: 0, limit: 0 }
);
assert.deepEqual(groups, [toGroup([call])]);
});
}); });