From 6ab5bc2d7f37e462d6800112f5c1961d952a7faa Mon Sep 17 00:00:00 2001 From: hitalin Date: Sat, 9 May 2026 18:33:07 +0900 Subject: [PATCH] =?UTF-8?q?fix(chat):=20create-to-{user,room}=20=E3=81=AE?= =?UTF-8?q?=20text/fileId=20=E3=82=92=20Option=20=E3=81=A7=E5=8F=97?= =?UTF-8?q?=E3=81=91=E3=80=81Misskey=20schema=20=E3=81=AB=E5=90=88?= =?UTF-8?q?=E3=82=8F=E3=81=9B=E3=81=A6=20toUserId=20/=20toRoomId=20?= =?UTF-8?q?=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Misskey 新 Chat API #15686 のスキーマ: - パラメータ名は `toUserId` / `toRoomId` (`userId` / `roomId` ではない) - `text` と `fileId` は両方 nullable で、サーバ側で「どちらか一方は必須」を バリデーション (テキストなし & ファイルなしは contentRequired エラー) 旧シグネチャは `text: &str` 必須 + パラメータ名間違い (`userId` / `roomId`) で、 実呼び出されると失敗するか想定通りに動かなかった (NoteDeck 側からは呼ばれて おらず実害なし)。 notedeck の `messaging/messages/create` 404 エラー (Misskey v2025 で legacy 削除済み) を修正するため、本関数経由で新 API に切り替えるための前提整備。 --- src/api.rs | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/api.rs b/src/api.rs index 5717a44..aaee9c4 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1953,39 +1953,52 @@ impl MisskeyClient { } } + /// Misskey 新 Chat API (#15686) `chat/messages/create-to-user`。 + /// + /// `text` と `file_id` の両方を `Option<&str>` で受け取り、None の場合は + /// JSON body から省く。Misskey 側のスキーマも nullable で、サーバ側で + /// 「どちらか一方は必須」のバリデーションが走る。 pub async fn create_chat_message_to_user( &self, host: &str, token: &str, user_id: &str, - text: &str, + text: Option<&str>, + file_id: Option<&str>, ) -> Result { + let mut body = json!({ "toUserId": user_id }); + if let Some(t) = text { + body["text"] = json!(t); + } + if let Some(fid) = file_id { + body["fileId"] = json!(fid); + } let data = self - .request( - host, - token, - "chat/messages/create-to-user", - json!({ "userId": user_id, "text": text }), - ) + .request(host, token, "chat/messages/create-to-user", body) .await?; let message: ChatMessage = serde_json::from_value(data)?; Ok(message) } + /// Misskey 新 Chat API (#15686) `chat/messages/create-to-room`。 + /// `create_chat_message_to_user` と同じ optional ルール。 pub async fn create_chat_message_to_room( &self, host: &str, token: &str, room_id: &str, - text: &str, + text: Option<&str>, + file_id: Option<&str>, ) -> Result { + let mut body = json!({ "toRoomId": room_id }); + if let Some(t) = text { + body["text"] = json!(t); + } + if let Some(fid) = file_id { + body["fileId"] = json!(fid); + } let data = self - .request( - host, - token, - "chat/messages/create-to-room", - json!({ "roomId": room_id, "text": text }), - ) + .request(host, token, "chat/messages/create-to-room", body) .await?; let message: ChatMessage = serde_json::from_value(data)?; Ok(message)