Adding more PR review changes.

pull/2170/head
warrickct 3 years ago
parent 36ca2a767c
commit f93a2e5fad

@ -1338,9 +1338,9 @@ function updateToLokiSchemaVersion19(currentVersion, db) {
function updateToLokiSchemaVersion20(currentVersion, db) { function updateToLokiSchemaVersion20(currentVersion, db) {
const targetVersion = 20; const targetVersion = 20;
// if (currentVersion >= targetVersion) { if (currentVersion >= targetVersion) {
// return; return;
// } }
console.log(`updateToLokiSchemaVersion${targetVersion}: starting...`); console.log(`updateToLokiSchemaVersion${targetVersion}: starting...`);
db.transaction(() => { db.transaction(() => {
db.exec(` db.exec(`
@ -1350,22 +1350,11 @@ function updateToLokiSchemaVersion20(currentVersion, db) {
`); `);
// all closed group admins // all closed group admins
const closedGroupRows = db const closedGroupRows = getAllClosedGroupConversations(db, false) || [];
.prepare(
`
SELECT json FROM ${CONVERSATIONS_TABLE} WHERE
type = 'group' AND
id NOT LIKE 'publicChat:%';
`
)
.all();
console.warn({ closedGroupRows });
const adminIds = closedGroupRows.map(json => { const adminIds = closedGroupRows.map(json => {
return jsonToObject(json).groupAdmins; return jsonToObject(json).groupAdmins;
}); });
console.warn({ adminIds });
forEach(adminIds, id => { forEach(adminIds, id => {
db.exec( db.exec(
` `
@ -2959,13 +2948,13 @@ function getMessagesCountByConversation(instance, conversationId) {
return row ? row['count(*)'] : 0; return row ? row['count(*)'] : 0;
} }
function getAllClosedGroupConversationsV1(instance) { function getAllClosedGroupConversations(instance, order = true) {
const rows = (globalInstance || instance) const rows = (globalInstance || instance)
.prepare( .prepare(
`SELECT json FROM ${CONVERSATIONS_TABLE} WHERE `SELECT json FROM ${CONVERSATIONS_TABLE} WHERE
type = 'group' AND type = 'group' AND
id NOT LIKE 'publicChat:%' id NOT LIKE 'publicChat:%'
ORDER BY id ASC;` ${order ? 'ORDER BY id ASC' : ''};`
) )
.all(); .all();
@ -2981,7 +2970,7 @@ function remove05PrefixFromStringIfNeeded(str) {
function updateExistingClosedGroupV1ToClosedGroupV2(db) { function updateExistingClosedGroupV1ToClosedGroupV2(db) {
// the migration is called only once, so all current groups not being open groups are v1 closed group. // 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 => { allClosedGroupV1.forEach(groupV1 => {
const groupId = groupV1.id; const groupId = groupV1.id;

@ -132,9 +132,10 @@ export const acceptConversation = async (conversationId: string, syncToDevices:
} }
Promise.all([ Promise.all([
await convoToApprove.setIsApproved(true), await convoToApprove.setIsApproved(true, false),
await convoToApprove.setDidApproveMe(true), await convoToApprove.setDidApproveMe(true, false),
]); ]);
convoToApprove.commit();
await convoToApprove.sendMessageRequestResponse(true); await convoToApprove.sendMessageRequestResponse(true);
// Conversation was not approved before so a sync is needed // Conversation was not approved before so a sync is needed

@ -646,13 +646,9 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
const shouldApprove = !this.isApproved() && this.isPrivate(); const shouldApprove = !this.isApproved() && this.isPrivate();
const hasMsgsFromOther = const hasMsgsFromOther =
(await getMessagesByConversation(this.id, { type: MessageDirection.incoming })).length > 0; (await getMessagesByConversation(this.id, { type: MessageDirection.incoming })).length > 0;
console.warn(hasMsgsFromOther);
if (shouldApprove) { if (shouldApprove) {
await this.setIsApproved(true); await this.setIsApproved(true);
if (!this.didApproveMe() && hasMsgsFromOther) { 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.setDidApproveMe(true);
await this.sendMessageRequestResponse(true); await this.sendMessageRequestResponse(true);
void forceSyncConfigurationNowIfNeeded(); void forceSyncConfigurationNowIfNeeded();
@ -660,13 +656,6 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
// void forceSyncConfigurationNowIfNeeded(); // 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()) { if (this.isOpenGroupV2()) {
const chatMessageOpenGroupV2 = new OpenGroupVisibleMessage(chatMessageParams); const chatMessageOpenGroupV2 = new OpenGroupVisibleMessage(chatMessageParams);
const roomInfos = this.toOpenGroupV2(); const roomInfos = this.toOpenGroupV2();
@ -1209,7 +1198,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
} }
} }
public async setIsApproved(value: boolean) { public async setIsApproved(value: boolean, commit: boolean = true) {
if (value !== this.isApproved()) { if (value !== this.isApproved()) {
window?.log?.info(`Setting ${this.attributes.profileName} isApproved to:: ${value}`); window?.log?.info(`Setting ${this.attributes.profileName} isApproved to:: ${value}`);
this.set({ this.set({
@ -1226,7 +1215,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
} }
} }
public async setDidApproveMe(value: boolean) { public async setDidApproveMe(value: boolean, commit: boolean = false) {
if (value !== this.didApproveMe()) { if (value !== this.didApproveMe()) {
window?.log?.info(`Setting ${this.attributes.profileName} didApproveMe to:: ${value}`); window?.log?.info(`Setting ${this.attributes.profileName} didApproveMe to:: ${value}`);
this.set({ this.set({

@ -112,15 +112,13 @@ export async function handleClosedGroupControlMessage(
} }
if (type === Type.NEW) { if (type === Type.NEW) {
if ( if (
getConversationController() !getConversationController()
.get(envelope.senderIdentity) .get(envelope.senderIdentity)
.isApproved() == false .isApproved()
) { ) {
window?.log?.info( window?.log?.info(
'Received new closed group message from an unapproved sender -- dropping message.' 'Received new closed group message from an unapproved sender -- dropping message.'
); );
// TODO: remove console output
console.warn('Received unapproved closed group invite msg');
return; return;
} }
await handleNewClosedGroup(envelope, groupUpdate); await handleNewClosedGroup(envelope, groupUpdate);

@ -222,11 +222,6 @@ async function handleRegularMessage(
if (type === 'outgoing') { if (type === 'outgoing') {
await handleSyncedReceipts(message, conversation); 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'); const conversationActiveAt = conversation.get('active_at');

Loading…
Cancel
Save