Switch to the /v2/ storage-service endpoints for group operations

This commit is contained in:
Jamie Kyle 2024-05-03 17:42:11 -07:00 committed by GitHub
parent 711f7d3352
commit 408444352f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 68 additions and 36 deletions

View file

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