Use new server params for group log fetch
This commit is contained in:
parent
0d19f9131b
commit
6de2710841
3 changed files with 59 additions and 17 deletions
22
ts/groups.ts
22
ts/groups.ts
|
@ -2541,7 +2541,16 @@ export async function respondToGroupV2Migration({
|
||||||
logId: `getGroupLog/${logId}`,
|
logId: `getGroupLog/${logId}`,
|
||||||
publicParams,
|
publicParams,
|
||||||
secretParams,
|
secretParams,
|
||||||
request: (sender, options) => sender.getGroupLog(0, options),
|
request: (sender, options) =>
|
||||||
|
sender.getGroupLog(
|
||||||
|
{
|
||||||
|
startVersion: 0,
|
||||||
|
includeFirstState: true,
|
||||||
|
includeLastState: false,
|
||||||
|
maxSupportedChangeEpoch: SUPPORTED_CHANGE_EPOCH,
|
||||||
|
},
|
||||||
|
options
|
||||||
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Attempt to start with the first group state, only later processing future updates
|
// Attempt to start with the first group state, only later processing future updates
|
||||||
|
@ -3276,6 +3285,7 @@ async function getGroupDelta({
|
||||||
});
|
});
|
||||||
|
|
||||||
const currentRevision = group.revision;
|
const currentRevision = group.revision;
|
||||||
|
const isFirstFetch = !isNumber(currentRevision);
|
||||||
let revisionToFetch = isNumber(currentRevision)
|
let revisionToFetch = isNumber(currentRevision)
|
||||||
? currentRevision + 1
|
? currentRevision + 1
|
||||||
: undefined;
|
: undefined;
|
||||||
|
@ -3284,7 +3294,15 @@ async function getGroupDelta({
|
||||||
const changes: Array<Proto.IGroupChanges> = [];
|
const changes: Array<Proto.IGroupChanges> = [];
|
||||||
do {
|
do {
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
response = await sender.getGroupLog(revisionToFetch, options);
|
response = await sender.getGroupLog(
|
||||||
|
{
|
||||||
|
startVersion: revisionToFetch,
|
||||||
|
includeFirstState: isFirstFetch,
|
||||||
|
includeLastState: false,
|
||||||
|
maxSupportedChangeEpoch: SUPPORTED_CHANGE_EPOCH,
|
||||||
|
},
|
||||||
|
options
|
||||||
|
);
|
||||||
changes.push(response.changes);
|
changes.push(response.changes);
|
||||||
if (response.end) {
|
if (response.end) {
|
||||||
revisionToFetch = response.end + 1;
|
revisionToFetch = response.end + 1;
|
||||||
|
|
|
@ -28,6 +28,7 @@ import type * as Attachment from '../types/Attachment';
|
||||||
import type { UUID, UUIDStringType } from '../types/UUID';
|
import type { UUID, UUIDStringType } from '../types/UUID';
|
||||||
import type {
|
import type {
|
||||||
ChallengeType,
|
ChallengeType,
|
||||||
|
GetGroupLogOptionsType,
|
||||||
GroupCredentialsType,
|
GroupCredentialsType,
|
||||||
GroupLogResponseType,
|
GroupLogResponseType,
|
||||||
MultiRecipient200ResponseType,
|
MultiRecipient200ResponseType,
|
||||||
|
@ -2134,10 +2135,10 @@ export default class MessageSender {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getGroupLog(
|
async getGroupLog(
|
||||||
startVersion: number | undefined,
|
options: GetGroupLogOptionsType,
|
||||||
options: Readonly<GroupCredentialsType>
|
credentials: GroupCredentialsType
|
||||||
): Promise<GroupLogResponseType> {
|
): Promise<GroupLogResponseType> {
|
||||||
return this.server.getGroupLog(startVersion, options);
|
return this.server.getGroupLog(options, credentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getGroupAvatar(key: string): Promise<Uint8Array> {
|
async getGroupAvatar(key: string): Promise<Uint8Array> {
|
||||||
|
|
|
@ -681,6 +681,12 @@ export type GroupCredentialsType = {
|
||||||
groupPublicParamsHex: string;
|
groupPublicParamsHex: string;
|
||||||
authCredentialPresentationHex: string;
|
authCredentialPresentationHex: string;
|
||||||
};
|
};
|
||||||
|
export type GetGroupLogOptionsType = Readonly<{
|
||||||
|
startVersion: number | undefined;
|
||||||
|
includeFirstState: boolean;
|
||||||
|
includeLastState: boolean;
|
||||||
|
maxSupportedChangeEpoch: number;
|
||||||
|
}>;
|
||||||
export type GroupLogResponseType = {
|
export type GroupLogResponseType = {
|
||||||
currentRevision?: number;
|
currentRevision?: number;
|
||||||
start?: number;
|
start?: number;
|
||||||
|
@ -804,8 +810,8 @@ export type WebAPIType = {
|
||||||
options: GroupCredentialsType
|
options: GroupCredentialsType
|
||||||
) => Promise<Proto.GroupExternalCredential>;
|
) => Promise<Proto.GroupExternalCredential>;
|
||||||
getGroupLog: (
|
getGroupLog: (
|
||||||
startVersion: number | undefined,
|
options: GetGroupLogOptionsType,
|
||||||
options: GroupCredentialsType
|
credentials: GroupCredentialsType
|
||||||
) => Promise<GroupLogResponseType>;
|
) => Promise<GroupLogResponseType>;
|
||||||
getIceServers: () => Promise<GetIceServersResultType>;
|
getIceServers: () => Promise<GetIceServersResultType>;
|
||||||
getKeysForIdentifier: (
|
getKeysForIdentifier: (
|
||||||
|
@ -1071,7 +1077,7 @@ export function initialize({
|
||||||
let password = initialPassword;
|
let password = initialPassword;
|
||||||
const PARSE_RANGE_HEADER = /\/(\d+)$/;
|
const PARSE_RANGE_HEADER = /\/(\d+)$/;
|
||||||
const PARSE_GROUP_LOG_RANGE_HEADER =
|
const PARSE_GROUP_LOG_RANGE_HEADER =
|
||||||
/$versions (\d{1,10})-(\d{1,10})\/(d{1,10})/;
|
/^versions\s+(\d{1,10})-(\d{1,10})\/(\d{1,10})/;
|
||||||
|
|
||||||
let activeRegistration: ExplodePromiseResultType<void> | undefined;
|
let activeRegistration: ExplodePromiseResultType<void> | undefined;
|
||||||
|
|
||||||
|
@ -2603,14 +2609,21 @@ export function initialize({
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getGroupLog(
|
async function getGroupLog(
|
||||||
startVersion: number | undefined,
|
options: GetGroupLogOptionsType,
|
||||||
options: GroupCredentialsType
|
credentials: GroupCredentialsType
|
||||||
): Promise<GroupLogResponseType> {
|
): Promise<GroupLogResponseType> {
|
||||||
const basicAuth = generateGroupAuth(
|
const basicAuth = generateGroupAuth(
|
||||||
options.groupPublicParamsHex,
|
credentials.groupPublicParamsHex,
|
||||||
options.authCredentialPresentationHex
|
credentials.authCredentialPresentationHex
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const {
|
||||||
|
startVersion,
|
||||||
|
includeFirstState,
|
||||||
|
includeLastState,
|
||||||
|
maxSupportedChangeEpoch,
|
||||||
|
} = options;
|
||||||
|
|
||||||
// If we don't know starting revision - fetch it from the server
|
// If we don't know starting revision - fetch it from the server
|
||||||
if (startVersion === undefined) {
|
if (startVersion === undefined) {
|
||||||
const { data: joinedData } = await _ajax({
|
const { data: joinedData } = await _ajax({
|
||||||
|
@ -2624,7 +2637,13 @@ export function initialize({
|
||||||
|
|
||||||
const { joinedAtVersion } = Proto.Member.decode(joinedData);
|
const { joinedAtVersion } = Proto.Member.decode(joinedData);
|
||||||
|
|
||||||
return getGroupLog(joinedAtVersion, options);
|
return getGroupLog(
|
||||||
|
{
|
||||||
|
...options,
|
||||||
|
startVersion: joinedAtVersion,
|
||||||
|
},
|
||||||
|
credentials
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const withDetails = await _ajax({
|
const withDetails = await _ajax({
|
||||||
|
@ -2634,7 +2653,11 @@ export function initialize({
|
||||||
host: storageUrl,
|
host: storageUrl,
|
||||||
httpType: 'GET',
|
httpType: 'GET',
|
||||||
responseType: 'byteswithdetails',
|
responseType: 'byteswithdetails',
|
||||||
urlParameters: `/${startVersion}`,
|
urlParameters:
|
||||||
|
`/${startVersion}?` +
|
||||||
|
`includeFirstState=${Boolean(includeFirstState)}&` +
|
||||||
|
`includeLastState=${Boolean(includeLastState)}&` +
|
||||||
|
`maxSupportedChangeEpoch=${Number(maxSupportedChangeEpoch)}`,
|
||||||
});
|
});
|
||||||
const { data, response } = withDetails;
|
const { data, response } = withDetails;
|
||||||
const changes = Proto.GroupChanges.decode(data);
|
const changes = Proto.GroupChanges.decode(data);
|
||||||
|
@ -2643,9 +2666,9 @@ export function initialize({
|
||||||
const range = response.headers.get('Content-Range');
|
const range = response.headers.get('Content-Range');
|
||||||
const match = PARSE_GROUP_LOG_RANGE_HEADER.exec(range || '');
|
const match = PARSE_GROUP_LOG_RANGE_HEADER.exec(range || '');
|
||||||
|
|
||||||
const start = match ? parseInt(match[0], 10) : undefined;
|
const start = match ? parseInt(match[1], 10) : undefined;
|
||||||
const end = match ? parseInt(match[1], 10) : undefined;
|
const end = match ? parseInt(match[2], 10) : undefined;
|
||||||
const currentRevision = match ? parseInt(match[2], 10) : undefined;
|
const currentRevision = match ? parseInt(match[3], 10) : undefined;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
match &&
|
match &&
|
||||||
|
|
Loading…
Add table
Reference in a new issue