add main stream
This commit is contained in:
parent
08576c49de
commit
06c0373be9
|
@ -11,35 +11,34 @@ export default class extends Channel {
|
||||||
public async init(params: any) {
|
public async init(params: any) {
|
||||||
// Subscribe main stream channel
|
// Subscribe main stream channel
|
||||||
this.subscriber.on(`mainStream:${this.user!.id}`, async data => {
|
this.subscriber.on(`mainStream:${this.user!.id}`, async data => {
|
||||||
const { type } = data;
|
switch (data.type) {
|
||||||
let { body } = data;
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case 'notification': {
|
case 'notification': {
|
||||||
if (this.muting.has(body.userId)) return;
|
if (data.body.userId && this.muting.has(data.body.userId)) return;
|
||||||
if (body.note && body.note.isHidden) {
|
|
||||||
const note = await Notes.pack(body.note.id, this.user, {
|
// ????
|
||||||
|
if (data.body.note && data.body.note.isHidden) {
|
||||||
|
const note = await Notes.pack(data.body.note.id, this.user, {
|
||||||
detail: true
|
detail: true
|
||||||
});
|
});
|
||||||
this.connection.cacheNote(note);
|
this.connection.cacheNote(note);
|
||||||
body.note = note;
|
data.body.note = note;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'mention': {
|
case 'mention': {
|
||||||
if (this.muting.has(body.userId)) return;
|
if (this.muting.has(data.body.userId)) return;
|
||||||
if (body.isHidden) {
|
if (data.body.isHidden) {
|
||||||
const note = await Notes.pack(body.id, this.user, {
|
const note = await Notes.pack(data.body.id, this.user, {
|
||||||
detail: true
|
detail: true
|
||||||
});
|
});
|
||||||
this.connection.cacheNote(note);
|
this.connection.cacheNote(note);
|
||||||
body = note;
|
data.body = note;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.send(type, body);
|
this.send(data.type, data.body);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ import { UserProfile } from '@/models/entities/user-profile';
|
||||||
import { publishChannelStream, publishGroupMessagingStream, publishMessagingStream } from '@/services/stream';
|
import { publishChannelStream, publishGroupMessagingStream, publishMessagingStream } from '@/services/stream';
|
||||||
import { UserGroup } from '@/models/entities/user-group';
|
import { UserGroup } from '@/models/entities/user-group';
|
||||||
import { PackedNote } from '@/models/repositories/note';
|
import { PackedNote } from '@/models/repositories/note';
|
||||||
import { StreamEventEmitter, UserEvent } from './types';
|
import { StreamEventEmitter, UserEvents } from './types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main stream connection
|
* Main stream connection
|
||||||
|
@ -65,7 +65,7 @@ export default class Connection {
|
||||||
}
|
}
|
||||||
|
|
||||||
@autobind
|
@autobind
|
||||||
private onUserEvent(ev: UserEvent) { // { type, body }と展開すると型も展開されてしまう
|
private onUserEvent(ev: UserEvents) { // { type, body }と展開すると型も展開されてしまう
|
||||||
switch (ev.type) {
|
switch (ev.type) {
|
||||||
case 'follow':
|
case 'follow':
|
||||||
this.following.add(ev.body.id);
|
this.following.add(ev.body.id);
|
||||||
|
|
|
@ -5,6 +5,8 @@ import StreamTypes from 'misskey-js/built/streaming.types';
|
||||||
import { Channel } from '@/models/entities/channel';
|
import { Channel } from '@/models/entities/channel';
|
||||||
import { UserProfile } from '@/models/entities/user-profile';
|
import { UserProfile } from '@/models/entities/user-profile';
|
||||||
import { PackedUser } from '@/models/repositories/user';
|
import { PackedUser } from '@/models/repositories/user';
|
||||||
|
import { PackedNotification } from '@/models/repositories/notification';
|
||||||
|
import { PackedNote } from '@/models/repositories/note';
|
||||||
|
|
||||||
type Payload<T extends (payload: any) => void> = T extends (payload: infer P) => void ? P : never;
|
type Payload<T extends (payload: any) => void> = T extends (payload: infer P) => void ? P : never;
|
||||||
|
|
||||||
|
@ -14,11 +16,12 @@ type EventUnionFromDictionary<
|
||||||
U = { [K in keyof T]: { type: K; body: T[K]} }
|
U = { [K in keyof T]: { type: K; body: T[K]} }
|
||||||
> = U[keyof U];
|
> = U[keyof U];
|
||||||
|
|
||||||
export type BroadcastStream<T extends keyof StreamTypes.BroadcasrEvents> = {
|
type EventUnionFromMkJSTypes<
|
||||||
name: 'broadcast';
|
T extends { [key: string]: ((payload: any) => void) | (() => void) },
|
||||||
type: T;
|
U = { [K in keyof T]: { type: K; body: Payload<T[K]>} }
|
||||||
body: Payload<StreamTypes.BroadcasrEvents[T]>;
|
> = U[keyof U]
|
||||||
};
|
|
||||||
|
export type BroadcastStream = EventUnionFromMkJSTypes<StreamTypes.BroadcasrEvents>;
|
||||||
|
|
||||||
export interface UserEventTypes {
|
export interface UserEventTypes {
|
||||||
terminate: {};
|
terminate: {};
|
||||||
|
@ -31,19 +34,45 @@ export interface UserEventTypes {
|
||||||
unfollow: PackedUser;
|
unfollow: PackedUser;
|
||||||
userAdded: PackedUser;
|
userAdded: PackedUser;
|
||||||
};
|
};
|
||||||
|
|
||||||
// UserList userRemoved: PackedUser;
|
|
||||||
|
|
||||||
export type UserEventName = `user:${User['id']}`;
|
export type UserEventName = `user:${User['id']}`;
|
||||||
export type UserEvent = EventUnionFromDictionary<UserEventTypes>;
|
export type UserEvents = EventUnionFromDictionary<UserEventTypes>;
|
||||||
|
|
||||||
|
export interface mainStreamTypes {
|
||||||
|
notification: PackedNotification;
|
||||||
|
mention: PackedNote;
|
||||||
|
reply: PackedNote;
|
||||||
|
renote: PackedNote;
|
||||||
|
follow: PackedUser;
|
||||||
|
followed: PackedUser;
|
||||||
|
unfollow: PackedUser;
|
||||||
|
meUpdated: PackedUser;
|
||||||
|
pageEvent: Payload<StreamTypes.Channels['main']['events']['pageEvent']>;
|
||||||
|
urlUploadFinished: Payload<StreamTypes.Channels['main']['events']['urlUploadFinished']>;
|
||||||
|
readAllNotifications: never;
|
||||||
|
unreadNotification: never;
|
||||||
|
unreadMention: never;
|
||||||
|
readAllUnreadMentions: never;
|
||||||
|
unreadSpecifiedNote: never;
|
||||||
|
readAllUnreadSpecifiedNotes: never;
|
||||||
|
readAllMessagingMessages: never;
|
||||||
|
unreadMessagingMessage: never;
|
||||||
|
readAllAntennas: never;
|
||||||
|
unreadAntenna: never;
|
||||||
|
readAllAnnouncements: never;
|
||||||
|
readAllChannels: never;
|
||||||
|
unreadChannel: never;
|
||||||
|
myTokenRegenerated: never;
|
||||||
|
};
|
||||||
|
export type mainStreamName = `mainStream:${User['id']}`;
|
||||||
|
export type mainStreams = EventUnionFromDictionary<mainStreamTypes>;
|
||||||
|
|
||||||
interface StreamEvents {
|
interface StreamEvents {
|
||||||
'broadcast': <T extends keyof StreamTypes.BroadcasrEvents>(e: BroadcastStream<T>) => void;
|
'broadcast': (e: BroadcastStream) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AuthenticatedStreamEvents {
|
interface AuthenticatedStreamEvents {
|
||||||
[key: UserEventName]: (e: UserEvent) => void;
|
[key: UserEventName]: (e: UserEvents) => void;
|
||||||
[key: `mainStream:${User['id']}`]: (e: { type: string; body: any }) => void;
|
[key: mainStreamName]: (e: mainStreams) => void;
|
||||||
[key: `driveStream:${User['id']}`]: (e: { type: string; body: any }) => void;
|
[key: `driveStream:${User['id']}`]: (e: { type: string; body: any }) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue