summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/stream
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2023-01-12 21:02:26 +0900
committerGitHub <noreply@github.com>2023-01-12 21:02:26 +0900
commit2470afaa2e200fb2fc748e0f8eef5e2c215369b6 (patch)
treec270452679996127a9d15c4ba5f97b39bb9ba560 /packages/backend/src/server/api/stream
parentUpdate CHANGELOG.md (diff)
downloadsharkey-2470afaa2e200fb2fc748e0f8eef5e2c215369b6.tar.gz
sharkey-2470afaa2e200fb2fc748e0f8eef5e2c215369b6.tar.bz2
sharkey-2470afaa2e200fb2fc748e0f8eef5e2c215369b6.zip
Role (#9437)
* wip * Update CHANGELOG.md * wip * wip * wip * Update create.ts * wip * wip * Update CHANGELOG.md * wip * wip * wip * wip * wip * wip * wip * Update CHANGELOG.md * wip * wip * Update delete.ts * Update delete.ts * wip * wip * wip * Update account-info.vue * wip * wip * Update settings.vue * Update user-info.vue * wip * Update show-file.ts * Update show-user.ts * wip * wip * Update delete.ts * wip * wip * Update overview.moderators.vue * Create 1673500412259-Role.js * wip * wip * Update roles.vue * 色 * Update roles.vue * integrate silence * wip * wip
Diffstat (limited to 'packages/backend/src/server/api/stream')
-rw-r--r--packages/backend/src/server/api/stream/channels/global-timeline.ts10
-rw-r--r--packages/backend/src/server/api/stream/channels/hybrid-timeline.ts8
-rw-r--r--packages/backend/src/server/api/stream/channels/local-timeline.ts10
-rw-r--r--packages/backend/src/server/api/stream/types.ts34
4 files changed, 40 insertions, 22 deletions
diff --git a/packages/backend/src/server/api/stream/channels/global-timeline.ts b/packages/backend/src/server/api/stream/channels/global-timeline.ts
index 34f782e580..185c813869 100644
--- a/packages/backend/src/server/api/stream/channels/global-timeline.ts
+++ b/packages/backend/src/server/api/stream/channels/global-timeline.ts
@@ -7,6 +7,7 @@ import type { Packed } from '@/misc/schema.js';
import { MetaService } from '@/core/MetaService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { bindThis } from '@/decorators.js';
+import { RoleService } from '@/core/RoleService.js';
import Channel from '../channel.js';
class GlobalTimelineChannel extends Channel {
@@ -16,6 +17,7 @@ class GlobalTimelineChannel extends Channel {
constructor(
private metaService: MetaService,
+ private roleService: RoleService,
private noteEntityService: NoteEntityService,
id: string,
@@ -27,10 +29,8 @@ class GlobalTimelineChannel extends Channel {
@bindThis
public async init(params: any) {
- const meta = await this.metaService.fetch();
- if (meta.disableGlobalTimeline) {
- if (this.user == null || (!this.user.isAdmin && !this.user.isModerator)) return;
- }
+ const role = await this.roleService.getUserRoleOptions(this.user ? this.user.id : null);
+ if (!role.gtlAvailable) return;
// Subscribe events
this.subscriber.on('notesStream', this.onNote);
@@ -95,6 +95,7 @@ export class GlobalTimelineChannelService {
constructor(
private metaService: MetaService,
+ private roleService: RoleService,
private noteEntityService: NoteEntityService,
) {
}
@@ -103,6 +104,7 @@ export class GlobalTimelineChannelService {
public create(id: string, connection: Channel['connection']): GlobalTimelineChannel {
return new GlobalTimelineChannel(
this.metaService,
+ this.roleService,
this.noteEntityService,
id,
connection,
diff --git a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts
index 6c6afb12bf..a0f75f202c 100644
--- a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts
+++ b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts
@@ -8,6 +8,7 @@ import { DI } from '@/di-symbols.js';
import { MetaService } from '@/core/MetaService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { bindThis } from '@/decorators.js';
+import { RoleService } from '@/core/RoleService.js';
import Channel from '../channel.js';
class HybridTimelineChannel extends Channel {
@@ -17,6 +18,7 @@ class HybridTimelineChannel extends Channel {
constructor(
private metaService: MetaService,
+ private roleService: RoleService,
private noteEntityService: NoteEntityService,
id: string,
@@ -28,8 +30,8 @@ class HybridTimelineChannel extends Channel {
@bindThis
public async init(params: any): Promise<void> {
- const meta = await this.metaService.fetch();
- if (meta.disableLocalTimeline && !this.user!.isAdmin && !this.user!.isModerator) return;
+ const role = await this.roleService.getUserRoleOptions(this.user ? this.user.id : null);
+ if (!role.ltlAvailable) return;
// Subscribe events
this.subscriber.on('notesStream', this.onNote);
@@ -112,6 +114,7 @@ export class HybridTimelineChannelService {
constructor(
private metaService: MetaService,
+ private roleService: RoleService,
private noteEntityService: NoteEntityService,
) {
}
@@ -120,6 +123,7 @@ export class HybridTimelineChannelService {
public create(id: string, connection: Channel['connection']): HybridTimelineChannel {
return new HybridTimelineChannel(
this.metaService,
+ this.roleService,
this.noteEntityService,
id,
connection,
diff --git a/packages/backend/src/server/api/stream/channels/local-timeline.ts b/packages/backend/src/server/api/stream/channels/local-timeline.ts
index 54388787ef..7d76f42fe7 100644
--- a/packages/backend/src/server/api/stream/channels/local-timeline.ts
+++ b/packages/backend/src/server/api/stream/channels/local-timeline.ts
@@ -6,6 +6,7 @@ import type { Packed } from '@/misc/schema.js';
import { MetaService } from '@/core/MetaService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { bindThis } from '@/decorators.js';
+import { RoleService } from '@/core/RoleService.js';
import Channel from '../channel.js';
class LocalTimelineChannel extends Channel {
@@ -15,6 +16,7 @@ class LocalTimelineChannel extends Channel {
constructor(
private metaService: MetaService,
+ private roleService: RoleService,
private noteEntityService: NoteEntityService,
id: string,
@@ -26,10 +28,8 @@ class LocalTimelineChannel extends Channel {
@bindThis
public async init(params: any) {
- const meta = await this.metaService.fetch();
- if (meta.disableLocalTimeline) {
- if (this.user == null || (!this.user.isAdmin && !this.user.isModerator)) return;
- }
+ const role = await this.roleService.getUserRoleOptions(this.user ? this.user.id : null);
+ if (!role.ltlAvailable) return;
// Subscribe events
this.subscriber.on('notesStream', this.onNote);
@@ -92,6 +92,7 @@ export class LocalTimelineChannelService {
constructor(
private metaService: MetaService,
+ private roleService: RoleService,
private noteEntityService: NoteEntityService,
) {
}
@@ -100,6 +101,7 @@ export class LocalTimelineChannelService {
public create(id: string, connection: Channel['connection']): LocalTimelineChannel {
return new LocalTimelineChannel(
this.metaService,
+ this.roleService,
this.noteEntityService,
id,
connection,
diff --git a/packages/backend/src/server/api/stream/types.ts b/packages/backend/src/server/api/stream/types.ts
index ec05be56ee..3bc844f949 100644
--- a/packages/backend/src/server/api/stream/types.ts
+++ b/packages/backend/src/server/api/stream/types.ts
@@ -14,23 +14,33 @@ import type { Page } from '@/models/entities/Page.js';
import type { Packed } from '@/misc/schema.js';
import type { Webhook } from '@/models/entities/Webhook.js';
import type { Meta } from '@/models/entities/Meta.js';
+import { Role, RoleAssignment } from '@/models';
import type Emitter from 'strict-event-emitter-types';
import type { EventEmitter } from 'events';
+// redis通すとDateのインスタンスはstringに変換されるので
+type Serialized<T> = {
+ [K in keyof T]: T[K] extends Date ? string : T[K];
+};
+
//#region Stream type-body definitions
export interface InternalStreamTypes {
- userChangeSuspendedState: { id: User['id']; isSuspended: User['isSuspended']; };
- userChangeSilencedState: { id: User['id']; isSilenced: User['isSilenced']; };
- userChangeModeratorState: { id: User['id']; isModerator: User['isModerator']; };
- userTokenRegenerated: { id: User['id']; oldToken: User['token']; newToken: User['token']; };
- remoteUserUpdated: { id: User['id']; };
- webhookCreated: Webhook;
- webhookDeleted: Webhook;
- webhookUpdated: Webhook;
- antennaCreated: Antenna;
- antennaDeleted: Antenna;
- antennaUpdated: Antenna;
- metaUpdated: Meta,
+ userChangeSuspendedState: Serialized<{ id: User['id']; isSuspended: User['isSuspended']; }>;
+ userTokenRegenerated: Serialized<{ id: User['id']; oldToken: User['token']; newToken: User['token']; }>;
+ remoteUserUpdated: Serialized<{ id: User['id']; }>;
+ defaultRoleOverrideUpdated: Serialized<Role['options']>;
+ roleCreated: Serialized<Role>;
+ roleDeleted: Serialized<Role>;
+ roleUpdated: Serialized<Role>;
+ userRoleAssigned: Serialized<RoleAssignment>;
+ userRoleUnassigned: Serialized<RoleAssignment>;
+ webhookCreated: Serialized<Webhook>;
+ webhookDeleted: Serialized<Webhook>;
+ webhookUpdated: Serialized<Webhook>;
+ antennaCreated: Serialized<Antenna>;
+ antennaDeleted: Serialized<Antenna>;
+ antennaUpdated: Serialized<Antenna>;
+ metaUpdated: Serialized<Meta>;
}
export interface BroadcastTypes {