Switch to the /v2/ storage-service endpoints for group operations
This commit is contained in:
parent
711f7d3352
commit
408444352f
6 changed files with 68 additions and 36 deletions
|
@ -211,7 +211,7 @@
|
|||
"@formatjs/intl": "2.6.7",
|
||||
"@indutny/rezip-electron": "1.3.1",
|
||||
"@mixer/parallel-prettier": "2.0.3",
|
||||
"@signalapp/mock-server": "6.3.0",
|
||||
"@signalapp/mock-server": "6.4.1",
|
||||
"@storybook/addon-a11y": "7.4.5",
|
||||
"@storybook/addon-actions": "7.4.5",
|
||||
"@storybook/addon-controls": "7.4.5",
|
||||
|
|
|
@ -220,6 +220,19 @@ message GroupChange {
|
|||
uint32 changeEpoch = 3; // Allows clients to decide whether their change logic can successfully apply this diff
|
||||
}
|
||||
|
||||
// External credentials
|
||||
|
||||
message ExternalGroupCredential {
|
||||
string token = 1;
|
||||
}
|
||||
|
||||
// API responses
|
||||
|
||||
message GroupResponse {
|
||||
Group group = 1;
|
||||
bytes groupSendEndorsementResponse = 2;
|
||||
}
|
||||
|
||||
message GroupChanges {
|
||||
message GroupChangeState {
|
||||
GroupChange groupChange = 1;
|
||||
|
@ -227,6 +240,12 @@ message GroupChanges {
|
|||
}
|
||||
|
||||
repeated GroupChangeState groupChanges = 1;
|
||||
bytes groupSendEndorsementResponse = 2;
|
||||
}
|
||||
|
||||
message GroupChangeResponse {
|
||||
GroupChange groupChange = 1;
|
||||
bytes groupSendEndorsementResponse = 2;
|
||||
}
|
||||
|
||||
message GroupAttributeBlob {
|
||||
|
@ -238,10 +257,6 @@ message GroupAttributeBlob {
|
|||
}
|
||||
}
|
||||
|
||||
message GroupExternalCredential {
|
||||
string token = 1;
|
||||
}
|
||||
|
||||
message GroupInviteLink {
|
||||
message GroupInviteLinkContentsV1 {
|
||||
bytes groupMasterKey = 1;
|
||||
|
|
16
ts/groups.ts
16
ts/groups.ts
|
@ -1446,7 +1446,7 @@ async function uploadGroupChange({
|
|||
actions: Proto.GroupChange.IActions;
|
||||
group: ConversationAttributesType;
|
||||
inviteLinkPassword?: string;
|
||||
}): Promise<Proto.IGroupChange> {
|
||||
}): Promise<Proto.IGroupChangeResponse> {
|
||||
const logId = idForLogging(group.groupId);
|
||||
|
||||
// Ensure we have the credentials we need before attempting GroupsV2 operations
|
||||
|
@ -1552,11 +1552,13 @@ export async function modifyGroupV2({
|
|||
}
|
||||
|
||||
// Upload. If we don't have permission, the server will return an error here.
|
||||
const groupChange = await uploadGroupChange({
|
||||
const groupChangeResponse = await uploadGroupChange({
|
||||
actions,
|
||||
inviteLinkPassword,
|
||||
group: conversation.attributes,
|
||||
});
|
||||
const { groupChange } = groupChangeResponse;
|
||||
strictAssert(groupChange, 'missing groupChange');
|
||||
|
||||
const groupChangeBuffer =
|
||||
Proto.GroupChange.encode(groupChange).finish();
|
||||
|
@ -2738,12 +2740,13 @@ export async function respondToGroupV2Migration({
|
|||
`respondToGroupV2Migration/${logId}: Failed to access log endpoint; fetching full group state`
|
||||
);
|
||||
try {
|
||||
firstGroupState = await makeRequestWithCredentials({
|
||||
const groupResponse = await makeRequestWithCredentials({
|
||||
logId: `getGroup/${logId}`,
|
||||
publicParams,
|
||||
secretParams,
|
||||
request: (sender, options) => sender.getGroup(options),
|
||||
});
|
||||
firstGroupState = groupResponse.group;
|
||||
} catch (secondError) {
|
||||
if (secondError.code === GROUP_ACCESS_DENIED_CODE) {
|
||||
log.info(
|
||||
|
@ -3652,13 +3655,16 @@ async function updateGroupViaState({
|
|||
throw new Error('updateGroupViaState: group was missing publicParams!');
|
||||
}
|
||||
|
||||
const groupState = await makeRequestWithCredentials({
|
||||
const groupResponse = await makeRequestWithCredentials({
|
||||
logId: `getGroup/${logId}`,
|
||||
publicParams,
|
||||
secretParams,
|
||||
request: (sender, requestOptions) => sender.getGroup(requestOptions),
|
||||
});
|
||||
|
||||
const groupState = groupResponse.group;
|
||||
strictAssert(groupState, 'Group state must be present');
|
||||
|
||||
const decryptedGroupState = decryptGroupState(
|
||||
groupState,
|
||||
secretParams,
|
||||
|
@ -3792,7 +3798,7 @@ async function updateGroupViaLogs({
|
|||
// `integrateGroupChanges`.
|
||||
let revisionToFetch = isNumber(currentRevision) ? currentRevision : undefined;
|
||||
|
||||
let response;
|
||||
let response: GroupLogResponseType;
|
||||
const changes: Array<Proto.IGroupChanges> = [];
|
||||
do {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
|
|
|
@ -2153,7 +2153,7 @@ export default class MessageSender {
|
|||
async createGroup(
|
||||
group: Readonly<Proto.IGroup>,
|
||||
options: Readonly<GroupCredentialsType>
|
||||
): Promise<void> {
|
||||
): Promise<Proto.IGroupResponse> {
|
||||
return this.server.createGroup(group, options);
|
||||
}
|
||||
|
||||
|
@ -2166,7 +2166,7 @@ export default class MessageSender {
|
|||
|
||||
async getGroup(
|
||||
options: Readonly<GroupCredentialsType>
|
||||
): Promise<Proto.Group> {
|
||||
): Promise<Proto.IGroupResponse> {
|
||||
return this.server.getGroup(options);
|
||||
}
|
||||
|
||||
|
@ -2192,7 +2192,7 @@ export default class MessageSender {
|
|||
changes: Readonly<Proto.GroupChange.IActions>,
|
||||
options: Readonly<GroupCredentialsType>,
|
||||
inviteLinkBase64?: string
|
||||
): Promise<Proto.IGroupChange> {
|
||||
): Promise<Proto.IGroupChangeResponse> {
|
||||
return this.server.modifyGroup(changes, options, inviteLinkBase64);
|
||||
}
|
||||
|
||||
|
@ -2243,8 +2243,8 @@ export default class MessageSender {
|
|||
|
||||
async getGroupMembershipToken(
|
||||
options: Readonly<GroupCredentialsType>
|
||||
): Promise<Proto.GroupExternalCredential> {
|
||||
return this.server.getGroupExternalCredential(options);
|
||||
): Promise<Proto.IExternalGroupCredential> {
|
||||
return this.server.getExternalGroupCredential(options);
|
||||
}
|
||||
|
||||
public async sendChallengeResponse(
|
||||
|
|
|
@ -538,9 +538,9 @@ const URL_CALLS = {
|
|||
getBackupCDNCredentials: 'v1/archives/auth/read',
|
||||
getBackupUploadForm: 'v1/archives/upload/form',
|
||||
getBackupMediaUploadForm: 'v1/archives/media/upload/form',
|
||||
groupLog: 'v1/groups/logs',
|
||||
groupLog: 'v2/groups/logs',
|
||||
groupJoinedAtVersion: 'v1/groups/joined_at_version',
|
||||
groups: 'v1/groups',
|
||||
groups: 'v2/groups',
|
||||
groupsViaLink: 'v1/groups/join/',
|
||||
groupToken: 'v1/groups/token',
|
||||
keys: 'v2/keys',
|
||||
|
@ -715,6 +715,7 @@ export type GroupLogResponseType = {
|
|||
start?: number;
|
||||
end?: number;
|
||||
changes: Proto.GroupChanges;
|
||||
groupSendEndorsementResponse: Uint8Array | null;
|
||||
};
|
||||
|
||||
export type ProfileRequestDataType = {
|
||||
|
@ -1144,7 +1145,7 @@ export type WebAPIType = {
|
|||
createGroup: (
|
||||
group: Proto.IGroup,
|
||||
options: GroupCredentialsType
|
||||
) => Promise<void>;
|
||||
) => Promise<Proto.IGroupResponse>;
|
||||
deleteUsername: (abortSignal?: AbortSignal) => Promise<void>;
|
||||
downloadOnboardingStories: (
|
||||
version: string,
|
||||
|
@ -1172,7 +1173,7 @@ export type WebAPIType = {
|
|||
}) => Promise<Readable>;
|
||||
getAvatar: (path: string) => Promise<Uint8Array>;
|
||||
getHasSubscription: (subscriberId: Uint8Array) => Promise<boolean>;
|
||||
getGroup: (options: GroupCredentialsType) => Promise<Proto.Group>;
|
||||
getGroup: (options: GroupCredentialsType) => Promise<Proto.IGroupResponse>;
|
||||
getGroupFromLink: (
|
||||
inviteLinkPassword: string | undefined,
|
||||
auth: GroupCredentialsType
|
||||
|
@ -1181,9 +1182,9 @@ export type WebAPIType = {
|
|||
getGroupCredentials: (
|
||||
options: GetGroupCredentialsOptionsType
|
||||
) => Promise<GetGroupCredentialsResultType>;
|
||||
getGroupExternalCredential: (
|
||||
getExternalGroupCredential: (
|
||||
options: GroupCredentialsType
|
||||
) => Promise<Proto.GroupExternalCredential>;
|
||||
) => Promise<Proto.IExternalGroupCredential>;
|
||||
getGroupLog: (
|
||||
options: GetGroupLogOptionsType,
|
||||
credentials: GroupCredentialsType
|
||||
|
@ -1253,7 +1254,7 @@ export type WebAPIType = {
|
|||
changes: Proto.GroupChange.IActions,
|
||||
options: GroupCredentialsType,
|
||||
inviteLinkBase64?: string
|
||||
) => Promise<Proto.IGroupChange>;
|
||||
) => Promise<Proto.IGroupChangeResponse>;
|
||||
modifyStorageRecords: MessageSender['modifyStorageRecords'];
|
||||
postBatchIdentityCheck: (
|
||||
elements: VerifyServiceIdRequestType
|
||||
|
@ -1662,7 +1663,7 @@ export function initialize({
|
|||
getGroup,
|
||||
getGroupAvatar,
|
||||
getGroupCredentials,
|
||||
getGroupExternalCredential,
|
||||
getExternalGroupCredential,
|
||||
getGroupFromLink,
|
||||
getGroupLog,
|
||||
getHasSubscription,
|
||||
|
@ -3605,9 +3606,9 @@ export function initialize({
|
|||
return response;
|
||||
}
|
||||
|
||||
async function getGroupExternalCredential(
|
||||
async function getExternalGroupCredential(
|
||||
options: GroupCredentialsType
|
||||
): Promise<Proto.GroupExternalCredential> {
|
||||
): Promise<Proto.IExternalGroupCredential> {
|
||||
const basicAuth = generateGroupAuth(
|
||||
options.groupPublicParamsHex,
|
||||
options.authCredentialPresentationHex
|
||||
|
@ -3623,7 +3624,7 @@ export function initialize({
|
|||
disableSessionResumption: true,
|
||||
});
|
||||
|
||||
return Proto.GroupExternalCredential.decode(response);
|
||||
return Proto.ExternalGroupCredential.decode(response);
|
||||
}
|
||||
|
||||
function verifyAttributes(attributes: Proto.IAvatarUploadAttributes) {
|
||||
|
@ -3727,14 +3728,14 @@ export function initialize({
|
|||
async function createGroup(
|
||||
group: Proto.IGroup,
|
||||
options: GroupCredentialsType
|
||||
): Promise<void> {
|
||||
): Promise<Proto.IGroupResponse> {
|
||||
const basicAuth = generateGroupAuth(
|
||||
options.groupPublicParamsHex,
|
||||
options.authCredentialPresentationHex
|
||||
);
|
||||
const data = Proto.Group.encode(group).finish();
|
||||
|
||||
await _ajax({
|
||||
const response = await _ajax({
|
||||
basicAuth,
|
||||
call: 'groups',
|
||||
contentType: 'application/x-protobuf',
|
||||
|
@ -3742,12 +3743,15 @@ export function initialize({
|
|||
host: storageUrl,
|
||||
disableSessionResumption: true,
|
||||
httpType: 'PUT',
|
||||
responseType: 'bytes',
|
||||
});
|
||||
|
||||
return Proto.GroupResponse.decode(response);
|
||||
}
|
||||
|
||||
async function getGroup(
|
||||
options: GroupCredentialsType
|
||||
): Promise<Proto.Group> {
|
||||
): Promise<Proto.IGroupResponse> {
|
||||
const basicAuth = generateGroupAuth(
|
||||
options.groupPublicParamsHex,
|
||||
options.authCredentialPresentationHex
|
||||
|
@ -3763,7 +3767,7 @@ export function initialize({
|
|||
responseType: 'bytes',
|
||||
});
|
||||
|
||||
return Proto.Group.decode(response);
|
||||
return Proto.GroupResponse.decode(response);
|
||||
}
|
||||
|
||||
async function getGroupFromLink(
|
||||
|
@ -3799,7 +3803,7 @@ export function initialize({
|
|||
changes: Proto.GroupChange.IActions,
|
||||
options: GroupCredentialsType,
|
||||
inviteLinkBase64?: string
|
||||
): Promise<Proto.IGroupChange> {
|
||||
): Promise<Proto.IGroupChangeResponse> {
|
||||
const basicAuth = generateGroupAuth(
|
||||
options.groupPublicParamsHex,
|
||||
options.authCredentialPresentationHex
|
||||
|
@ -3826,7 +3830,7 @@ export function initialize({
|
|||
: undefined,
|
||||
});
|
||||
|
||||
return Proto.GroupChange.decode(response);
|
||||
return Proto.GroupChangeResponse.decode(response);
|
||||
}
|
||||
|
||||
async function getGroupLog(
|
||||
|
@ -3876,6 +3880,10 @@ export function initialize({
|
|||
disableSessionResumption: true,
|
||||
httpType: 'GET',
|
||||
responseType: 'byteswithdetails',
|
||||
headers: {
|
||||
// TODO(jamie): To be implmented in DESKTOP-699
|
||||
'Cached-Send-Endorsements': '0',
|
||||
},
|
||||
urlParameters:
|
||||
`/${startVersion}?` +
|
||||
`includeFirstState=${Boolean(includeFirstState)}&` +
|
||||
|
@ -3884,6 +3892,7 @@ export function initialize({
|
|||
});
|
||||
const { data, response } = withDetails;
|
||||
const changes = Proto.GroupChanges.decode(data);
|
||||
const { groupSendEndorsementResponse } = changes;
|
||||
|
||||
if (response && response.status === 206) {
|
||||
const range = response.headers.get('Content-Range');
|
||||
|
@ -3904,12 +3913,14 @@ export function initialize({
|
|||
start,
|
||||
end,
|
||||
currentRevision,
|
||||
groupSendEndorsementResponse,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
changes,
|
||||
groupSendEndorsementResponse,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -4001,10 +4001,10 @@
|
|||
type-fest "^3.5.0"
|
||||
uuid "^8.3.0"
|
||||
|
||||
"@signalapp/mock-server@6.3.0":
|
||||
version "6.3.0"
|
||||
resolved "https://registry.yarnpkg.com/@signalapp/mock-server/-/mock-server-6.3.0.tgz#5715fc1ff4517310caacc767ab4790530f11c673"
|
||||
integrity sha512-mC4QXqS7+MH1p3U7kTuUqJsFUHfBZ6wemuzvQvhk3+4bRoc77Wynu1uIN0WRLhx/faOGwBkSiAWNiLhQt0Vscw==
|
||||
"@signalapp/mock-server@6.4.1":
|
||||
version "6.4.1"
|
||||
resolved "https://registry.yarnpkg.com/@signalapp/mock-server/-/mock-server-6.4.1.tgz#b49700f8d43b0c76d3f02820dd3b3da82a910f12"
|
||||
integrity sha512-is75JwGL2CjLJ3NakMxw6rkgx379aKc3n328lSaiwLKVgBpuG/ms8wF3fNALxFstKoMl41lPzooOMWeqm+ubVQ==
|
||||
dependencies:
|
||||
"@signalapp/libsignal-client" "^0.42.0"
|
||||
debug "^4.3.2"
|
||||
|
|
Loading…
Reference in a new issue