Skip to content

Commit

Permalink
feat: notificationsOutboxRead RPC caller and handler
Browse files Browse the repository at this point in the history
  • Loading branch information
amydevs committed Apr 15, 2024
1 parent 8d5a16a commit 20dd528
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/client/callers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import nodesListConnections from './nodesListConnections';
import nodesPing from './nodesPing';
import notificationsClear from './notificationsClear';
import notificationsOutboxClear from './notificationsOutboxClear';
import notificationsOutboxRead from './notificationsOutboxRead';
import notificationsRead from './notificationsRead';
import notificationsSend from './notificationsSend';
import vaultsClone from './vaultsClone';
Expand Down Expand Up @@ -123,6 +124,7 @@ const clientManifest = {
nodesPing,
notificationsClear,
notificationsOutboxClear,
notificationsOutboxRead,
notificationsRead,
notificationsSend,
vaultsClone,
Expand Down
12 changes: 12 additions & 0 deletions src/client/callers/notificationsOutboxRead.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { HandlerTypes } from '@matrixai/rpc';
import type NotificationsOutboxRead from '../handlers/NotificationsOutboxRead';
import { ServerCaller } from '@matrixai/rpc';

type CallerTypes = HandlerTypes<NotificationsOutboxRead>;

const notificationsOutboxRead = new ServerCaller<
CallerTypes['input'],
CallerTypes['output']
>();

export default notificationsOutboxRead;
43 changes: 43 additions & 0 deletions src/client/handlers/NotificationsOutboxRead.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type { DB } from '@matrixai/db';
import type {
ClientRPCRequestParams,
ClientRPCResponseResult,
NotificationMessage,
NotificationOutboxReadMessage,
} from '../types';
import type NotificationsManager from '../../notifications/NotificationsManager';
import { ServerHandler } from '@matrixai/rpc';

class NotificationsOutboxRead extends ServerHandler<
{
db: DB;
notificationsManager: NotificationsManager;
},
ClientRPCRequestParams<NotificationOutboxReadMessage>,
ClientRPCResponseResult<NotificationMessage>
> {
public async *handle(
input: ClientRPCRequestParams<NotificationOutboxReadMessage>,
_cancel,
_meta,
ctx,
): AsyncGenerator<ClientRPCResponseResult<NotificationMessage>> {
if (ctx.signal.aborted) throw ctx.signal.reason;
const { db, notificationsManager } = this.container;
const notifications = await db.withTransactionF((tran) =>
notificationsManager.readOutboxNotifications({
number: input.number,
order: input.order,
tran,
}),
);
for (const notification of notifications) {
if (ctx.signal.aborted) throw ctx.signal.reason;
yield {
notification: notification,
};
}
}
}

export default NotificationsOutboxRead;
2 changes: 2 additions & 0 deletions src/client/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import NodesListConnections from './NodesListConnections';
import NodesPing from './NodesPing';
import NotificationsClear from './NotificationsClear';
import NotificationsOutboxClear from './NotificationsOutboxClear';
import NotificationsOutboxRead from './NotificationsOutboxRead';
import NotificationsRead from './NotificationsRead';
import NotificationsSend from './NotificationsSend';
import VaultsClone from './VaultsClone';
Expand Down Expand Up @@ -163,6 +164,7 @@ const serverManifest = (container: {
nodesPing: new NodesPing(container),
notificationsClear: new NotificationsClear(container),
notificationsOutboxClear: new NotificationsOutboxClear(container),
notificationsOutboxRead: new NotificationsOutboxRead(container),
notificationsRead: new NotificationsRead(container),
notificationsSend: new NotificationsSend(container),
vaultsClone: new VaultsClone(container),
Expand Down
6 changes: 6 additions & 0 deletions src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ type NotificationReadMessage = {
order?: 'newest' | 'oldest';
};

type NotificationOutboxReadMessage = {
number?: number | 'all';
order?: 'newest' | 'oldest';
};

type NotificationMessage = {
notification: Notification;
};
Expand Down Expand Up @@ -374,6 +379,7 @@ export type {
SuccessMessage,
NotificationMessage,
NotificationReadMessage,
NotificationOutboxReadMessage,
NotificationSendMessage,
VaultNameMessage,
VaultIdMessage,
Expand Down

0 comments on commit 20dd528

Please sign in to comment.