summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/stream/channels/messaging-index.ts
blob: bebc07f4ad664eb581c15aac66b6e22beedbd0a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { Inject, Injectable } from '@nestjs/common';
import Channel from '../channel.js';

class MessagingIndexChannel extends Channel {
	public readonly chName = 'messagingIndex';
	public static shouldShare = true;
	public static requireCredential = true;

	public async init(params: any) {
		// Subscribe messaging index stream
		this.subscriber.on(`messagingIndexStream:${this.user!.id}`, data => {
			this.send(data);
		});
	}
}

@Injectable()
export class MessagingIndexChannelService {
	public readonly shouldShare = MessagingIndexChannel.shouldShare;
	public readonly requireCredential = MessagingIndexChannel.requireCredential;

	constructor(
	) {
	}

	public create(id: string, connection: Channel['connection']): MessagingIndexChannel {
		return new MessagingIndexChannel(
			id,
			connection,
		);
	}
}