diff options
-rw-r--r-- | bridge/nctalk/nctalk.go | 44 | ||||
-rw-r--r-- | go.mod | 2 | ||||
-rw-r--r-- | go.sum | 2 | ||||
-rw-r--r-- | vendor/gomod.garykim.dev/nc-talk/.drone.yml | 24 | ||||
-rw-r--r-- | vendor/gomod.garykim.dev/nc-talk/.github_changelog_generator | 12 | ||||
-rw-r--r-- | vendor/gomod.garykim.dev/nc-talk/.golangci.yml | 26 | ||||
-rw-r--r-- | vendor/gomod.garykim.dev/nc-talk/CHANGELOG.md | 71 | ||||
-rw-r--r-- | vendor/gomod.garykim.dev/nc-talk/README.md | 27 | ||||
-rw-r--r-- | vendor/gomod.garykim.dev/nc-talk/constants/constants.go | 2 | ||||
-rw-r--r-- | vendor/gomod.garykim.dev/nc-talk/go.mod | 8 | ||||
-rw-r--r-- | vendor/gomod.garykim.dev/nc-talk/go.sum | 15 | ||||
-rw-r--r-- | vendor/gomod.garykim.dev/nc-talk/gonctalk.go | 44 | ||||
-rw-r--r-- | vendor/gomod.garykim.dev/nc-talk/room/room.go | 6 | ||||
-rw-r--r-- | vendor/modules.txt | 3 |
14 files changed, 49 insertions, 237 deletions
diff --git a/bridge/nctalk/nctalk.go b/bridge/nctalk/nctalk.go index 23b59135..6af819af 100644 --- a/bridge/nctalk/nctalk.go +++ b/bridge/nctalk/nctalk.go @@ -9,7 +9,6 @@ import ( "github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge/config" - talk "gomod.garykim.dev/nc-talk" "gomod.garykim.dev/nc-talk/ocs" "gomod.garykim.dev/nc-talk/room" "gomod.garykim.dev/nc-talk/user" @@ -61,8 +60,12 @@ func (b *Btalk) Disconnect() error { } func (b *Btalk) JoinChannel(channel config.ChannelInfo) error { + tr, err := room.NewTalkRoom(b.user, channel.Name) + if err != nil { + return err + } newRoom := Broom{ - room: talk.NewRoom(b.user, channel.Name), + room: tr, } newRoom.ctx, newRoom.ctxCancel = context.WithCancel(context.Background()) c, err := newRoom.room.ReceiveMessages(newRoom.ctx) @@ -79,6 +82,7 @@ func (b *Btalk) JoinChannel(channel config.ChannelInfo) error { go func() { for msg := range c { + msg := msg // ignore messages that are one of the following // * not a message from a user // * from ourselves @@ -97,6 +101,15 @@ func (b *Btalk) JoinChannel(channel config.ChannelInfo) error { if msg.ID != 0 { remoteMessage.ID = strconv.Itoa(msg.ID) } + + // Handle Files + err = b.handleFiles(&remoteMessage, &msg) + if err != nil { + b.Log.Errorf("Error handling file: %#v", msg) + + continue + } + b.Log.Debugf("<= Message is %#v", remoteMessage) b.Remote <- remoteMessage } @@ -132,6 +145,31 @@ func (b *Btalk) getRoom(token string) *Broom { return nil } +func (b *Btalk) handleFiles(mmsg *config.Message, message *ocs.TalkRoomMessageData) error { + for _, parameter := range message.MessageParameters { + if parameter.Type == ocs.ROSTypeFile { + // Get the file + file, err := b.user.DownloadFile(parameter.Path) + if err != nil { + return err + } + + if mmsg.Extra == nil { + mmsg.Extra = make(map[string][]interface{}) + } + + mmsg.Extra["file"] = append(mmsg.Extra["file"], config.FileInfo{ + Name: parameter.Name, + Data: file, + Size: int64(len(*file)), + Avatar: false, + }) + } + } + + return nil +} + // Spec: https://github.com/nextcloud/server/issues/1706#issue-182308785 func formatRichObjectString(message string, parameters map[string]ocs.RichObjectString) string { for id, parameter := range parameters { @@ -142,7 +180,7 @@ func formatRichObjectString(message string, parameters map[string]ocs.RichObject text = "@" + text case ocs.ROSTypeFile: if parameter.Link != "" { - text = parameter.Link + text = parameter.Name } } @@ -50,7 +50,7 @@ require ( github.com/zfjagann/golang-ring v0.0.0-20190304061218-d34796e0a6c2 golang.org/x/image v0.0.0-20200801110659-972c09e46d76 golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43 - gomod.garykim.dev/nc-talk v0.1.4 + gomod.garykim.dev/nc-talk v0.1.5 gopkg.in/olahol/melody.v1 v1.0.0-20170518105555-d52139073376 layeh.com/gumble v0.0.0-20200818122324-146f9205029b ) @@ -993,6 +993,8 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1N golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gomod.garykim.dev/nc-talk v0.1.4 h1:U9viudEgq/biocorgWvZRVR+27IPEczYl/yszSvzN+8= gomod.garykim.dev/nc-talk v0.1.4/go.mod h1:zKg8yxCk2KaTy6aPDEfRac0Jik72czX+nRsG8CZuhtc= +gomod.garykim.dev/nc-talk v0.1.5 h1:zZ/FviVpwJuhD/YrKiAvs6Z3Oew/DL/w6RKbKaanhFA= +gomod.garykim.dev/nc-talk v0.1.5/go.mod h1:zKg8yxCk2KaTy6aPDEfRac0Jik72czX+nRsG8CZuhtc= google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/api v0.0.0-20181030000543-1d582fd0359e/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/api v0.0.0-20181220000619-583d854617af/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= diff --git a/vendor/gomod.garykim.dev/nc-talk/.drone.yml b/vendor/gomod.garykim.dev/nc-talk/.drone.yml deleted file mode 100644 index f2367e4d..00000000 --- a/vendor/gomod.garykim.dev/nc-talk/.drone.yml +++ /dev/null @@ -1,24 +0,0 @@ -kind: pipeline -type: docker -name: test - -steps: - - name: golangci-lint - image: golangci/golangci-lint:latest-alpine - commands: - - golangci-lint run - - name: test - image: golang:1.13 - commands: - - go test ./... - - name: build-test - image: golang:1.13 - commands: - - go build - -trigger: - branch: - - master - event: - - pull_request - - push diff --git a/vendor/gomod.garykim.dev/nc-talk/.github_changelog_generator b/vendor/gomod.garykim.dev/nc-talk/.github_changelog_generator deleted file mode 100644 index eb4525d8..00000000 --- a/vendor/gomod.garykim.dev/nc-talk/.github_changelog_generator +++ /dev/null @@ -1,12 +0,0 @@ -user=gary-kim -project=go-nc-talk -add_sections={"dependencies": {"labels": ["dependencies"], "prefix": "### Dependencies"}, "Added": {"labels": ["feature"], "prefix": "### Added"}} -output= -header_label=# Go Library for Nextcloud Talk -enhancement_prefix=### Changed -deprecated_prefix=### Deprecated -removed_prefix=### Removed -security_prefix=### Security -bug_prefix=### Fixed -add_pr_wo_labels=false -issues=false diff --git a/vendor/gomod.garykim.dev/nc-talk/.golangci.yml b/vendor/gomod.garykim.dev/nc-talk/.golangci.yml deleted file mode 100644 index ef89770a..00000000 --- a/vendor/gomod.garykim.dev/nc-talk/.golangci.yml +++ /dev/null @@ -1,26 +0,0 @@ -# golangci-lint configuration options - -linters: - enable: - - deadcode - - errcheck - - goimports - - golint - - ineffassign - - structcheck - - varcheck - - govet - - unconvert - - prealloc - - maligned - disable-all: false - -issues: - # Enable some lints excluded by default - exclude-use-default: false - - # Maximum issues count per one linter. Set to 0 to disable. Default is 50. - max-per-linter: 0 - - # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. - max-same-issues: 0 diff --git a/vendor/gomod.garykim.dev/nc-talk/CHANGELOG.md b/vendor/gomod.garykim.dev/nc-talk/CHANGELOG.md deleted file mode 100644 index b30e1f11..00000000 --- a/vendor/gomod.garykim.dev/nc-talk/CHANGELOG.md +++ /dev/null @@ -1,71 +0,0 @@ -# Go Library for Nextcloud Talk - -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.4](https://github.com/gary-kim/go-nc-talk/tree/v0.1.4) - 2020-09-22 - -[Full Changelog](https://github.com/gary-kim/go-nc-talk/compare/v0.1.3...v0.1.4) - -### Fixed - -- Add ActorType for message data [\#18](https://github.com/gary-kim/go-nc-talk/pull/18) ([@gary-kim](https://github.com/gary-kim)) - -## [v0.1.3](https://github.com/gary-kim/go-nc-talk/tree/v0.1.3) - 2020-09-03 - -[Full Changelog](https://github.com/gary-kim/go-nc-talk/compare/v0.1.2...v0.1.3) - -### Fixed - -- Close response bodies [\#15](https://github.com/gary-kim/go-nc-talk/pull/15) ([@gary-kim](https://github.com/gary-kim)) - -## [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) - -### Fixed - -- ROS type should be of ROST type [\#12](https://github.com/gary-kim/go-nc-talk/pull/12) ([@gary-kim](https://github.com/gary-kim)) -- Fix error when sending a message with no RCS data [\#10](https://github.com/gary-kim/go-nc-talk/pull/10) ([@gary-kim](https://github.com/gary-kim)) - -## [v0.1.0](https://github.com/gary-kim/go-nc-talk/tree/v0.1.0) - 2020-08-13 - -[Full Changelog](https://github.com/gary-kim/go-nc-talk/compare/v0.0.2...v0.1.0) - -### Added - -- Add TLSConfig [\#9](https://github.com/gary-kim/go-nc-talk/pull/9) ([@gary-kim](https://github.com/gary-kim)) -- Add Software using this library in README [\#8](https://github.com/gary-kim/go-nc-talk/pull/8) ([@gary-kim](https://github.com/gary-kim)) -- Add some basic tests [\#7](https://github.com/gary-kim/go-nc-talk/pull/7) ([@gary-kim](https://github.com/gary-kim)) -- Add support for downloading files [\#1](https://github.com/gary-kim/go-nc-talk/pull/1) ([@gary-kim](https://github.com/gary-kim)) - -### Fixed - -- Return error on blank token [\#6](https://github.com/gary-kim/go-nc-talk/pull/6) ([@gary-kim](https://github.com/gary-kim)) -- Add v0.0.2 to changelog [\#4](https://github.com/gary-kim/go-nc-talk/pull/4) ([@gary-kim](https://github.com/gary-kim)) - -## [v0.0.2](https://github.com/gary-kim/go-nc-talk/tree/v0.0.2) - 2020-07-26 - -[Full Changelog](https://github.com/gary-kim/go-nc-talk/compare/v0.0.1...v0.0.2) - -### Changed - -- Add installation instructions to README.md [\#2](https://github.com/gary-kim/go-nc-talk/pull/2) ([@gary-kim](https://github.com/gary-kim)) - -### Fixed - -- Fix Capabilities Request [\#3](https://github.com/gary-kim/go-nc-talk/pull/3) ([@gary-kim](https://github.com/gary-kim)) - -## [v0.0.1](https://github.com/gary-kim/riotchat/tree/v0.0.1) - 2020-07-10 - -* First release diff --git a/vendor/gomod.garykim.dev/nc-talk/README.md b/vendor/gomod.garykim.dev/nc-talk/README.md deleted file mode 100644 index efa87c6c..00000000 --- a/vendor/gomod.garykim.dev/nc-talk/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# Go Library for Nextcloud Talk - -[![Build Status](https://ghdrone.garykim.dev/api/badges/gary-kim/go-nc-talk/status.svg)](https://ghdrone.garykim.dev/gary-kim/go-nc-talk) -[![Godoc](https://img.shields.io/badge/godoc-gomod.garykim.dev%2Fnc--talk-informational)](https://pkg.go.dev/gomod.garykim.dev/nc-talk) - -A Go library that can be used to communicate with [Nextcloud Talk](https://github.com/nextcloud/spreed) instances. - -### Installing - -You can use this library in your Go projects by installing it with go mod: - -```bash -GO111MODULE=on go get gomod.garykim.dev/nc-talk -``` - -Check out the documentation for the package [here](https://pkg.go.dev/gomod.garykim.dev/nc-talk). - - -### Software using this library - -* [Matterbridge](https://github.com/42wim/matterbridge) - -### License - -Copyright © 2020 Gary Kim <<gary@garykim.dev>>, All Rights Reserved - -Licensed under [Apache-2.0](LICENSE) 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/go.mod b/vendor/gomod.garykim.dev/nc-talk/go.mod deleted file mode 100644 index 1aa51ff7..00000000 --- a/vendor/gomod.garykim.dev/nc-talk/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module gomod.garykim.dev/nc-talk - -go 1.13 - -require ( - github.com/monaco-io/request v1.0.4 - github.com/stretchr/testify v1.6.1 -) diff --git a/vendor/gomod.garykim.dev/nc-talk/go.sum b/vendor/gomod.garykim.dev/nc-talk/go.sum deleted file mode 100644 index b4d32468..00000000 --- a/vendor/gomod.garykim.dev/nc-talk/go.sum +++ /dev/null @@ -1,15 +0,0 @@ -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/monaco-io/request v1.0.3 h1:FsiIwXCCbHEyWx9A7lgg6JBTMHhHlEEsADsgAOvZ9HA= -github.com/monaco-io/request v1.0.3/go.mod h1:EmggwHktBsbJmCgwZXqy7o0H1NNsAstQBWZrFVd3xtQ= -github.com/monaco-io/request v1.0.4 h1:AbogA+IvPOWqyGZIFU7kSb8YS2Jv5Dnl5ncMj8cQV+o= -github.com/monaco-io/request v1.0.4/go.mod h1:EmggwHktBsbJmCgwZXqy7o0H1NNsAstQBWZrFVd3xtQ= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/vendor/gomod.garykim.dev/nc-talk/gonctalk.go b/vendor/gomod.garykim.dev/nc-talk/gonctalk.go deleted file mode 100644 index 727d5006..00000000 --- a/vendor/gomod.garykim.dev/nc-talk/gonctalk.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2020 Gary Kim <gary@garykim.dev>, All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package talk - -import ( - "gomod.garykim.dev/nc-talk/room" - "gomod.garykim.dev/nc-talk/user" -) - -// NewUser returns a TalkUser instance -// The url should be the full URL of the Nextcloud instance (e.g. https://cloud.mydomain.me) -// -// Deprecated: Use user.NewUser instead for more options and error checks -func NewUser(url string, username string, password string) *user.TalkUser { - return &user.TalkUser{ - NextcloudURL: url, - User: username, - Pass: password, - } -} - -// NewRoom returns a new TalkRoom instance -// Token should be the Nextcloud Room Token (e.g. "d6zoa2zs" if the room URL is https://cloud.mydomain.me/call/d6zoa2zs) -// -// Deprecated: Use room.NewRoom instead for extra error checks. -func NewRoom(tuser *user.TalkUser, token string) *room.TalkRoom { - tr := &room.TalkRoom{ - User: tuser, - Token: token, - } - return tr -} diff --git a/vendor/gomod.garykim.dev/nc-talk/room/room.go b/vendor/gomod.garykim.dev/nc-talk/room/room.go index b53b01fc..da058a37 100644 --- a/vendor/gomod.garykim.dev/nc-talk/room/room.go +++ b/vendor/gomod.garykim.dev/nc-talk/room/room.go @@ -62,7 +62,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 +93,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", @@ -154,7 +154,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/modules.txt b/vendor/modules.txt index 313cad58..e95b3de7 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -293,8 +293,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.4 -gomod.garykim.dev/nc-talk +# gomod.garykim.dev/nc-talk v0.1.5 gomod.garykim.dev/nc-talk/constants gomod.garykim.dev/nc-talk/ocs gomod.garykim.dev/nc-talk/room |