diff options
Diffstat (limited to 'vendor')
-rw-r--r-- | vendor/gomod.garykim.dev/nc-talk/CHANGELOG.md | 8 | ||||
-rw-r--r-- | vendor/gomod.garykim.dev/nc-talk/room/room.go | 15 | ||||
-rw-r--r-- | vendor/gomod.garykim.dev/nc-talk/user/user.go | 54 | ||||
-rw-r--r-- | vendor/modules.txt | 2 |
4 files changed, 71 insertions, 8 deletions
diff --git a/vendor/gomod.garykim.dev/nc-talk/CHANGELOG.md b/vendor/gomod.garykim.dev/nc-talk/CHANGELOG.md index 405a2112..55e2cf03 100644 --- a/vendor/gomod.garykim.dev/nc-talk/CHANGELOG.md +++ b/vendor/gomod.garykim.dev/nc-talk/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v0.1.2](https://github.com/gary-kim/go-nc-talk/tree/v0.1.2) - 2020-08-28 + +[Full Changelog](https://github.com/gary-kim/go-nc-talk/compare/v0.1.1...v0.1.2) + +### Fixed + +- Use lastReadMessage for first lastKnownMessageId [\#14](https://github.com/gary-kim/go-nc-talk/pull/14) ([@tilosp](https://github.com/tilosp)) + ## [v0.1.1](https://github.com/gary-kim/go-nc-talk/tree/v0.1.1) - 2020-08-24 [Full Changelog](https://github.com/gary-kim/go-nc-talk/compare/v0.1.0...v0.1.1) diff --git a/vendor/gomod.garykim.dev/nc-talk/room/room.go b/vendor/gomod.garykim.dev/nc-talk/room/room.go index 5452993d..3527bb7a 100644 --- a/vendor/gomod.garykim.dev/nc-talk/room/room.go +++ b/vendor/gomod.garykim.dev/nc-talk/room/room.go @@ -18,6 +18,7 @@ import ( "context" "errors" "io/ioutil" + "strconv" "time" "github.com/monaco-io/request" @@ -98,16 +99,16 @@ func (t *TalkRoom) ReceiveMessages(ctx context.Context) (chan ocs.TalkRoomMessag "includeLastKnown": "0", } lastKnown := "" - client := t.User.RequestClient(request.Client{ - URL: url, - Params: requestParam, - Timeout: time.Second * 60, - }) - res, err := client.Resp() + res, err := t.User.GetRooms() if err != nil { return nil, err } - lastKnown = res.Header.Get("X-Chat-Last-Given") + for _, r := range *res { + if r.Token == t.Token { + lastKnown = strconv.Itoa(r.LastReadMessage) + break + } + } go func() { for { if ctx.Err() != nil { diff --git a/vendor/gomod.garykim.dev/nc-talk/user/user.go b/vendor/gomod.garykim.dev/nc-talk/user/user.go index 2f8a3c0a..08c01e33 100644 --- a/vendor/gomod.garykim.dev/nc-talk/user/user.go +++ b/vendor/gomod.garykim.dev/nc-talk/user/user.go @@ -28,6 +28,7 @@ import ( const ( ocsCapabilitiesEndpoint = "/ocs/v2.php/cloud/capabilities" + ocsRoomsEndpoint = "/ocs/v2.php/apps/spreed/api/v2/room" ) var ( @@ -84,6 +85,35 @@ type Capabilities struct { ChatReferenceID bool `ocscapability:"chat-reference-id"` } +// RoomInfo contains information about a room +type RoomInfo struct { + Token string `json:"token"` + Name string `json:"name"` + DisplayName string `json:"displayName"` + SessionID string `json:"sessionId"` + ObjectType string `json:"objectType"` + ObjectID string `json:"objectId"` + Type int `json:"type"` + ParticipantType int `json:"participantType"` + ParticipantFlags int `json:"participantFlags"` + ReadOnly int `json:"readOnly"` + LastPing int `json:"lastPing"` + LastActivity int `json:"lastActivity"` + NotificationLevel int `json:"notificationLevel"` + LobbyState int `json:"lobbyState"` + LobbyTimer int `json:"lobbyTimer"` + UnreadMessages int `json:"unreadMessages"` + LastReadMessage int `json:"lastReadMessage"` + HasPassword bool `json:"hasPassword"` + HasCall bool `json:"hasCall"` + CanStartCall bool `json:"canStartCall"` + CanDeleteConversation bool `json:"canDeleteConversation"` + CanLeaveConversation bool `json:"canLeaveConversation"` + IsFavorite bool `json:"isFavorite"` + UnreadMention bool `json:"unreadMention"` + LastMessage ocs.TalkRoomMessageData `json:"lastMessage"` +} + // NewUser returns a TalkUser instance // The url should be the full URL of the Nextcloud instance (e.g. https://cloud.mydomain.me) func NewUser(url string, username string, password string, config *TalkUserConfig) (*TalkUser, error) { @@ -124,6 +154,30 @@ func (t *TalkUser) RequestClient(client request.Client) *request.Client { return &client } +// GetRooms returns a list of all rooms the user is in +func (t *TalkUser) GetRooms() (*[]RoomInfo, error) { + client := t.RequestClient(request.Client{ + URL: ocsRoomsEndpoint, + }) + res, err := client.Do() + if err != nil { + return nil, err + } + + var roomsRequest struct { + OCS struct { + Data []RoomInfo `json:"data"` + } `json:"ocs"` + } + + err = json.Unmarshal(res.Data, &roomsRequest) + if err != nil { + return nil, err + } + + return &roomsRequest.OCS.Data, nil +} + // Capabilities returns an instance of Capabilities that describes what the Nextcloud Talk instance supports func (t *TalkUser) Capabilities() (*Capabilities, error) { if t.capabilities != nil { diff --git a/vendor/modules.txt b/vendor/modules.txt index cd3e7000..65810bd7 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -291,7 +291,7 @@ golang.org/x/text/secure/bidirule golang.org/x/text/transform golang.org/x/text/unicode/bidi golang.org/x/text/unicode/norm -# gomod.garykim.dev/nc-talk v0.1.1 +# gomod.garykim.dev/nc-talk v0.1.2 gomod.garykim.dev/nc-talk gomod.garykim.dev/nc-talk/constants gomod.garykim.dev/nc-talk/ocs |