Open6
misskeyクライアント制作記
- misskey API docs https://misskey-hub.net/docs/api/
- github https://github.com/misskey-dev/misskey
Web Socketについて
接続
const host = [インスタンスのドメイン名]
const token = [配られたtoken]
const ws = new WebSocket(`wss://${host}/streaming?i=${token}`);
タイムラインを購読
type MisskeyStreamChannel = "globalTimeline" | "homeTimeline" | "hybridTimeline" | "localTimeline" | "main";
type Params = {
local?: boolean;
media?: boolean;
reply?: boolean;
renote?: boolean;
poll?: boolean;
myRenote?: boolean;
myReaction?: boolean;
following?: boolean;
}
ws.send(JSON.stringify({
type: "connect",
body: {
channel : "homeTimeline", // MisskeyStreamChannel
id: uuid(),
params: null // Params
}
})
タイムラインの購読だけでは取得したNoteにreactionが付いたことに気づけない。
API docsには書いてないが、s
でそれぞれのNoteの更新を購読する
TODO: これunsubscribeどうするんだろうね
ws.send(JSON.stringify({
type: "s",
body: {
id: [NoteId]
}
})
TODO: 公式Webもそうだが、放っておくと確実にWebSocketが切断されるので切断を検出して再接続する仕組みが必要
受け取り
connect
で購読しているTLのNoteがやってくるよ
type MisskeyStreamMessage = {
id: string;
type: "note";
body: MisskeyNote;
};
MisskeyNote: https://misskey-hub.net/docs/api/entity/note.html
reaction
Reactionする
reaction済みのnoteにはnote.myReaction
にリアクションが入る
reactionを取り消す
既にmyReactionがあるNoteにReactionする
一度既存のreactionをdeleteしてからcreateする必要がある
- delete reaction
- create reaction
- get reactions
APIへの接続はBrowserWindow
内でやるとセキュリティ上良くないので、https://github.com/arantes555/electron-fetch
を導入してみた
ipc.invoke
でElectron内のスレッドにAPI呼び出しを頼み、fetchコードでは何も考えず結果を返す
TODO: WebSocketへの接続どうするの
Misskey APIに含まれる型はmisskey-jsを参照するのが良さそう
お気に入りに入れてるchannelsを取得するAPIはエンドポイント一覧にないぽい (2023-10-25)
/api/channels/my-favorites
typeは以下
export type MisskeyChannel = {
bannerUrl: string;
color: string;
createdAt: string;
description: string;
hasUnreadNote: boolean;
id: string;
isArchived: boolean;
isFavorited: boolean;
isFollowing: boolean;
lastNotedAt: string;
name: string;
notesCount: number;
pinnedNoteIds: string[];
userId: string;
usersCount: number;
}