summaryrefslogtreecommitdiff
path: root/src/server/api/stream/index.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2021-02-21 13:38:29 +0900
committersyuilo <syuilotan@yahoo.co.jp>2021-02-21 13:38:29 +0900
commit3d68a0988bb40567e71a23cbe809d9eff4e1a2c0 (patch)
treedbecada3558bfaeef7ae72a44c0e643f678f252a /src/server/api/stream/index.ts
parentMerge branch 'develop' (diff)
parent12.71.0 (diff)
downloadmisskey-3d68a0988bb40567e71a23cbe809d9eff4e1a2c0.tar.gz
misskey-3d68a0988bb40567e71a23cbe809d9eff4e1a2c0.tar.bz2
misskey-3d68a0988bb40567e71a23cbe809d9eff4e1a2c0.zip
Merge branch 'develop'
Diffstat (limited to 'src/server/api/stream/index.ts')
-rw-r--r--src/server/api/stream/index.ts34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/server/api/stream/index.ts b/src/server/api/stream/index.ts
index 5b975d07db..c56a0a157b 100644
--- a/src/server/api/stream/index.ts
+++ b/src/server/api/stream/index.ts
@@ -12,6 +12,8 @@ import { Users, Followings, Mutings, UserProfiles, ChannelFollowings } from '../
import { ApiError } from '../error';
import { AccessToken } from '../../../models/entities/access-token';
import { UserProfile } from '../../../models/entities/user-profile';
+import { publishChannelStream, publishGroupMessagingStream, publishMessagingStream } from '../../../services/stream';
+import { UserGroup } from '../../../models/entities/user-group';
/**
* Main stream connection
@@ -27,10 +29,10 @@ export default class Connection {
public subscriber: EventEmitter;
private channels: Channel[] = [];
private subscribingNotes: any = {};
- private followingClock: NodeJS.Timer;
- private mutingClock: NodeJS.Timer;
- private followingChannelsClock: NodeJS.Timer;
- private userProfileClock: NodeJS.Timer;
+ private followingClock: ReturnType<typeof setInterval>;
+ private mutingClock: ReturnType<typeof setInterval>;
+ private followingChannelsClock: ReturnType<typeof setInterval>;
+ private userProfileClock: ReturnType<typeof setInterval>;
constructor(
wsConnection: websocket.connection,
@@ -93,6 +95,12 @@ export default class Connection {
case 'disconnect': this.onChannelDisconnectRequested(body); break;
case 'channel': this.onChannelMessageRequested(body); break;
case 'ch': this.onChannelMessageRequested(body); break; // alias
+
+ // 個々のチャンネルではなくルートレベルでこれらのメッセージを受け取る理由は、
+ // クライアントの事情を考慮したとき、入力フォームはノートチャンネルやメッセージのメインコンポーネントとは別
+ // なこともあるため、それらのコンポーネントがそれぞれ各チャンネルに接続するようにするのは面倒なため。
+ case 'typingOnChannel': this.typingOnChannel(body.channel); break;
+ case 'typingOnMessaging': this.typingOnMessaging(body); break;
}
}
@@ -259,6 +267,24 @@ export default class Connection {
}
@autobind
+ private typingOnChannel(channel: ChannelModel['id']) {
+ if (this.user) {
+ publishChannelStream(channel, 'typing', this.user.id);
+ }
+ }
+
+ @autobind
+ private typingOnMessaging(param: { partner?: User['id']; group?: UserGroup['id']; }) {
+ if (this.user) {
+ if (param.partner) {
+ publishMessagingStream(param.partner, this.user.id, 'typing', this.user.id);
+ } else if (param.group) {
+ publishGroupMessagingStream(param.group, 'typing', this.user.id);
+ }
+ }
+ }
+
+ @autobind
private async updateFollowing() {
const followings = await Followings.find({
where: {