diff --git a/app/sql.js b/app/sql.js index 0a9455bf5..30a10281e 100644 --- a/app/sql.js +++ b/app/sql.js @@ -1338,9 +1338,9 @@ function updateToLokiSchemaVersion19(currentVersion, db) { function updateToLokiSchemaVersion20(currentVersion, db) { const targetVersion = 20; - // if (currentVersion >= targetVersion) { - // return; - // } + if (currentVersion >= targetVersion) { + return; + } console.log(`updateToLokiSchemaVersion${targetVersion}: starting...`); db.transaction(() => { db.exec(` @@ -1350,22 +1350,11 @@ function updateToLokiSchemaVersion20(currentVersion, db) { `); // all closed group admins - const closedGroupRows = db - .prepare( - ` - SELECT json FROM ${CONVERSATIONS_TABLE} WHERE - type = 'group' AND - id NOT LIKE 'publicChat:%'; - ` - ) - .all(); - - console.warn({ closedGroupRows }); + const closedGroupRows = getAllClosedGroupConversations(db, false) || []; const adminIds = closedGroupRows.map(json => { return jsonToObject(json).groupAdmins; }); - console.warn({ adminIds }); forEach(adminIds, id => { db.exec( ` @@ -2959,13 +2948,13 @@ function getMessagesCountByConversation(instance, conversationId) { return row ? row['count(*)'] : 0; } -function getAllClosedGroupConversationsV1(instance) { +function getAllClosedGroupConversations(instance, order = true) { const rows = (globalInstance || instance) .prepare( `SELECT json FROM ${CONVERSATIONS_TABLE} WHERE type = 'group' AND id NOT LIKE 'publicChat:%' - ORDER BY id ASC;` + ${order ? 'ORDER BY id ASC' : ''};` ) .all(); @@ -2981,7 +2970,7 @@ function remove05PrefixFromStringIfNeeded(str) { function updateExistingClosedGroupV1ToClosedGroupV2(db) { // the migration is called only once, so all current groups not being open groups are v1 closed group. - const allClosedGroupV1 = getAllClosedGroupConversationsV1(db) || []; + const allClosedGroupV1 = getAllClosedGroupConversations(db) || []; allClosedGroupV1.forEach(groupV1 => { const groupId = groupV1.id; diff --git a/ts/interactions/conversationInteractions.ts b/ts/interactions/conversationInteractions.ts index 23d24f12e..932fcab82 100644 --- a/ts/interactions/conversationInteractions.ts +++ b/ts/interactions/conversationInteractions.ts @@ -132,9 +132,10 @@ export const acceptConversation = async (conversationId: string, syncToDevices: } Promise.all([ - await convoToApprove.setIsApproved(true), - await convoToApprove.setDidApproveMe(true), + await convoToApprove.setIsApproved(true, false), + await convoToApprove.setDidApproveMe(true, false), ]); + convoToApprove.commit(); await convoToApprove.sendMessageRequestResponse(true); // Conversation was not approved before so a sync is needed diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index c78677f3a..b10a5e63d 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -646,13 +646,9 @@ export class ConversationModel extends Backbone.Model { const shouldApprove = !this.isApproved() && this.isPrivate(); const hasMsgsFromOther = (await getMessagesByConversation(this.id, { type: MessageDirection.incoming })).length > 0; - console.warn(hasMsgsFromOther); if (shouldApprove) { await this.setIsApproved(true); if (!this.didApproveMe() && hasMsgsFromOther) { - console.warn('This is a reply message sending message request acceptance response.'); - // TODO: if this is a reply, send messageRequestAccept - await this.setDidApproveMe(true); await this.sendMessageRequestResponse(true); void forceSyncConfigurationNowIfNeeded(); @@ -660,13 +656,6 @@ export class ConversationModel extends Backbone.Model { // void forceSyncConfigurationNowIfNeeded(); } - // TODO: remove once dev-tested - if (chatMessageParams.body?.includes('unapprove')) { - await this.setIsApproved(false); - await this.setDidApproveMe(false); - // void forceSyncConfigurationNowIfNeeded(); - } - if (this.isOpenGroupV2()) { const chatMessageOpenGroupV2 = new OpenGroupVisibleMessage(chatMessageParams); const roomInfos = this.toOpenGroupV2(); @@ -1209,7 +1198,7 @@ export class ConversationModel extends Backbone.Model { } } - public async setIsApproved(value: boolean) { + public async setIsApproved(value: boolean, commit: boolean = true) { if (value !== this.isApproved()) { window?.log?.info(`Setting ${this.attributes.profileName} isApproved to:: ${value}`); this.set({ @@ -1226,7 +1215,7 @@ export class ConversationModel extends Backbone.Model { } } - public async setDidApproveMe(value: boolean) { + public async setDidApproveMe(value: boolean, commit: boolean = false) { if (value !== this.didApproveMe()) { window?.log?.info(`Setting ${this.attributes.profileName} didApproveMe to:: ${value}`); this.set({ diff --git a/ts/receiver/closedGroups.ts b/ts/receiver/closedGroups.ts index 8e0cfdec8..20512aef4 100644 --- a/ts/receiver/closedGroups.ts +++ b/ts/receiver/closedGroups.ts @@ -112,15 +112,13 @@ export async function handleClosedGroupControlMessage( } if (type === Type.NEW) { if ( - getConversationController() + !getConversationController() .get(envelope.senderIdentity) - .isApproved() == false + .isApproved() ) { window?.log?.info( 'Received new closed group message from an unapproved sender -- dropping message.' ); - // TODO: remove console output - console.warn('Received unapproved closed group invite msg'); return; } await handleNewClosedGroup(envelope, groupUpdate); diff --git a/ts/receiver/queuedJob.ts b/ts/receiver/queuedJob.ts index b91cd081f..27e9cfab4 100644 --- a/ts/receiver/queuedJob.ts +++ b/ts/receiver/queuedJob.ts @@ -222,11 +222,6 @@ async function handleRegularMessage( if (type === 'outgoing') { await handleSyncedReceipts(message, conversation); - - // if (window.lokiFeatureFlags.useMessageRequests) { - // // assumes sync receipts are always from linked device outgoings - // await conversation.setIsApproved(true); - // } } const conversationActiveAt = conversation.get('active_at');