From 1d50da4b1c43273ab2dc8c47829e03f5f6981f92 Mon Sep 17 00:00:00 2001 From: Gary Kim Date: Tue, 1 Jun 2021 17:17:07 -0400 Subject: Add support for message deletion (nctalk) (#1492) * nctalk: add message deletion support Signed-off-by: Gary Kim * nctalk: seperate out deletion and sending logic Signed-off-by: Gary Kim * nctalk: update library to v0.2.0 Signed-off-by: Gary Kim * Rename functions to be clearer Signed-off-by: Gary Kim * Update to go-nc-talk v0.2.1 Signed-off-by: Gary Kim * Update to go-nc-talk v0.2.2 Signed-off-by: Gary Kim * Make deletions easier to debug Signed-off-by: Gary Kim --- vendor/gomod.garykim.dev/nc-talk/user/user.go | 117 ++++++++++++++++++-------- 1 file changed, 83 insertions(+), 34 deletions(-) (limited to 'vendor/gomod.garykim.dev/nc-talk/user/user.go') diff --git a/vendor/gomod.garykim.dev/nc-talk/user/user.go b/vendor/gomod.garykim.dev/nc-talk/user/user.go index 2b42dacf..e557cffa 100644 --- a/vendor/gomod.garykim.dev/nc-talk/user/user.go +++ b/vendor/gomod.garykim.dev/nc-talk/user/user.go @@ -28,12 +28,16 @@ import ( const ( ocsCapabilitiesEndpoint = "/ocs/v2.php/cloud/capabilities" - ocsRoomsEndpoint = "/ocs/v2.php/apps/spreed/api/v2/room" + ocsRoomsv2Endpoint = "/ocs/v2.php/apps/spreed/api/v2/room" + ocsRoomsv4Endpoint = "/ocs/v2.php/apps/spreed/api/v4/room" ) var ( - // ErrUserIsNil is returned when a funciton is called with an nil user. + // ErrUserIsNil is returned when a function is called with an nil user. ErrUserIsNil = errors.New("user is nil") + + // ErrCannotDownloadFile is returned when a function cannot download the requested file + ErrCannotDownloadFile = errors.New("cannot download file") ) // TalkUser represents a user of Nextcloud Talk @@ -53,36 +57,52 @@ type TalkUserConfig struct { // Capabilities describes the capabilities that the Nextcloud Talk instance is capable of. Visit https://nextcloud-talk.readthedocs.io/en/latest/capabilities/ for more info. type Capabilities struct { AttachmentsFolder string `ocscapability:"config => attachments => folder"` - ChatMaxLength int - Audio bool `ocscapability:"audio"` - Video bool `ocscapability:"video"` - Chat bool `ocscapability:"chat"` - GuestSignaling bool `ocscapability:"guest-signaling"` - EmptyGroupRoom bool `ocscapability:"empty-group-room"` - GuestDisplayNames bool `ocscapability:"guest-display-names"` - MultiRoomUsers bool `ocscapability:"multi-room-users"` - ChatV2 bool `ocscapability:"chat-v2"` - Favorites bool `ocscapability:"favorites"` - LastRoomActivity bool `ocscapability:"last-room-activity"` - NoPing bool `ocscapability:"no-ping"` - SystemMessages bool `ocscapability:"system-messages"` - MentionFlag bool `ocscapability:"mention-flag"` - InCallFlags bool `ocscapability:"in-call-flags"` - InviteByMail bool `ocscapability:"invite-by-mail"` - NotificationLevels bool `ocscapability:"notification-levels"` - InviteGroupsAndMails bool `ocscapability:"invite-groups-and-mails"` - LockedOneToOneRooms bool `ocscapability:"locked-one-to-one-rooms"` - ReadOnlyRooms bool `ocscapability:"read-only-rooms"` - ChatReadMarker bool `ocscapability:"chat-read-marker"` - WebinaryLobby bool `ocscapability:"webinary-lobby"` - StartCallFlag bool `ocscapability:"start-call-flag"` - ChatReplies bool `ocscapability:"chat-replies"` - CirclesSupport bool `ocscapability:"circles-support"` - AttachmentsAllowed bool `ocscapability:"config => attachments => allowed"` - ConversationsCanCreate bool `ocscapability:"config => conversations => can-create"` - ForceMute bool `ocscapability:"force-mute"` - ConversationV2 bool `ocscapability:"conversation-v2"` - ChatReferenceID bool `ocscapability:"chat-reference-id"` + Audio bool `ocscapability:"audio"` + Video bool `ocscapability:"video"` + Chat bool `ocscapability:"chat"` + GuestSignaling bool `ocscapability:"guest-signaling"` + EmptyGroupRoom bool `ocscapability:"empty-group-room"` + GuestDisplayNames bool `ocscapability:"guest-display-names"` + MultiRoomUsers bool `ocscapability:"multi-room-users"` + ChatV2 bool `ocscapability:"chat-v2"` + Favorites bool `ocscapability:"favorites"` + LastRoomActivity bool `ocscapability:"last-room-activity"` + NoPing bool `ocscapability:"no-ping"` + SystemMessages bool `ocscapability:"system-messages"` + MentionFlag bool `ocscapability:"mention-flag"` + InCallFlags bool `ocscapability:"in-call-flags"` + InviteByMail bool `ocscapability:"invite-by-mail"` + NotificationLevels bool `ocscapability:"notification-levels"` + InviteGroupsAndMails bool `ocscapability:"invite-groups-and-mails"` + LockedOneToOneRooms bool `ocscapability:"locked-one-to-one-rooms"` + ReadOnlyRooms bool `ocscapability:"read-only-rooms"` + ChatReadMarker bool `ocscapability:"chat-read-marker"` + WebinaryLobby bool `ocscapability:"webinary-lobby"` + StartCallFlag bool `ocscapability:"start-call-flag"` + ChatReplies bool `ocscapability:"chat-replies"` + CirclesSupport bool `ocscapability:"circles-support"` + AttachmentsAllowed bool `ocscapability:"config => attachments => allowed"` + ConversationsCanCreate bool `ocscapability:"config => conversations => can-create"` + ForceMute bool `ocscapability:"force-mute"` + ConversationV2 bool `ocscapability:"conversation-v2"` + ChatReferenceID bool `ocscapability:"chat-reference-id"` + ConversationV3 bool `ocscapability:"conversation-v3"` + ConversationV4 bool `ocscapability:"conversation-v4"` + SIPSupport bool `ocscapability:"sip-support"` + ChatReadStatus bool `ocscapability:"chat-read-status"` + ListableRooms bool `ocscapability:"listable-rooms"` + PhonebookSearch bool `ocscapability:"phonebook-search"` + RaiseHand bool `ocscapability:"raise-hand"` + RoomDescription bool `ocscapability:"room-description"` + DeleteMessages bool `ocscapability:"delete-messages"` + RichObjectSharing bool `ocscapability:"rich-object-sharing"` + ConversationCallFlags bool `ocscapability:"conversation-call-flags"` + GeoLocationSharing bool `ocscapability:"geo-location-sharing"` + ReadPrivacyConfig bool `ocscapability:"config => chat => read-privacy"` + SignalingV3 bool `ocscapability:"signaling-v3"` + TempUserAvatarAPI bool `ocscapability:"temp-user-avatar-api"` + MaxGifSizeConfig int `ocscapability:"config => previews => max-gif-size"` + ChatMaxLength int `ocscapability:"config => chat => max-length"` } // RoomInfo contains information about a room @@ -160,8 +180,17 @@ func (t *TalkUser) RequestClient(client request.Client) *request.Client { // GetRooms returns a list of all rooms the user is in func (t *TalkUser) GetRooms() (*[]RoomInfo, error) { + endpoint := ocsRoomsv2Endpoint + capabilities, err := t.Capabilities() + if err != nil { + return nil, err + } + if capabilities.ConversationV4 { + endpoint = ocsRoomsv4Endpoint + } + client := t.RequestClient(request.Client{ - URL: ocsRoomsEndpoint, + URL: endpoint, }) res, err := client.Do() if err != nil { @@ -239,6 +268,22 @@ func (t *TalkUser) Capabilities() (*Capabilities, error) { ConversationV2: sliceContains(sc.Features, "conversation-v2"), ChatReferenceID: sliceContains(sc.Features, "chat-reference-id"), ChatMaxLength: sc.Config.Chat.MaxLength, + ConversationV3: sliceContains(sc.Features, "conversation-v3"), + ConversationV4: sliceContains(sc.Features, "conversation-v4"), + SIPSupport: sliceContains(sc.Features, "sip-support"), + ChatReadStatus: sliceContains(sc.Features, "chat-read-status"), + ListableRooms: sliceContains(sc.Features, "listable-rooms"), + PhonebookSearch: sliceContains(sc.Features, "phonebook-search"), + RaiseHand: sliceContains(sc.Features, "raise-hand"), + RoomDescription: sliceContains(sc.Features, "room-description"), + ReadPrivacyConfig: sc.Config.Chat.ReadPrivacy != 0, + MaxGifSizeConfig: sc.Config.Previews.MaxGifSize, + DeleteMessages: sliceContains(sc.Features, "delete-messages"), + RichObjectSharing: sliceContains(sc.Features, "rich-object-sharing"), + ConversationCallFlags: sliceContains(sc.Features, "conversation-call-flags"), + GeoLocationSharing: sliceContains(sc.Features, "geo-location-sharing"), + SignalingV3: sliceContains(sc.Features, "signaling-v3"), + TempUserAvatarAPI: sliceContains(sc.Features, "temp-user-avatar-api"), } t.capabilities = tr @@ -264,7 +309,11 @@ func (t *TalkUser) DownloadFile(path string) (data *[]byte, err error) { URL: url, }) res, err := c.Do() - if err != nil || res.StatusCode() != 200 { + if err != nil { + return + } + if res.StatusCode() != 200 { + err = ErrCannotDownloadFile return } data = &res.Data -- cgit v1.2.3