fix: track hidden mods and admins if we get them

pull/2423/head
Audric Ackermann 3 years ago
parent ef9b2dfc80
commit 5266a24d88

@ -1446,6 +1446,8 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
admins?: Array<string>;
image_id?: number;
moderators?: Array<string>;
hidden_admins?: Array<string>;
hidden_moderators?: Array<string>;
};
}) {
if (!infos || isEmpty(infos)) {
@ -1477,26 +1479,21 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
this.set('uploadCapability', Boolean(upload));
}
if (details.admins && isArray(details.admins)) {
const replacedWithOurRealSessionId = await this.replaceWithOurRealSessionId(details.admins);
const adminChanged = await this.updateGroupAdmins(replacedWithOurRealSessionId, false);
if (adminChanged) {
hasChange = adminChanged;
}
}
const adminChanged = await this.handleModsOrAdminsChanges({
modsOrAdmins: details.admins,
hiddenModsOrAdmins: details.hidden_admins,
type: 'admins',
});
if (details.moderators && isArray(details.moderators)) {
const replacedWithOurRealSessionId = await this.replaceWithOurRealSessionId(
details.moderators
);
const moderatorsChanged = await this.updateGroupModerators(
replacedWithOurRealSessionId,
false
);
if (moderatorsChanged) {
hasChange = moderatorsChanged;
}
}
hasChange = hasChange || adminChanged;
const modsChanged = await this.handleModsOrAdminsChanges({
modsOrAdmins: details.moderators,
hiddenModsOrAdmins: details.hidden_moderators,
type: 'mods',
});
hasChange = hasChange || modsChanged;
if (this.isOpenGroupV2() && details.image_id && isNumber(details.image_id)) {
const roomInfos = OpenGroupData.getV2OpenGroupRoom(this.id);
@ -1926,6 +1923,34 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
);
return replacedWithOurRealSessionId;
}
private async handleModsOrAdminsChanges({
modsOrAdmins,
hiddenModsOrAdmins,
type,
}: {
modsOrAdmins?: Array<string>;
hiddenModsOrAdmins?: Array<string>;
type: 'mods' | 'admins';
}) {
if (modsOrAdmins && isArray(modsOrAdmins)) {
const localModsOrAdmins = [...modsOrAdmins];
if (hiddenModsOrAdmins && isArray(hiddenModsOrAdmins)) {
localModsOrAdmins.push(...hiddenModsOrAdmins);
}
const replacedWithOurRealSessionId = await this.replaceWithOurRealSessionId(
uniq(localModsOrAdmins)
);
const moderatorsOrAdminsChanged =
type === 'admins'
? await this.updateGroupAdmins(replacedWithOurRealSessionId, false)
: await this.updateGroupModerators(replacedWithOurRealSessionId, false);
return moderatorsOrAdminsChanged;
}
return false;
}
}
const throttledAllConversationsDispatch = debounce(

@ -208,7 +208,6 @@ export class OpenGroupServerPoller {
pollInfo: {
roomId,
infoUpdated: 0,
// infoUpdated: -1,
},
});

@ -73,7 +73,13 @@ async function handlePollInfoResponse(
token: string;
upload: boolean;
write: boolean;
details: { admins?: Array<string>; image_id: number; moderators?: Array<string> };
details: {
admins?: Array<string>;
image_id: number;
moderators?: Array<string>;
hidden_admins?: Array<string>;
hidden_moderators?: Array<string>;
};
},
serverUrl: string,
roomIdsStillPolled: Set<string>
@ -109,7 +115,14 @@ async function handlePollInfoResponse(
write,
upload,
subscriberCount: active_users,
details: pick(details, 'admins', 'image_id', 'moderators'),
details: pick(
details,
'admins',
'image_id',
'moderators',
'hidden_admins',
'hidden_moderators'
),
});
}

Loading…
Cancel
Save