Skip to content

Commit

Permalink
SSE for sharing (#10807)
Browse files Browse the repository at this point in the history
Add SSE events for sharing 

---------

Co-authored-by: Jannik Stehle <[email protected]>
  • Loading branch information
AlexAndBear and JammingBen authored Apr 25, 2024
1 parent b246572 commit 4f2f0e7
Show file tree
Hide file tree
Showing 10 changed files with 974 additions and 564 deletions.
7 changes: 7 additions & 0 deletions changelog/unreleased/enhancement-add-sse-events-for-sharing
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: Add SSE event for moving

We've added Server-Sent Events (SSE) for sharing.
This notifies the user when they received or revoked access to a share or membership to a space.

https://github.com/owncloud/web/pull/10807
https://github.com/owncloud/web/issues/10647
11 changes: 10 additions & 1 deletion packages/web-client/src/sse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ export enum MESSAGE_TYPE {
ITEM_TRASHED = 'item-trashed',
ITEM_RESTORED = 'item-restored',
ITEM_MOVED = 'item-moved',
FOLDER_CREATED = 'folder-created'
FOLDER_CREATED = 'folder-created',
SPACE_MEMBER_ADDED = 'space-member-added',
SPACE_MEMBER_REMOVED = 'space-member-removed',
SPACE_SHARE_UPDATED = 'space-share-updated',
SHARE_CREATED = 'share-created',
SHARE_REMOVED = 'share-removed',
SHARE_UPDATED = 'share-updated',
LINK_CREATED = 'link-created',
LINK_REMOVED = 'link-removed',
LINK_UPDATED = 'link-updated'
}

export class RetriableError extends Error {
Expand Down
185 changes: 138 additions & 47 deletions packages/web-runtime/src/container/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import {
useResourcesStore,
ResourcesStore,
SpacesStore,
MessageStore
MessageStore,
SharesStore
} from '@ownclouders/web-pkg'
import { authService } from '../services/auth'
import {
Expand Down Expand Up @@ -62,7 +63,18 @@ import {
onSSEItemTrashedEvent,
onSSEFolderCreatedEvent,
onSSEFileTouchedEvent,
onSSEItemMovedEvent
onSSEItemMovedEvent,
onSSESpaceMemberAddedEvent,
onSSESpaceMemberRemovedEvent,
onSSESpaceShareUpdatedEvent,
onSSEShareCreatedEvent,
onSSEShareRemovedEvent,
onSSEShareUpdatedEvent,
onSSELinkCreatedEvent,
onSSELinkRemovedEvent,
sseEventWrapper,
SseEventWrapperOptions,
onSSELinkUpdatedEvent
} from './sse'

const getEmbedConfigFromQuery = (
Expand Down Expand Up @@ -633,6 +645,7 @@ export const registerSSEEventListeners = ({
resourcesStore,
spacesStore,
messageStore,
sharesStore,
clientService,
previewService,
configStore,
Expand All @@ -643,6 +656,7 @@ export const registerSSEEventListeners = ({
resourcesStore: ResourcesStore
spacesStore: SpacesStore
messageStore: MessageStore
sharesStore: SharesStore
clientService: ClientService
previewService: PreviewService
configStore: ConfigStore
Expand All @@ -660,101 +674,178 @@ export const registerSSEEventListeners = ({
}
)

const sseEventWrapperOptions = {
resourcesStore,
spacesStore,
messageStore,
userStore,
sharesStore,
clientService,
previewService,
language,
router,
resourceQueue
} satisfies Partial<SseEventWrapperOptions>

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.ITEM_RENAMED, (msg) =>
onSSEItemRenamedEvent({
sseEventWrapper({
topic: MESSAGE_TYPE.ITEM_RENAMED,
resourcesStore,
spacesStore,
msg,
clientService,
router
...sseEventWrapperOptions,
method: onSSEItemRenamedEvent
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.POSTPROCESSING_FINISHED, (msg) =>
onSSEProcessingFinishedEvent({
sseEventWrapper({
topic: MESSAGE_TYPE.POSTPROCESSING_FINISHED,
resourcesStore,
spacesStore,
msg,
clientService,
previewService,
resourceQueue
...sseEventWrapperOptions,
method: onSSEProcessingFinishedEvent
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.FILE_LOCKED, (msg) =>
onSSEFileLockingEvent({
sseEventWrapper({
topic: MESSAGE_TYPE.FILE_LOCKED,
resourcesStore,
spacesStore,
userStore,
msg,
clientService
...sseEventWrapperOptions,
method: onSSEFileLockingEvent
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.FILE_UNLOCKED, (msg) =>
onSSEFileLockingEvent({
sseEventWrapper({
topic: MESSAGE_TYPE.FILE_UNLOCKED,
resourcesStore,
spacesStore,
userStore,
msg,
clientService
...sseEventWrapperOptions,
method: onSSEFileLockingEvent
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.ITEM_TRASHED, (msg) =>
onSSEItemTrashedEvent({
sseEventWrapper({
topic: MESSAGE_TYPE.ITEM_TRASHED,
language,
resourcesStore,
clientService,
messageStore,
msg
msg,
...sseEventWrapperOptions,
method: onSSEItemTrashedEvent
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.ITEM_RESTORED, (msg) =>
onSSEItemRestoredEvent({
sseEventWrapper({
topic: MESSAGE_TYPE.ITEM_RESTORED,
resourcesStore,
spacesStore,
userStore,
msg,
clientService
...sseEventWrapperOptions,
method: onSSEItemRestoredEvent
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.ITEM_MOVED, (msg) =>
onSSEItemMovedEvent({
sseEventWrapper({
topic: MESSAGE_TYPE.ITEM_MOVED,
resourcesStore,
spacesStore,
userStore,
msg,
clientService
...sseEventWrapperOptions,
method: onSSEItemMovedEvent
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.FOLDER_CREATED, (msg) =>
onSSEFolderCreatedEvent({
sseEventWrapper({
topic: MESSAGE_TYPE.FOLDER_CREATED,
resourcesStore,
spacesStore,
msg,
clientService
...sseEventWrapperOptions,
method: onSSEFolderCreatedEvent
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.FILE_TOUCHED, (msg) =>
onSSEFileTouchedEvent({
sseEventWrapper({
topic: MESSAGE_TYPE.FILE_TOUCHED,
resourcesStore,
spacesStore,
msg,
clientService
...sseEventWrapperOptions,
method: onSSEFileTouchedEvent
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.SPACE_MEMBER_ADDED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.SPACE_MEMBER_ADDED,
msg,
...sseEventWrapperOptions,
method: onSSESpaceMemberAddedEvent
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.SPACE_MEMBER_REMOVED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.SPACE_MEMBER_REMOVED,
msg,
...sseEventWrapperOptions,
method: onSSESpaceMemberRemovedEvent
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.SPACE_SHARE_UPDATED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.SPACE_SHARE_UPDATED,
msg,
...sseEventWrapperOptions,
method: onSSESpaceShareUpdatedEvent
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.SHARE_CREATED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.SHARE_CREATED,
msg,
...sseEventWrapperOptions,
method: onSSEShareCreatedEvent
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.SHARE_REMOVED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.SHARE_REMOVED,
msg,
...sseEventWrapperOptions,
method: onSSEShareRemovedEvent
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.SHARE_UPDATED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.SHARE_UPDATED,
msg,
...sseEventWrapperOptions,
method: onSSEShareUpdatedEvent
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.LINK_CREATED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.LINK_CREATED,
msg,
...sseEventWrapperOptions,
method: onSSELinkCreatedEvent
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.LINK_REMOVED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.LINK_REMOVED,
msg,
...sseEventWrapperOptions,
method: onSSELinkRemovedEvent
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.LINK_UPDATED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.LINK_UPDATED,
msg,
...sseEventWrapperOptions,
method: onSSELinkUpdatedEvent
})
)
}
Expand Down
Loading

0 comments on commit 4f2f0e7

Please sign in to comment.