GroupV2: Always add profileKeys to newProfileKeys return value
This commit is contained in:
parent
a1c534ec0c
commit
987d3168e8
1 changed files with 34 additions and 50 deletions
84
ts/groups.ts
84
ts/groups.ts
|
@ -2498,7 +2498,7 @@ export async function respondToGroupV2Migration({
|
||||||
attributes.secretParams,
|
attributes.secretParams,
|
||||||
logId
|
logId
|
||||||
);
|
);
|
||||||
const newAttributes = await applyGroupState({
|
const { newAttributes, newProfileKeys } = await applyGroupState({
|
||||||
group: attributes,
|
group: attributes,
|
||||||
groupState,
|
groupState,
|
||||||
});
|
});
|
||||||
|
@ -2543,7 +2543,7 @@ export async function respondToGroupV2Migration({
|
||||||
updates: {
|
updates: {
|
||||||
newAttributes,
|
newAttributes,
|
||||||
groupChangeMessages,
|
groupChangeMessages,
|
||||||
members: [],
|
members: profileKeysToMembers(newProfileKeys),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3317,7 +3317,7 @@ async function integrateGroupChange({
|
||||||
logId
|
logId
|
||||||
);
|
);
|
||||||
|
|
||||||
const newAttributes = await applyGroupState({
|
const { newAttributes, newProfileKeys } = await applyGroupState({
|
||||||
group,
|
group,
|
||||||
groupState: decryptedGroupState,
|
groupState: decryptedGroupState,
|
||||||
sourceConversationId: isFirstFetch ? sourceConversationId : undefined,
|
sourceConversationId: isFirstFetch ? sourceConversationId : undefined,
|
||||||
|
@ -3330,7 +3330,7 @@ async function integrateGroupChange({
|
||||||
current: newAttributes,
|
current: newAttributes,
|
||||||
sourceConversationId: isFirstFetch ? sourceConversationId : undefined,
|
sourceConversationId: isFirstFetch ? sourceConversationId : undefined,
|
||||||
}),
|
}),
|
||||||
members: getMembers(decryptedGroupState),
|
members: profileKeysToMembers(newProfileKeys),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3358,10 +3358,7 @@ async function integrateGroupChange({
|
||||||
return {
|
return {
|
||||||
newAttributes,
|
newAttributes,
|
||||||
groupChangeMessages,
|
groupChangeMessages,
|
||||||
members: newProfileKeys.map(item => ({
|
members: profileKeysToMembers(newProfileKeys),
|
||||||
...item,
|
|
||||||
profileKey: arrayBufferToBase64(item.profileKey),
|
|
||||||
})),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3407,7 +3404,7 @@ async function getCurrentGroupState({
|
||||||
window.log.info(
|
window.log.info(
|
||||||
`getCurrentGroupState/${logId}: Applying full group state, from version ${oldVersion} to ${newVersion}.`
|
`getCurrentGroupState/${logId}: Applying full group state, from version ${oldVersion} to ${newVersion}.`
|
||||||
);
|
);
|
||||||
const newAttributes = await applyGroupState({
|
const { newAttributes, newProfileKeys } = await applyGroupState({
|
||||||
group,
|
group,
|
||||||
groupState: decryptedGroupState,
|
groupState: decryptedGroupState,
|
||||||
});
|
});
|
||||||
|
@ -3419,7 +3416,7 @@ async function getCurrentGroupState({
|
||||||
current: newAttributes,
|
current: newAttributes,
|
||||||
dropInitialJoinMessage,
|
dropInitialJoinMessage,
|
||||||
}),
|
}),
|
||||||
members: getMembers(decryptedGroupState),
|
members: profileKeysToMembers(newProfileKeys),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3827,14 +3824,10 @@ function extractDiffs({
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMembers(groupState: GroupClass) {
|
function profileKeysToMembers(items: Array<GroupChangeMemberType>) {
|
||||||
if (!groupState.members || !groupState.members.length) {
|
return items.map(item => ({
|
||||||
return [];
|
profileKey: arrayBufferToBase64(item.profileKey),
|
||||||
}
|
uuid: item.uuid,
|
||||||
|
|
||||||
return groupState.members.map((member: MemberClass) => ({
|
|
||||||
profileKey: arrayBufferToBase64(member.profileKey),
|
|
||||||
uuid: member.userId,
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3842,7 +3835,7 @@ type GroupChangeMemberType = {
|
||||||
profileKey: ArrayBuffer;
|
profileKey: ArrayBuffer;
|
||||||
uuid: string;
|
uuid: string;
|
||||||
};
|
};
|
||||||
type GroupChangeResultType = {
|
type GroupApplyResultType = {
|
||||||
newAttributes: ConversationAttributesType;
|
newAttributes: ConversationAttributesType;
|
||||||
newProfileKeys: Array<GroupChangeMemberType>;
|
newProfileKeys: Array<GroupChangeMemberType>;
|
||||||
};
|
};
|
||||||
|
@ -3855,7 +3848,7 @@ async function applyGroupChange({
|
||||||
actions: GroupChangeClass.Actions;
|
actions: GroupChangeClass.Actions;
|
||||||
group: ConversationAttributesType;
|
group: ConversationAttributesType;
|
||||||
sourceConversationId: string;
|
sourceConversationId: string;
|
||||||
}): Promise<GroupChangeResultType> {
|
}): Promise<GroupApplyResultType> {
|
||||||
const logId = idForLogging(group.groupId);
|
const logId = idForLogging(group.groupId);
|
||||||
const ourConversationId = window.ConversationController.getOurConversationId();
|
const ourConversationId = window.ConversationController.getOurConversationId();
|
||||||
|
|
||||||
|
@ -3894,12 +3887,7 @@ async function applyGroupChange({
|
||||||
|
|
||||||
const conversation = window.ConversationController.getOrCreate(
|
const conversation = window.ConversationController.getOrCreate(
|
||||||
added.userId,
|
added.userId,
|
||||||
'private',
|
'private'
|
||||||
{
|
|
||||||
profileKey: added.profileKey
|
|
||||||
? arrayBufferToBase64(added.profileKey)
|
|
||||||
: undefined,
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (members[conversation.id]) {
|
if (members[conversation.id]) {
|
||||||
|
@ -4085,10 +4073,7 @@ async function applyGroupChange({
|
||||||
|
|
||||||
const conversation = window.ConversationController.getOrCreate(
|
const conversation = window.ConversationController.getOrCreate(
|
||||||
uuid,
|
uuid,
|
||||||
'private',
|
'private'
|
||||||
{
|
|
||||||
profileKey: profileKey ? arrayBufferToBase64(profileKey) : undefined,
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const previousRecord = pendingMembers[conversation.id];
|
const previousRecord = pendingMembers[conversation.id];
|
||||||
|
@ -4426,12 +4411,13 @@ async function applyGroupState({
|
||||||
group: ConversationAttributesType;
|
group: ConversationAttributesType;
|
||||||
groupState: GroupClass;
|
groupState: GroupClass;
|
||||||
sourceConversationId?: string;
|
sourceConversationId?: string;
|
||||||
}): Promise<ConversationAttributesType> {
|
}): Promise<GroupApplyResultType> {
|
||||||
const logId = idForLogging(group.groupId);
|
const logId = idForLogging(group.groupId);
|
||||||
const ACCESS_ENUM = window.textsecure.protobuf.AccessControl.AccessRequired;
|
const ACCESS_ENUM = window.textsecure.protobuf.AccessControl.AccessRequired;
|
||||||
const MEMBER_ROLE_ENUM = window.textsecure.protobuf.Member.Role;
|
const MEMBER_ROLE_ENUM = window.textsecure.protobuf.Member.Role;
|
||||||
const version = groupState.version || 0;
|
const version = groupState.version || 0;
|
||||||
const result = { ...group };
|
const result = { ...group };
|
||||||
|
const newProfileKeys: Array<GroupChangeMemberType> = [];
|
||||||
|
|
||||||
// version
|
// version
|
||||||
result.revision = version;
|
result.revision = version;
|
||||||
|
@ -4480,12 +4466,7 @@ async function applyGroupState({
|
||||||
result.membersV2 = groupState.members.map((member: MemberClass) => {
|
result.membersV2 = groupState.members.map((member: MemberClass) => {
|
||||||
const conversation = window.ConversationController.getOrCreate(
|
const conversation = window.ConversationController.getOrCreate(
|
||||||
member.userId,
|
member.userId,
|
||||||
'private',
|
'private'
|
||||||
{
|
|
||||||
profileKey: member.profileKey
|
|
||||||
? arrayBufferToBase64(member.profileKey)
|
|
||||||
: undefined,
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (ourConversationId && conversation.id === ourConversationId) {
|
if (ourConversationId && conversation.id === ourConversationId) {
|
||||||
|
@ -4508,6 +4489,11 @@ async function applyGroupState({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newProfileKeys.push({
|
||||||
|
profileKey: member.profileKey,
|
||||||
|
uuid: member.userId,
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
role: member.role || MEMBER_ROLE_ENUM.DEFAULT,
|
role: member.role || MEMBER_ROLE_ENUM.DEFAULT,
|
||||||
joinedAtVersion: member.joinedAtVersion || version,
|
joinedAtVersion: member.joinedAtVersion || version,
|
||||||
|
@ -4526,12 +4512,7 @@ async function applyGroupState({
|
||||||
if (member.member && member.member.userId) {
|
if (member.member && member.member.userId) {
|
||||||
pending = window.ConversationController.getOrCreate(
|
pending = window.ConversationController.getOrCreate(
|
||||||
member.member.userId,
|
member.member.userId,
|
||||||
'private',
|
'private'
|
||||||
{
|
|
||||||
profileKey: member.member.profileKey
|
|
||||||
? arrayBufferToBase64(member.member.profileKey)
|
|
||||||
: undefined,
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
@ -4556,6 +4537,11 @@ async function applyGroupState({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newProfileKeys.push({
|
||||||
|
profileKey: member.member.profileKey,
|
||||||
|
uuid: member.member.userId,
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
addedByUserId: invitedBy.id,
|
addedByUserId: invitedBy.id,
|
||||||
conversationId: pending.id,
|
conversationId: pending.id,
|
||||||
|
@ -4575,12 +4561,7 @@ async function applyGroupState({
|
||||||
if (member.userId) {
|
if (member.userId) {
|
||||||
pending = window.ConversationController.getOrCreate(
|
pending = window.ConversationController.getOrCreate(
|
||||||
member.userId,
|
member.userId,
|
||||||
'private',
|
'private'
|
||||||
{
|
|
||||||
profileKey: member.profileKey
|
|
||||||
? arrayBufferToBase64(member.profileKey)
|
|
||||||
: undefined,
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
@ -4604,7 +4585,10 @@ async function applyGroupState({
|
||||||
result.groupInviteLinkPassword = undefined;
|
result.groupInviteLinkPassword = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return {
|
||||||
|
newAttributes: result,
|
||||||
|
newProfileKeys,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function isValidRole(role?: number): role is number {
|
function isValidRole(role?: number): role is number {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue