summaryrefslogtreecommitdiffstats
path: root/vendor/gomod.garykim.dev
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gomod.garykim.dev')
-rw-r--r--vendor/gomod.garykim.dev/nc-talk/constants/constants.go2
-rw-r--r--vendor/gomod.garykim.dev/nc-talk/ocs/message.go3
-rw-r--r--vendor/gomod.garykim.dev/nc-talk/room/room.go28
-rw-r--r--vendor/gomod.garykim.dev/nc-talk/user/user.go58
4 files changed, 60 insertions, 31 deletions
diff --git a/vendor/gomod.garykim.dev/nc-talk/constants/constants.go b/vendor/gomod.garykim.dev/nc-talk/constants/constants.go
index c70e4daa..44473546 100644
--- a/vendor/gomod.garykim.dev/nc-talk/constants/constants.go
+++ b/vendor/gomod.garykim.dev/nc-talk/constants/constants.go
@@ -21,5 +21,5 @@ const (
// RemoteDavEndpoint returns the endpoint for the Dav API for Nextcloud
func RemoteDavEndpoint(username string, davType string) string {
- return "/remote.php/dav/" + username + "/" + davType + "/"
+ return "/remote.php/dav/" + davType + "/" + username + "/"
}
diff --git a/vendor/gomod.garykim.dev/nc-talk/ocs/message.go b/vendor/gomod.garykim.dev/nc-talk/ocs/message.go
index 9de28b47..d4766006 100644
--- a/vendor/gomod.garykim.dev/nc-talk/ocs/message.go
+++ b/vendor/gomod.garykim.dev/nc-talk/ocs/message.go
@@ -43,7 +43,10 @@ const (
)
// TalkRoomMessageData describes the data part of a ocs response for a Talk room message
+//
+// Error will be set if a message request ran into an error.
type TalkRoomMessageData struct {
+ Error error `json:"-"`
Message string `json:"message"`
ID int `json:"id"`
ActorType ActorType `json:"actorType"`
diff --git a/vendor/gomod.garykim.dev/nc-talk/room/room.go b/vendor/gomod.garykim.dev/nc-talk/room/room.go
index b53b01fc..1ee73740 100644
--- a/vendor/gomod.garykim.dev/nc-talk/room/room.go
+++ b/vendor/gomod.garykim.dev/nc-talk/room/room.go
@@ -33,10 +33,14 @@ var (
ErrEmptyToken = errors.New("given an empty token")
// ErrRoomNotFound is returned when a room with the given token could not be found
ErrRoomNotFound = errors.New("room could not be found")
+ // ErrUnauthorized is returned when the room could not be accessed due to being unauthorized
+ ErrUnauthorized = errors.New("unauthorized error when accessing room")
// ErrNotModeratorInLobby is returned when the room is in lobby mode but the user is not a moderator
ErrNotModeratorInLobby = errors.New("room is in lobby mode but user is not a moderator")
// ErrUnexpectedReturnCode is returned when the server did not respond with an expected return code
ErrUnexpectedReturnCode = errors.New("unexpected return code")
+ // ErrTooManyRequests is returned if the server returns a 429
+ ErrTooManyRequests = errors.New("too many requests")
)
// TalkRoom represents a room in Nextcloud Talk
@@ -62,7 +66,7 @@ func NewTalkRoom(tuser *user.TalkUser, token string) (*TalkRoom, error) {
// SendMessage sends a message in the Talk room
func (t *TalkRoom) SendMessage(msg string) (*ocs.TalkRoomMessageData, error) {
- url := t.User.NextcloudURL + constants.BaseEndpoint + "/chat/" + t.Token
+ url := t.User.NextcloudURL + constants.BaseEndpoint + "chat/" + t.Token
requestParams := map[string]string{
"message": msg,
}
@@ -93,7 +97,7 @@ func (t *TalkRoom) ReceiveMessages(ctx context.Context) (chan ocs.TalkRoomMessag
if err != nil {
return nil, err
}
- url := t.User.NextcloudURL + constants.BaseEndpoint + "/chat/" + t.Token
+ url := t.User.NextcloudURL + constants.BaseEndpoint + "chat/" + t.Token
requestParam := map[string]string{
"lookIntoFuture": "1",
"includeLastKnown": "0",
@@ -127,6 +131,24 @@ func (t *TalkRoom) ReceiveMessages(ctx context.Context) (chan ocs.TalkRoomMessag
if err != nil {
continue
}
+
+ // If it seems that we no longer have access to the chat for one reason or another, stop the goroutine and set error in the next return.
+ if res.StatusCode == 404 {
+ _ = res.Body.Close()
+ c <- ocs.TalkRoomMessageData{Error: ErrRoomNotFound}
+ return
+ }
+ if res.StatusCode == 401 {
+ _ = res.Body.Close()
+ c <- ocs.TalkRoomMessageData{Error: ErrUnauthorized}
+ return
+ }
+ if res.StatusCode == 429 {
+ _ = res.Body.Close()
+ c <- ocs.TalkRoomMessageData{Error: ErrTooManyRequests}
+ return
+ }
+
if res.StatusCode == 200 {
lastKnown = res.Header.Get("X-Chat-Last-Given")
data, err := ioutil.ReadAll(res.Body)
@@ -154,7 +176,7 @@ func (t *TalkRoom) TestConnection() error {
if t.Token == "" {
return ErrEmptyToken
}
- url := t.User.NextcloudURL + constants.BaseEndpoint + "/chat/" + t.Token
+ url := t.User.NextcloudURL + constants.BaseEndpoint + "chat/" + t.Token
requestParam := map[string]string{
"lookIntoFuture": "0",
"includeLastKnown": "0",
diff --git a/vendor/gomod.garykim.dev/nc-talk/user/user.go b/vendor/gomod.garykim.dev/nc-talk/user/user.go
index 08c01e33..2b42dacf 100644
--- a/vendor/gomod.garykim.dev/nc-talk/user/user.go
+++ b/vendor/gomod.garykim.dev/nc-talk/user/user.go
@@ -87,38 +87,38 @@ type Capabilities struct {
// 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"`
+ 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) {
return &TalkUser{
- NextcloudURL: url,
+ NextcloudURL: strings.TrimSuffix(url, "/"),
User: username,
Pass: password,
Config: config,
@@ -143,7 +143,11 @@ func (t *TalkUser) RequestClient(client request.Client) *request.Client {
// Set Nextcloud URL if there is no host
if !strings.HasPrefix(client.URL, t.NextcloudURL) {
- client.URL = t.NextcloudURL + "/" + client.URL
+ if strings.HasPrefix(client.URL, "/") {
+ client.URL = t.NextcloudURL + client.URL
+ } else {
+ client.URL = t.NextcloudURL + "/" + client.URL
+ }
}
// Set TLS Config