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