Skip to content

Commit ca03b5c

Browse files
committed
fix notifications
1 parent 99659e7 commit ca03b5c

File tree

5 files changed

+32
-16
lines changed

5 files changed

+32
-16
lines changed

packages/services/src/Domain/Sync/SyncBackoffService.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { AbstractService } from '../Service/AbstractService'
66
import { InternalEventHandlerInterface } from '../Internal/InternalEventHandlerInterface'
77
import { InternalEventBusInterface } from '../Internal/InternalEventBusInterface'
88
import { InternalEventInterface } from '../Internal/InternalEventInterface'
9-
import { ApplicationEvent } from '../Event/ApplicationEvent'
9+
import { SyncEvent } from '../Event/SyncEvent'
1010

1111
export class SyncBackoffService
1212
extends AbstractService
@@ -63,12 +63,18 @@ export class SyncBackoffService
6363
}
6464

6565
async handleEvent(event: InternalEventInterface): Promise<void> {
66-
if (event.type === ApplicationEvent.CompletedIncrementalSync) {
67-
for (const payload of (event.payload as Record<string, unknown>)
68-
.uploadedPayloads as ServerSyncPushContextualPayload[]) {
69-
this.backoffPenalties.delete(payload.uuid)
70-
this.backoffStartTimestamps.delete(payload.uuid)
71-
}
66+
if (
67+
event.type !== SyncEvent.PaginatedSyncRequestCompleted ||
68+
event.payload === undefined ||
69+
(event.payload as Record<string, unknown>).uploadedPayloads === undefined
70+
) {
71+
return
72+
}
73+
74+
for (const payload of (event.payload as Record<string, unknown>)
75+
.uploadedPayloads as ServerSyncPushContextualPayload[]) {
76+
this.backoffPenalties.delete(payload.uuid)
77+
this.backoffStartTimestamps.delete(payload.uuid)
7278
}
7379
}
7480

packages/snjs/lib/Application/Application.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ import {
116116
LoggerInterface,
117117
canBlockDeinit,
118118
} from '@standardnotes/utils'
119-
import { UuidString, ApplicationEventPayload } from '../Types'
119+
import { UuidString } from '../Types'
120120
import { applicationEventForSyncEvent } from '@Lib/Application/Event'
121121
import { BackupServiceInterface, FilesClientInterface } from '@standardnotes/files'
122122
import { ComputePrivateUsername } from '@standardnotes/encryption'
@@ -273,12 +273,12 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
273273
}),
274274
)
275275

276-
const syncEventCallback = async (eventName: SyncEvent) => {
276+
const syncEventCallback = async (eventName: SyncEvent, data?: unknown) => {
277277
const appEvent = applicationEventForSyncEvent(eventName)
278278
if (appEvent) {
279279
await encryptionService.onSyncEvent(eventName)
280280

281-
await this.notifyEvent(appEvent)
281+
await this.notifyEvent(appEvent, data)
282282

283283
if (appEvent === ApplicationEvent.CompletedFullSync) {
284284
if (!this.handledFullSyncStage) {
@@ -529,7 +529,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
529529
return this.addEventObserver(filteredCallback, event)
530530
}
531531

532-
private async notifyEvent(event: ApplicationEvent, data?: ApplicationEventPayload) {
532+
private async notifyEvent(event: ApplicationEvent, data?: unknown) {
533533
if (event === ApplicationEvent.Started) {
534534
this.onStart()
535535
} else if (event === ApplicationEvent.Launched) {

packages/snjs/lib/Application/Dependencies/DependencyEvents.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function RegisterApplicationServicesEvents(container: Dependencies, event
4545
events.addEventHandler(container.get(TYPES.VaultInviteService), ApplicationEvent.Launched)
4646
events.addEventHandler(container.get(TYPES.VaultInviteService), SyncEvent.ReceivedSharedVaultInvites)
4747
events.addEventHandler(container.get(TYPES.VaultInviteService), WebSocketsServiceEvent.UserInvitedToSharedVault)
48-
events.addEventHandler(container.get(TYPES.SyncBackoffService), ApplicationEvent.CompletedIncrementalSync)
48+
events.addEventHandler(container.get(TYPES.SyncBackoffService), SyncEvent.PaginatedSyncRequestCompleted)
4949

5050
if (container.get(TYPES.FilesBackupService)) {
5151
events.addEventHandler(container.get(TYPES.FilesBackupService), ApplicationEvent.ApplicationStageChanged)

packages/snjs/lib/Services/Sync/SyncService.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,6 @@ export class SyncService
10471047
}
10481048

10491049
if (response.status === PAYLOAD_TOO_LARGE) {
1050-
void this.notifyEvent(SyncEvent.PayloadTooLarge)
10511050
this.opStatus?.setIsTooLarge()
10521051
}
10531052

@@ -1070,6 +1069,10 @@ export class SyncService
10701069
uuidsToBackOff.push(uuidOrError.getValue())
10711070
}
10721071

1072+
void this.notifyEvent(SyncEvent.PayloadTooLarge, {
1073+
uuids: uuidsToBackOff.map((uuid) => uuid.value),
1074+
})
1075+
10731076
this.syncBackoffService.backoffItems(uuidsToBackOff)
10741077
}
10751078

packages/web/src/javascripts/Components/ApplicationView/ApplicationView.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ const ApplicationView: FunctionComponent<Props> = ({ application, mainApplicatio
117117
onAppLaunch()
118118
}
119119

120-
const removeAppObserver = application.addEventObserver(async (eventName) => {
120+
const removeAppObserver = application.addEventObserver(async (eventName, data) => {
121121
switch (eventName) {
122122
case ApplicationEvent.Started:
123123
onAppStart()
@@ -153,12 +153,19 @@ const ApplicationView: FunctionComponent<Props> = ({ application, mainApplicatio
153153
message: 'Too many requests. Please try again later.',
154154
})
155155
break
156-
case ApplicationEvent.SyncPayloadTooLarge:
156+
case ApplicationEvent.SyncPayloadTooLarge: {
157+
if ('uuids' in (data as Record<string, unknown>) === false) {
158+
return
159+
}
160+
const notes = application.items.findItems((data as Record<string, unknown>).uuids as string[])
161+
const noteTitles = notes.map((note) => `"${note.title}"`).join(', ')
162+
157163
addToast({
158164
type: ToastType.Error,
159-
message: 'Unable to sync. The payload of the request is too large.',
165+
message: `Unable to sync. The payload of the request is too large for the following notes: ${noteTitles}`,
160166
})
161167
break
168+
}
162169
}
163170
})
164171

0 commit comments

Comments
 (0)