2023-02-16 23:09:41 +09:00
|
|
|
import { Injectable } from '@nestjs/common';
|
2022-02-27 11:07:39 +09:00
|
|
|
import { isInstanceMuted, isUserFromMutedInstance } from '@/misc/is-instance-muted.js';
|
2022-09-18 03:27:08 +09:00
|
|
|
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
2022-12-04 15:03:09 +09:00
|
|
|
import { bindThis } from '@/decorators.js';
|
2022-09-18 03:27:08 +09:00
|
|
|
import Channel from '../channel.js';
|
2018-10-07 11:06:17 +09:00
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
class MainChannel extends Channel {
|
2018-10-11 23:01:57 +09:00
|
|
|
public readonly chName = 'main';
|
2018-10-11 23:07:20 +09:00
|
|
|
public static shouldShare = true;
|
2018-11-11 02:22:34 +09:00
|
|
|
public static requireCredential = true;
|
2018-10-11 23:01:57 +09:00
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
constructor(
|
|
|
|
private noteEntityService: NoteEntityService,
|
|
|
|
|
|
|
|
id: string,
|
|
|
|
connection: Channel['connection'],
|
|
|
|
) {
|
|
|
|
super(id, connection);
|
|
|
|
}
|
|
|
|
|
2022-12-04 15:03:09 +09:00
|
|
|
@bindThis
|
2018-10-07 11:06:17 +09:00
|
|
|
public async init(params: any) {
|
|
|
|
// Subscribe main stream channel
|
2019-04-13 01:43:22 +09:00
|
|
|
this.subscriber.on(`mainStream:${this.user!.id}`, async data => {
|
2021-10-21 01:04:10 +09:00
|
|
|
switch (data.type) {
|
2018-10-07 11:06:17 +09:00
|
|
|
case 'notification': {
|
2021-12-09 21:38:56 +09:00
|
|
|
// Ignore notifications from instances the user has muted
|
|
|
|
if (isUserFromMutedInstance(data.body, new Set<string>(this.userProfile?.mutedInstances ?? []))) return;
|
2023-04-05 10:21:10 +09:00
|
|
|
if (data.body.userId && this.userIdsWhoMeMuting.has(data.body.userId)) return;
|
2021-10-21 01:04:10 +09:00
|
|
|
|
|
|
|
if (data.body.note && data.body.note.isHidden) {
|
2022-09-18 03:27:08 +09:00
|
|
|
const note = await this.noteEntityService.pack(data.body.note.id, this.user, {
|
2021-12-09 23:58:30 +09:00
|
|
|
detail: true,
|
2019-09-24 03:58:00 +09:00
|
|
|
});
|
2021-03-21 17:38:09 +09:00
|
|
|
this.connection.cacheNote(note);
|
2021-10-21 01:04:10 +09:00
|
|
|
data.body.note = note;
|
2019-09-24 03:58:00 +09:00
|
|
|
}
|
2019-01-25 00:06:20 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'mention': {
|
2021-12-09 21:38:56 +09:00
|
|
|
if (isInstanceMuted(data.body, new Set<string>(this.userProfile?.mutedInstances ?? []))) return;
|
|
|
|
|
2023-04-05 10:21:10 +09:00
|
|
|
if (this.userIdsWhoMeMuting.has(data.body.userId)) return;
|
2021-10-21 01:04:10 +09:00
|
|
|
if (data.body.isHidden) {
|
2022-09-18 03:27:08 +09:00
|
|
|
const note = await this.noteEntityService.pack(data.body.id, this.user, {
|
2021-12-09 23:58:30 +09:00
|
|
|
detail: true,
|
2019-09-24 03:58:00 +09:00
|
|
|
});
|
2021-03-21 17:38:09 +09:00
|
|
|
this.connection.cacheNote(note);
|
2021-10-21 01:04:10 +09:00
|
|
|
data.body = note;
|
2019-09-24 03:58:00 +09:00
|
|
|
}
|
2018-10-07 11:06:17 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-10-08 01:56:36 +09:00
|
|
|
|
2021-10-21 01:04:10 +09:00
|
|
|
this.send(data.type, data.body);
|
2018-10-07 11:06:17 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2022-09-18 03:27:08 +09:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class MainChannelService {
|
|
|
|
public readonly shouldShare = MainChannel.shouldShare;
|
|
|
|
public readonly requireCredential = MainChannel.requireCredential;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private noteEntityService: NoteEntityService,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2022-12-04 15:03:09 +09:00
|
|
|
@bindThis
|
2022-09-18 03:27:08 +09:00
|
|
|
public create(id: string, connection: Channel['connection']): MainChannel {
|
|
|
|
return new MainChannel(
|
|
|
|
this.noteEntityService,
|
|
|
|
id,
|
|
|
|
connection,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|