-
Notifications
You must be signed in to change notification settings - Fork 20
feat: add read receipts support #339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import type { RoomID, UserID } from '@rocket.chat/federation-room'; | ||
|
|
||
| import type { BaseEDU } from './base'; | ||
|
|
||
| /** | ||
| * Typing receipt EDU as defined in the Matrix specification | ||
| * | ||
| * @see https://spec.matrix.org/latest/server-server-api/#receipts | ||
| */ | ||
| export interface ReceiptEDU extends BaseEDU { | ||
| edu_type: 'm.receipt'; | ||
| content: Record< | ||
| RoomID, | ||
| { | ||
| 'm.read': Record< | ||
| UserID, | ||
| { | ||
| data: { | ||
| thread_id?: string; | ||
| ts: number; | ||
| }; | ||
| event_ids: string[]; | ||
| } | ||
| >; | ||
| } | ||
| >; | ||
| } | ||
|
|
||
| export const isReceiptEDU = (edu: BaseEDU): edu is ReceiptEDU => { | ||
| return edu.edu_type === 'm.receipt'; | ||
| }; | ||
|
|
||
| export const createReceiptEDU = (roomId: RoomID, userId: UserID, eventIds: string[]): ReceiptEDU => ({ | ||
| edu_type: 'm.receipt', | ||
| content: { | ||
| [roomId]: { | ||
| 'm.read': { | ||
| [userId]: { | ||
| data: { | ||
| ts: Date.now(), | ||
| }, | ||
| event_ids: eventIds, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import type { PresenceUpdate } from '@rocket.chat/federation-core'; | ||
| import type { PresenceUpdate, ReceiptEDU } from '@rocket.chat/federation-core'; | ||
| import { createPresenceEDU, createTypingEDU, createLogger } from '@rocket.chat/federation-core'; | ||
| import { RoomID } from '@rocket.chat/federation-room'; | ||
| import { singleton } from 'tsyringe'; | ||
|
|
@@ -67,4 +67,53 @@ export class EduService { | |
| throw error; | ||
| } | ||
| } | ||
|
|
||
| async sendReadReceipt({ | ||
| roomId, | ||
| userId, | ||
| eventIds, | ||
| threadId, | ||
| }: { | ||
| roomId: RoomID; | ||
| userId: string; | ||
| eventIds: string[]; | ||
| threadId?: string; | ||
| }): Promise<void> { | ||
| try { | ||
| const origin = this.configService.serverName; | ||
| const receiptEDU: ReceiptEDU = { | ||
| edu_type: 'm.receipt', | ||
| content: { | ||
| [roomId]: { | ||
| 'm.read': { | ||
| [userId]: { | ||
| data: { | ||
| ts: Date.now(), | ||
| thread_id: threadId, | ||
| }, | ||
| event_ids: eventIds, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
Comment on lines
+84
to
+99
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: In Matrix, the Server-server (
|
||
|
|
||
| this.logger.debug( | ||
| `Sending read receipt for user ${userId} in room ${roomId} for events ${eventIds.join(', ')} to all servers in room`, | ||
| ); | ||
|
|
||
| const servers = await this.stateService.getServersInRoom(roomId); | ||
| const uniqueServers = servers.filter((server) => server !== origin); | ||
|
|
||
| await this.federationService.sendEDUToServers([receiptEDU], uniqueServers); | ||
|
|
||
| this.logger.debug(`Sent read receipt to ${uniqueServers.length} unique servers for room ${roomId}`); | ||
| } catch (error) { | ||
| this.logger.error({ | ||
| msg: 'Failed to send read receipt', | ||
| err: error, | ||
| }); | ||
| throw error; | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.