chore: rebase broadcast notifications
Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
@@ -6,5 +6,5 @@
|
||||
|
||||
**BREAKING** Type definition added to signal recipients
|
||||
|
||||
Update to use `{type: 'broadcast'}` instead `null` and `{type: 'user', entityRefs: ''}`
|
||||
Update to use `{type: 'broadcast'}` instead `null` and `{type: 'user', entityRef: ''}`
|
||||
instead string entity references
|
||||
|
||||
@@ -286,7 +286,7 @@ export async function createRouter(
|
||||
|
||||
if (signals) {
|
||||
await signals.publish<NotificationReadSignal>({
|
||||
recipients: { type: 'user', entityRefs: [user] },
|
||||
recipients: { type: 'user', entityRef: [user] },
|
||||
message: { action: 'notification_read', notification_ids: ids },
|
||||
channel: 'notifications',
|
||||
});
|
||||
@@ -296,7 +296,7 @@ export async function createRouter(
|
||||
|
||||
if (signals) {
|
||||
await signals.publish<NotificationReadSignal>({
|
||||
recipients: { type: 'user', entityRefs: [user] },
|
||||
recipients: { type: 'user', entityRef: [user] },
|
||||
message: { action: 'notification_unread', notification_ids: ids },
|
||||
channel: 'notifications',
|
||||
});
|
||||
@@ -348,7 +348,7 @@ export async function createRouter(
|
||||
|
||||
if (signals) {
|
||||
await signals.publish<NewNotificationSignal>({
|
||||
recipients: null,
|
||||
recipients: { type: 'broadcast' },
|
||||
message: {
|
||||
action: 'new_notification',
|
||||
notification_id: ret.id,
|
||||
@@ -400,7 +400,7 @@ export async function createRouter(
|
||||
|
||||
if (signals) {
|
||||
await signals.publish<NewNotificationSignal>({
|
||||
recipients: { type: 'user', entityRefs: [user] },
|
||||
recipients: { type: 'user', entityRef: [user] },
|
||||
message: {
|
||||
action: 'new_notification',
|
||||
notification_id: ret.id,
|
||||
|
||||
@@ -152,7 +152,7 @@ describe('SignalManager', () => {
|
||||
await onEvent({
|
||||
topic: 'signals',
|
||||
eventPayload: {
|
||||
recipients: { type: 'user', entityRefs: 'user:default/john.doe' },
|
||||
recipients: { type: 'user', entityRef: 'user:default/john.doe' },
|
||||
channel: 'test',
|
||||
message: { msg: 'test' },
|
||||
},
|
||||
|
||||
@@ -135,9 +135,9 @@ export class SignalManager {
|
||||
const jsonMessage = JSON.stringify({ channel, message });
|
||||
let users: string[] = [];
|
||||
if (recipients.type === 'user') {
|
||||
users = Array.isArray(recipients.entityRefs)
|
||||
? recipients.entityRefs
|
||||
: [recipients.entityRefs];
|
||||
users = Array.isArray(recipients.entityRef)
|
||||
? recipients.entityRef
|
||||
: [recipients.entityRef];
|
||||
}
|
||||
|
||||
// Actual websocket message sending
|
||||
|
||||
@@ -118,7 +118,7 @@ to work:
|
||||
eventBroker.publish({
|
||||
topic: 'signals',
|
||||
eventPayload: {
|
||||
recipients: { type: 'user', entityRefs: ['user:default/user1'] },
|
||||
recipients: { type: 'user', entityRef: 'user:default/user1' },
|
||||
message: {
|
||||
message: 'hello world',
|
||||
},
|
||||
|
||||
@@ -24,7 +24,7 @@ export type SignalPayload<TMessage extends JsonObject = JsonObject> = {
|
||||
recipients:
|
||||
| {
|
||||
type: 'user';
|
||||
entityRefs: string | string[];
|
||||
entityRef: string | string[];
|
||||
}
|
||||
| {
|
||||
type: 'broadcast';
|
||||
|
||||
@@ -26,7 +26,7 @@ export type SignalsServiceOptions = {
|
||||
/** @public */
|
||||
export type SignalPayload<TMessage extends JsonObject = JsonObject> = {
|
||||
recipients:
|
||||
| { type: 'user'; entityRefs: string | string[] }
|
||||
| { type: 'user'; entityRef: string | string[] }
|
||||
| { type: 'broadcast' };
|
||||
channel: string;
|
||||
message: TMessage;
|
||||
|
||||
Reference in New Issue
Block a user