mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-02-20 00:39:32 -06:00
Dont trigger notification for regular save "echoes"
This commit is contained in:
@@ -1239,6 +1239,7 @@ describe('DocumentDetailComponent', () => {
|
|||||||
it('should queue incoming update while network is active and flush after', () => {
|
it('should queue incoming update while network is active and flush after', () => {
|
||||||
initNormally()
|
initNormally()
|
||||||
const loadSpy = jest.spyOn(component as any, 'loadDocument')
|
const loadSpy = jest.spyOn(component as any, 'loadDocument')
|
||||||
|
const toastSpy = jest.spyOn(toastService, 'showInfo')
|
||||||
|
|
||||||
component.networkActive = true
|
component.networkActive = true
|
||||||
;(component as any).handleIncomingDocumentUpdated({
|
;(component as any).handleIncomingDocumentUpdated({
|
||||||
@@ -1252,6 +1253,28 @@ describe('DocumentDetailComponent', () => {
|
|||||||
;(component as any).flushPendingIncomingUpdate()
|
;(component as any).flushPendingIncomingUpdate()
|
||||||
|
|
||||||
expect(loadSpy).toHaveBeenCalledWith(component.documentId, true)
|
expect(loadSpy).toHaveBeenCalledWith(component.documentId, true)
|
||||||
|
expect(toastSpy).toHaveBeenCalledWith(
|
||||||
|
'Document reloaded with latest changes.'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should ignore queued incoming update matching local save modified', () => {
|
||||||
|
initNormally()
|
||||||
|
const loadSpy = jest.spyOn(component as any, 'loadDocument')
|
||||||
|
const toastSpy = jest.spyOn(toastService, 'showInfo')
|
||||||
|
|
||||||
|
component.networkActive = true
|
||||||
|
;(component as any).lastLocalSaveModified = '2026-02-17T00:00:00+00:00'
|
||||||
|
;(component as any).handleIncomingDocumentUpdated({
|
||||||
|
document_id: component.documentId,
|
||||||
|
modified: '2026-02-17T00:00:00+00:00',
|
||||||
|
})
|
||||||
|
|
||||||
|
component.networkActive = false
|
||||||
|
;(component as any).flushPendingIncomingUpdate()
|
||||||
|
|
||||||
|
expect(loadSpy).not.toHaveBeenCalled()
|
||||||
|
expect(toastSpy).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should change preview element by render type', () => {
|
it('should change preview element by render type', () => {
|
||||||
|
|||||||
@@ -271,6 +271,7 @@ export class DocumentDetailComponent
|
|||||||
docChangeNotifier: Subject<any> = new Subject()
|
docChangeNotifier: Subject<any> = new Subject()
|
||||||
private incomingUpdateModal: NgbModalRef
|
private incomingUpdateModal: NgbModalRef
|
||||||
private pendingIncomingUpdate: IncomingDocumentUpdate
|
private pendingIncomingUpdate: IncomingDocumentUpdate
|
||||||
|
private lastLocalSaveModified: string | null = null
|
||||||
|
|
||||||
requiresPassword: boolean = false
|
requiresPassword: boolean = false
|
||||||
password: string
|
password: string
|
||||||
@@ -496,9 +497,16 @@ export class DocumentDetailComponent
|
|||||||
this.handleIncomingDocumentUpdated(pendingUpdate)
|
this.handleIncomingDocumentUpdated(pendingUpdate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getModifiedRawValue(modified: string | Date): string | null {
|
||||||
|
if (!modified) return null
|
||||||
|
if (typeof modified === 'string') return modified
|
||||||
|
return modified.toISOString()
|
||||||
|
}
|
||||||
|
|
||||||
private loadDocument(documentId: number, forceRemote: boolean = false): void {
|
private loadDocument(documentId: number, forceRemote: boolean = false): void {
|
||||||
this.closeIncomingUpdateModal()
|
this.closeIncomingUpdateModal()
|
||||||
this.pendingIncomingUpdate = null
|
this.pendingIncomingUpdate = null
|
||||||
|
this.lastLocalSaveModified = null
|
||||||
this.previewUrl = this.documentsService.getPreviewUrl(documentId)
|
this.previewUrl = this.documentsService.getPreviewUrl(documentId)
|
||||||
this.updatePdfSource()
|
this.updatePdfSource()
|
||||||
this.http
|
this.http
|
||||||
@@ -603,6 +611,18 @@ export class DocumentDetailComponent
|
|||||||
this.pendingIncomingUpdate = data
|
this.pendingIncomingUpdate = data
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// If modified timestamp of the incoming update is the same as the last local save,
|
||||||
|
// we assume this update is from our own save and dont notify
|
||||||
|
const incomingModified = this.getModifiedRawValue(data.modified)
|
||||||
|
if (
|
||||||
|
incomingModified &&
|
||||||
|
this.lastLocalSaveModified &&
|
||||||
|
incomingModified === this.lastLocalSaveModified
|
||||||
|
) {
|
||||||
|
this.lastLocalSaveModified = null
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.lastLocalSaveModified = null
|
||||||
|
|
||||||
if (this.openDocumentService.isDirty(this.document)) {
|
if (this.openDocumentService.isDirty(this.document)) {
|
||||||
this.showIncomingUpdateModal(data.modified)
|
this.showIncomingUpdateModal(data.modified)
|
||||||
@@ -1069,6 +1089,9 @@ export class DocumentDetailComponent
|
|||||||
.subscribe({
|
.subscribe({
|
||||||
next: (docValues) => {
|
next: (docValues) => {
|
||||||
this.closeIncomingUpdateModal()
|
this.closeIncomingUpdateModal()
|
||||||
|
this.lastLocalSaveModified = this.getModifiedRawValue(
|
||||||
|
docValues.modified
|
||||||
|
)
|
||||||
// in case data changed while saving eg removing inbox_tags
|
// in case data changed while saving eg removing inbox_tags
|
||||||
this.documentForm.patchValue(docValues)
|
this.documentForm.patchValue(docValues)
|
||||||
const newValues = Object.assign({}, this.documentForm.value)
|
const newValues = Object.assign({}, this.documentForm.value)
|
||||||
@@ -1095,6 +1118,7 @@ export class DocumentDetailComponent
|
|||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
this.networkActive = false
|
this.networkActive = false
|
||||||
|
this.lastLocalSaveModified = null
|
||||||
const canEdit =
|
const canEdit =
|
||||||
this.permissionsService.currentUserHasObjectPermissions(
|
this.permissionsService.currentUserHasObjectPermissions(
|
||||||
PermissionAction.Change,
|
PermissionAction.Change,
|
||||||
@@ -1155,6 +1179,7 @@ export class DocumentDetailComponent
|
|||||||
this.error = null
|
this.error = null
|
||||||
this.networkActive = false
|
this.networkActive = false
|
||||||
this.pendingIncomingUpdate = null
|
this.pendingIncomingUpdate = null
|
||||||
|
this.lastLocalSaveModified = null
|
||||||
if (closeResult && updateResult && nextDocId) {
|
if (closeResult && updateResult && nextDocId) {
|
||||||
this.router.navigate(['documents', nextDocId])
|
this.router.navigate(['documents', nextDocId])
|
||||||
this.titleInput?.focus()
|
this.titleInput?.focus()
|
||||||
@@ -1162,6 +1187,7 @@ export class DocumentDetailComponent
|
|||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
this.networkActive = false
|
this.networkActive = false
|
||||||
|
this.lastLocalSaveModified = null
|
||||||
this.error = error.error
|
this.error = error.error
|
||||||
this.toastService.showError($localize`Error saving document`, error)
|
this.toastService.showError($localize`Error saving document`, error)
|
||||||
this.flushPendingIncomingUpdate()
|
this.flushPendingIncomingUpdate()
|
||||||
|
|||||||
Reference in New Issue
Block a user