summaryrefslogtreecommitdiffstats
path: root/vendor/gomod.garykim.dev/nc-talk/room/room.go
diff options
context:
space:
mode:
authorGary Kim <gary@garykim.dev>2020-12-10 07:06:27 +0800
committerGitHub <noreply@github.com>2020-12-10 00:06:27 +0100
commit41b4e64be9216f5fa6db694b7a8f47f34ca415be (patch)
tree559ff1a6e8896cba67aff5f519009a9611280818 /vendor/gomod.garykim.dev/nc-talk/room/room.go
parent0d7315249d20bf9856605068074a7b6c6bcce835 (diff)
downloadmatterbridge-msglm-41b4e64be9216f5fa6db694b7a8f47f34ca415be.tar.gz
matterbridge-msglm-41b4e64be9216f5fa6db694b7a8f47f34ca415be.tar.bz2
matterbridge-msglm-41b4e64be9216f5fa6db694b7a8f47f34ca415be.zip
Update go-nc-talk (nctalk) (#1333)
Signed-off-by: Gary Kim <gary@garykim.dev>
Diffstat (limited to 'vendor/gomod.garykim.dev/nc-talk/room/room.go')
-rw-r--r--vendor/gomod.garykim.dev/nc-talk/room/room.go28
1 files changed, 25 insertions, 3 deletions
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",