Adding more PR review changes.

This commit is contained in:
warrickct 2022-02-11 14:05:51 +11:00
parent 36ca2a767c
commit f93a2e5fad
5 changed files with 14 additions and 42 deletions

View file

@ -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;

View file

@ -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

View file

@ -646,13 +646,9 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
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<ConversationAttributes> {
// 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<ConversationAttributes> {
}
}
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<ConversationAttributes> {
}
}
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({

View file

@ -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);

View file

@ -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');