From 20d99cc7021b5d13e293b2f0de349e03f76fd073 Mon Sep 17 00:00:00 2001 From: Elara Musayelyan Date: Mon, 12 Dec 2022 18:11:57 -0800 Subject: [PATCH] Add WebSocket types --- types/types.go | 5 +++-- types/websocket.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 types/websocket.go diff --git a/types/types.go b/types/types.go index 126e549..4920a1a 100644 --- a/types/types.go +++ b/types/types.go @@ -1,6 +1,7 @@ package types import ( + "encoding/json" "fmt" "net/http" ) @@ -27,6 +28,6 @@ func (le LemmyError) Error() string { } type LemmyWebSocketMsg struct { - Op UserOperation `json:"op"` - Data any `json:"data"` + Op UserOperation `json:"op"` + Data json.RawMessage `json:"data"` } diff --git a/types/websocket.go b/types/websocket.go new file mode 100644 index 0000000..8536f9b --- /dev/null +++ b/types/websocket.go @@ -0,0 +1,37 @@ +package types + +type UserJoin struct { + Auth string `json:"auth"` +} + +type UserJoinResponse struct { + Joined bool `json:"joined"` + LemmyResponse +} + +type CommunityJoin struct { + CommunityID int `json:"community_id"` +} + +type CommunityJoinResponse struct { + Joined bool `json:"joined"` + LemmyResponse +} + +type ModJoin struct { + CommunityID int `json:"community_id"` +} + +type ModJoinResponse struct { + Joined bool `json:"joined"` + LemmyResponse +} + +type PostJoin struct { + PostID int `json:"post_id"` +} + +type PostJoinResponse struct { + Joined bool `json:"joined"` + LemmyResponse +}