summaryrefslogtreecommitdiff
path: root/packages/backend/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'packages/backend/src/core')
-rw-r--r--packages/backend/src/core/GlobalEventService.ts7
-rw-r--r--packages/backend/src/core/NoteCreateService.ts2
-rw-r--r--packages/backend/src/core/RoleService.ts23
3 files changed, 32 insertions, 0 deletions
diff --git a/packages/backend/src/core/GlobalEventService.ts b/packages/backend/src/core/GlobalEventService.ts
index 9f4de5f985..2c2687a90c 100644
--- a/packages/backend/src/core/GlobalEventService.ts
+++ b/packages/backend/src/core/GlobalEventService.ts
@@ -14,11 +14,13 @@ import type {
MainStreamTypes,
NoteStreamTypes,
UserListStreamTypes,
+ RoleTimelineStreamTypes,
} from '@/server/api/stream/types.js';
import type { Packed } from '@/misc/json-schema.js';
import { DI } from '@/di-symbols.js';
import type { Config } from '@/config.js';
import { bindThis } from '@/decorators.js';
+import { Role } from '@/models';
@Injectable()
export class GlobalEventService {
@@ -82,6 +84,11 @@ export class GlobalEventService {
}
@bindThis
+ public publishRoleTimelineStream<K extends keyof RoleTimelineStreamTypes>(roleId: Role['id'], type: K, value?: RoleTimelineStreamTypes[K]): void {
+ this.publish(`roleTimelineStream:${roleId}`, type, typeof value === 'undefined' ? null : value);
+ }
+
+ @bindThis
public publishNotesStream(note: Packed<'Note'>): void {
this.publish('notesStream', null, note);
}
diff --git a/packages/backend/src/core/NoteCreateService.ts b/packages/backend/src/core/NoteCreateService.ts
index 32e4fe7f8a..79629cb2a8 100644
--- a/packages/backend/src/core/NoteCreateService.ts
+++ b/packages/backend/src/core/NoteCreateService.ts
@@ -547,6 +547,8 @@ export class NoteCreateService implements OnApplicationShutdown {
this.globalEventService.publishNotesStream(noteObj);
+ this.roleService.addNoteToRoleTimeline(noteObj);
+
this.webhookService.getActiveWebhooks().then(webhooks => {
webhooks = webhooks.filter(x => x.userId === user.id && x.on.includes('note'));
for (const webhook of webhooks) {
diff --git a/packages/backend/src/core/RoleService.ts b/packages/backend/src/core/RoleService.ts
index 77645e3f06..2a4271aa98 100644
--- a/packages/backend/src/core/RoleService.ts
+++ b/packages/backend/src/core/RoleService.ts
@@ -13,6 +13,7 @@ import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { StreamMessages } from '@/server/api/stream/types.js';
import { IdService } from '@/core/IdService.js';
import { GlobalEventService } from '@/core/GlobalEventService.js';
+import type { Packed } from '@/misc/json-schema';
import type { OnApplicationShutdown } from '@nestjs/common';
export type RolePolicies = {
@@ -64,6 +65,9 @@ export class RoleService implements OnApplicationShutdown {
public static NotAssignedError = class extends Error {};
constructor(
+ @Inject(DI.redis)
+ private redisClient: Redis.Redis,
+
@Inject(DI.redisForSub)
private redisForSub: Redis.Redis,
@@ -399,6 +403,25 @@ export class RoleService implements OnApplicationShutdown {
}
@bindThis
+ public async addNoteToRoleTimeline(note: Packed<'Note'>): Promise<void> {
+ const roles = await this.getUserRoles(note.userId);
+
+ const redisPipeline = this.redisClient.pipeline();
+
+ for (const role of roles) {
+ redisPipeline.xadd(
+ `roleTimeline:${role.id}`,
+ 'MAXLEN', '~', '1000',
+ '*',
+ 'note', note.id);
+
+ this.globalEventService.publishRoleTimelineStream(role.id, 'note', note);
+ }
+
+ redisPipeline.exec();
+ }
+
+ @bindThis
public onApplicationShutdown(signal?: string | undefined) {
this.redisForSub.off('message', this.onMessage);
}