summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/stream/Connection.ts
diff options
context:
space:
mode:
authoranatawa12 <anatawa12@icloud.com>2024-08-09 16:04:41 +0900
committerGitHub <noreply@github.com>2024-08-09 16:04:41 +0900
commitf50941389d8724442ce2d7326afe9fbdadd3b58e (patch)
tree852abb54937b8c04a4a8436e07bba2f226616a17 /packages/backend/src/server/api/stream/Connection.ts
parentfix(backend): check visibility of following/followers of remote users / feat:... (diff)
downloadsharkey-f50941389d8724442ce2d7326afe9fbdadd3b58e.tar.gz
sharkey-f50941389d8724442ce2d7326afe9fbdadd3b58e.tar.bz2
sharkey-f50941389d8724442ce2d7326afe9fbdadd3b58e.zip
fix: readAllNotifications message not working (#14374)
* refactor: add and use isJsonObject * fix: readNotification message without body is not working * docs(changelog): WSの`readAllNotifications` メッセージが `body` を持たない場合に動作しない問題 * Update CHANGELOG.md Co-authored-by: Sayamame-beans <61457993+Sayamame-beans@users.noreply.github.com> --------- Co-authored-by: Sayamame-beans <61457993+Sayamame-beans@users.noreply.github.com>
Diffstat (limited to 'packages/backend/src/server/api/stream/Connection.ts')
-rw-r--r--packages/backend/src/server/api/stream/Connection.ts27
1 files changed, 16 insertions, 11 deletions
diff --git a/packages/backend/src/server/api/stream/Connection.ts b/packages/backend/src/server/api/stream/Connection.ts
index 96082827f8..7773150b74 100644
--- a/packages/backend/src/server/api/stream/Connection.ts
+++ b/packages/backend/src/server/api/stream/Connection.ts
@@ -14,7 +14,8 @@ import { CacheService } from '@/core/CacheService.js';
import { MiFollowing, MiUserProfile } from '@/models/_.js';
import type { StreamEventEmitter, GlobalEvents } from '@/core/GlobalEventService.js';
import { ChannelFollowingService } from '@/core/ChannelFollowingService.js';
-import type { JsonObject } from '@/misc/json-value.js';
+import { isJsonObject } from '@/misc/json-value.js';
+import type { JsonObject, JsonValue } from '@/misc/json-value.js';
import type { ChannelsService } from './ChannelsService.js';
import type { EventEmitter } from 'events';
import type Channel from './channel.js';
@@ -112,8 +113,6 @@ export default class Connection {
const { type, body } = obj;
- if (typeof body !== 'object' || body === null || Array.isArray(body)) return;
-
switch (type) {
case 'readNotification': this.onReadNotification(body); break;
case 'subNote': this.onSubscribeNote(body); break;
@@ -154,7 +153,8 @@ export default class Connection {
}
@bindThis
- private readNote(body: JsonObject) {
+ private readNote(body: JsonValue | undefined) {
+ if (!isJsonObject(body)) return;
const id = body.id;
const note = this.cachedNotes.find(n => n.id === id);
@@ -166,7 +166,7 @@ export default class Connection {
}
@bindThis
- private onReadNotification(payload: JsonObject) {
+ private onReadNotification(payload: JsonValue | undefined) {
this.notificationService.readAllNotification(this.user!.id);
}
@@ -174,7 +174,8 @@ export default class Connection {
* 投稿購読要求時
*/
@bindThis
- private onSubscribeNote(payload: JsonObject) {
+ private onSubscribeNote(payload: JsonValue | undefined) {
+ if (!isJsonObject(payload)) return;
if (!payload.id || typeof payload.id !== 'string') return;
const current = this.subscribingNotes[payload.id] ?? 0;
@@ -190,7 +191,8 @@ export default class Connection {
* 投稿購読解除要求時
*/
@bindThis
- private onUnsubscribeNote(payload: JsonObject) {
+ private onUnsubscribeNote(payload: JsonValue | undefined) {
+ if (!isJsonObject(payload)) return;
if (!payload.id || typeof payload.id !== 'string') return;
const current = this.subscribingNotes[payload.id];
@@ -216,12 +218,13 @@ export default class Connection {
* チャンネル接続要求時
*/
@bindThis
- private onChannelConnectRequested(payload: JsonObject) {
+ private onChannelConnectRequested(payload: JsonValue | undefined) {
+ if (!isJsonObject(payload)) return;
const { channel, id, params, pong } = payload;
if (typeof id !== 'string') return;
if (typeof channel !== 'string') return;
if (typeof pong !== 'boolean' && typeof pong !== 'undefined' && pong !== null) return;
- if (typeof params !== 'undefined' && (typeof params !== 'object' || params === null || Array.isArray(params))) return;
+ if (typeof params !== 'undefined' && !isJsonObject(params)) return;
this.connectChannel(id, params, channel, pong ?? undefined);
}
@@ -229,7 +232,8 @@ export default class Connection {
* チャンネル切断要求時
*/
@bindThis
- private onChannelDisconnectRequested(payload: JsonObject) {
+ private onChannelDisconnectRequested(payload: JsonValue | undefined) {
+ if (!isJsonObject(payload)) return;
const { id } = payload;
if (typeof id !== 'string') return;
this.disconnectChannel(id);
@@ -297,7 +301,8 @@ export default class Connection {
* @param data メッセージ
*/
@bindThis
- private onChannelMessageRequested(data: JsonObject) {
+ private onChannelMessageRequested(data: JsonValue | undefined) {
+ if (!isJsonObject(data)) return;
if (typeof data.id !== 'string') return;
if (typeof data.type !== 'string') return;
if (typeof data.body === 'undefined') return;