Fetch joinedAtVersion before change log fetch for new groups
This commit is contained in:
parent
2603d53891
commit
437ef2d3a7
3 changed files with 21 additions and 44 deletions
42
ts/groups.ts
42
ts/groups.ts
|
@ -2946,11 +2946,6 @@ async function getGroupUpdates({
|
||||||
group,
|
group,
|
||||||
serverPublicParamsBase64,
|
serverPublicParamsBase64,
|
||||||
newRevision,
|
newRevision,
|
||||||
|
|
||||||
// If we just linked and this is a group where we have been a member
|
|
||||||
// from the beggining - applying all changes since the start is the best
|
|
||||||
// case scenario.
|
|
||||||
fallbackRevision: 0,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -2973,36 +2968,6 @@ async function getGroupUpdates({
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch of logs starting from the revision 0 failed, so we probably were
|
|
||||||
// just invited to the group. Try fetching logs from the same revision as in
|
|
||||||
// this message.
|
|
||||||
if (isFirstFetch) {
|
|
||||||
try {
|
|
||||||
const result = await updateGroupViaLogs({
|
|
||||||
group,
|
|
||||||
serverPublicParamsBase64,
|
|
||||||
newRevision,
|
|
||||||
fallbackRevision: newRevision,
|
|
||||||
});
|
|
||||||
|
|
||||||
return result;
|
|
||||||
} catch (error) {
|
|
||||||
if (error.code === TEMPORAL_AUTH_REJECTED_CODE) {
|
|
||||||
// We will fail over to the updateGroupViaState call below
|
|
||||||
log.info(
|
|
||||||
`getGroupUpdates/${logId}: Temporal credential failure, now fetching full state`
|
|
||||||
);
|
|
||||||
} else if (error.code === GROUP_ACCESS_DENIED_CODE) {
|
|
||||||
// We will fail over to the updateGroupViaState call below
|
|
||||||
log.info(
|
|
||||||
`getGroupUpdates/${logId}: Log access denied, now fetching full state`
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window.GV2_ENABLE_STATE_PROCESSING) {
|
if (window.GV2_ENABLE_STATE_PROCESSING) {
|
||||||
|
@ -3120,11 +3085,9 @@ async function updateGroupViaSingleChange({
|
||||||
async function updateGroupViaLogs({
|
async function updateGroupViaLogs({
|
||||||
group,
|
group,
|
||||||
serverPublicParamsBase64,
|
serverPublicParamsBase64,
|
||||||
fallbackRevision,
|
|
||||||
newRevision,
|
newRevision,
|
||||||
}: {
|
}: {
|
||||||
group: ConversationAttributesType;
|
group: ConversationAttributesType;
|
||||||
fallbackRevision: number;
|
|
||||||
newRevision: number;
|
newRevision: number;
|
||||||
serverPublicParamsBase64: string;
|
serverPublicParamsBase64: string;
|
||||||
}): Promise<UpdatesResultType> {
|
}): Promise<UpdatesResultType> {
|
||||||
|
@ -3137,7 +3100,6 @@ async function updateGroupViaLogs({
|
||||||
const groupCredentials = getCredentialsForToday(data);
|
const groupCredentials = getCredentialsForToday(data);
|
||||||
const deltaOptions = {
|
const deltaOptions = {
|
||||||
group,
|
group,
|
||||||
fallbackRevision,
|
|
||||||
newRevision,
|
newRevision,
|
||||||
serverPublicParamsBase64,
|
serverPublicParamsBase64,
|
||||||
authCredentialBase64: groupCredentials.today.credential,
|
authCredentialBase64: groupCredentials.today.credential,
|
||||||
|
@ -3261,13 +3223,11 @@ function getGroupCredentials({
|
||||||
async function getGroupDelta({
|
async function getGroupDelta({
|
||||||
group,
|
group,
|
||||||
newRevision,
|
newRevision,
|
||||||
fallbackRevision,
|
|
||||||
serverPublicParamsBase64,
|
serverPublicParamsBase64,
|
||||||
authCredentialBase64,
|
authCredentialBase64,
|
||||||
}: {
|
}: {
|
||||||
group: ConversationAttributesType;
|
group: ConversationAttributesType;
|
||||||
newRevision: number;
|
newRevision: number;
|
||||||
fallbackRevision: number;
|
|
||||||
serverPublicParamsBase64: string;
|
serverPublicParamsBase64: string;
|
||||||
authCredentialBase64: string;
|
authCredentialBase64: string;
|
||||||
}): Promise<UpdatesResultType> {
|
}): Promise<UpdatesResultType> {
|
||||||
|
@ -3292,7 +3252,7 @@ async function getGroupDelta({
|
||||||
const currentRevision = group.revision;
|
const currentRevision = group.revision;
|
||||||
let revisionToFetch = isNumber(currentRevision)
|
let revisionToFetch = isNumber(currentRevision)
|
||||||
? currentRevision + 1
|
? currentRevision + 1
|
||||||
: fallbackRevision;
|
: undefined;
|
||||||
|
|
||||||
let response;
|
let response;
|
||||||
const changes: Array<Proto.IGroupChanges> = [];
|
const changes: Array<Proto.IGroupChanges> = [];
|
||||||
|
|
|
@ -2134,7 +2134,7 @@ export default class MessageSender {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getGroupLog(
|
async getGroupLog(
|
||||||
startVersion: number,
|
startVersion: number | undefined,
|
||||||
options: Readonly<GroupCredentialsType>
|
options: Readonly<GroupCredentialsType>
|
||||||
): Promise<GroupLogResponseType> {
|
): Promise<GroupLogResponseType> {
|
||||||
return this.server.getGroupLog(startVersion, options);
|
return this.server.getGroupLog(startVersion, options);
|
||||||
|
|
|
@ -538,6 +538,7 @@ const URL_CALLS = {
|
||||||
getIceServers: 'v1/accounts/turn',
|
getIceServers: 'v1/accounts/turn',
|
||||||
getStickerPackUpload: 'v1/sticker/pack/form',
|
getStickerPackUpload: 'v1/sticker/pack/form',
|
||||||
groupLog: 'v1/groups/logs',
|
groupLog: 'v1/groups/logs',
|
||||||
|
groupJoinedAtVersion: 'v1/groups/joined_at_version',
|
||||||
groups: 'v1/groups',
|
groups: 'v1/groups',
|
||||||
groupsViaLink: 'v1/groups/join',
|
groupsViaLink: 'v1/groups/join',
|
||||||
groupToken: 'v1/groups/token',
|
groupToken: 'v1/groups/token',
|
||||||
|
@ -803,7 +804,7 @@ export type WebAPIType = {
|
||||||
options: GroupCredentialsType
|
options: GroupCredentialsType
|
||||||
) => Promise<Proto.GroupExternalCredential>;
|
) => Promise<Proto.GroupExternalCredential>;
|
||||||
getGroupLog: (
|
getGroupLog: (
|
||||||
startVersion: number,
|
startVersion: number | undefined,
|
||||||
options: GroupCredentialsType
|
options: GroupCredentialsType
|
||||||
) => Promise<GroupLogResponseType>;
|
) => Promise<GroupLogResponseType>;
|
||||||
getIceServers: () => Promise<GetIceServersResultType>;
|
getIceServers: () => Promise<GetIceServersResultType>;
|
||||||
|
@ -2590,7 +2591,7 @@ export function initialize({
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getGroupLog(
|
async function getGroupLog(
|
||||||
startVersion: number,
|
startVersion: number | undefined,
|
||||||
options: GroupCredentialsType
|
options: GroupCredentialsType
|
||||||
): Promise<GroupLogResponseType> {
|
): Promise<GroupLogResponseType> {
|
||||||
const basicAuth = generateGroupAuth(
|
const basicAuth = generateGroupAuth(
|
||||||
|
@ -2598,6 +2599,22 @@ export function initialize({
|
||||||
options.authCredentialPresentationHex
|
options.authCredentialPresentationHex
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// If we don't know starting revision - fetch it from the server
|
||||||
|
if (startVersion === undefined) {
|
||||||
|
const { data: joinedData } = await _ajax({
|
||||||
|
basicAuth,
|
||||||
|
call: 'groupJoinedAtVersion',
|
||||||
|
contentType: 'application/x-protobuf',
|
||||||
|
host: storageUrl,
|
||||||
|
httpType: 'GET',
|
||||||
|
responseType: 'byteswithdetails',
|
||||||
|
});
|
||||||
|
|
||||||
|
const { joinedAtVersion } = Proto.Member.decode(joinedData);
|
||||||
|
|
||||||
|
return getGroupLog(joinedAtVersion, options);
|
||||||
|
}
|
||||||
|
|
||||||
const withDetails = await _ajax({
|
const withDetails = await _ajax({
|
||||||
basicAuth,
|
basicAuth,
|
||||||
call: 'groupLog',
|
call: 'groupLog',
|
||||||
|
|
Loading…
Add table
Reference in a new issue