summaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
authorWim <wim@42.be>2020-01-01 22:08:11 +0100
committerWim <wim@42.be>2020-03-01 22:19:33 +0100
commit915ca8f817e0a9000d546766515e1ec4221d9d43 (patch)
treef0d7e9e6f796cfb74cb0f045e48b9412af270df2 /bridge
parenta65a81610ba30c54bdf1f2045b56b89fe469a140 (diff)
downloadmatterbridge-msglm-915ca8f817e0a9000d546766515e1ec4221d9d43.tar.gz
matterbridge-msglm-915ca8f817e0a9000d546766515e1ec4221d9d43.tar.bz2
matterbridge-msglm-915ca8f817e0a9000d546766515e1ec4221d9d43.zip
Make linter happy and cleanup (msteams)
Diffstat (limited to 'bridge')
-rw-r--r--bridge/msteams/handler.go13
-rw-r--r--bridge/msteams/msteams.go17
2 files changed, 16 insertions, 14 deletions
diff --git a/bridge/msteams/handler.go b/bridge/msteams/handler.go
index 3283588a..8cccfe0c 100644
--- a/bridge/msteams/handler.go
+++ b/bridge/msteams/handler.go
@@ -5,6 +5,7 @@ import (
"github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/bridge/helper"
+ msgraph "github.com/yaegashi/msgraph.go/beta"
)
func (b *Bmsteams) findFile(weburl string) (string, error) {
@@ -44,3 +45,15 @@ func (b *Bmsteams) handleDownloadFile(rmsg *config.Message, filename, weburl str
helper.HandleDownloadData(b.Log, rmsg, filename, comment, weburl, data, b.General)
return nil
}
+
+func (b *Bmsteams) handleAttachments(rmsg *config.Message, msg msgraph.ChatMessage) {
+ for _, a := range msg.Attachments {
+ //remove the attachment tags from the text
+ rmsg.Text = attachRE.ReplaceAllString(rmsg.Text, "")
+ //handle the download
+ err := b.handleDownloadFile(rmsg, *a.Name, *a.ContentURL)
+ if err != nil {
+ b.Log.Errorf("download of %s failed: %s", *a.Name, err)
+ }
+ }
+}
diff --git a/bridge/msteams/msteams.go b/bridge/msteams/msteams.go
index 8c9fa265..f6e556fe 100644
--- a/bridge/msteams/msteams.go
+++ b/bridge/msteams/msteams.go
@@ -19,8 +19,8 @@ import (
"golang.org/x/oauth2"
)
-//var defaultScopes = []string{"openid", "profile", "offline_access", "User.Read", "Files.Read", "ChannelMessage.Read.All", "Chat.ReadWrite", "User.Read.All", "User.ReadWrite.All", "Group.Read.All", "Group.ReadWrite.All"}
-var defaultScopes = []string{"openid", "profile", "offline_access", "Group.Read.All", "Group.ReadWrite.All"}
+var defaultScopes = []string{} //"openid", "profile", "offline_access", "Group.Read.All", "Group.ReadWrite.All"}
+var attachRE = regexp.MustCompile(`<attachment id=.*?attachment>`)
type Bmsteams struct {
gc *msgraph.GraphServiceRequestBuilder
@@ -121,7 +121,6 @@ func (b *Bmsteams) getMessages(channel string) ([]msgraph.ChatMessage, error) {
}
func (b *Bmsteams) poll(channelName string) {
- re := regexp.MustCompile(`<attachment id=.*?attachment>`)
msgmap := make(map[string]time.Time)
b.Log.Debug("getting initial messages")
res, err := b.getMessages(channelName)
@@ -173,17 +172,7 @@ func (b *Bmsteams) poll(channelName string) {
Extra: make(map[string][]interface{}),
}
- if len(msg.Attachments) > 0 {
- for _, a := range msg.Attachments {
- //remove the attachment tags from the text
- rmsg.Text = re.ReplaceAllString(rmsg.Text, "")
- //handle the download
- err := b.handleDownloadFile(&rmsg, *a.Name, *a.ContentURL)
- if err != nil {
- b.Log.Errorf("download of %s failed: %s", *a.Name, err)
- }
- }
- }
+ b.handleAttachments(&rmsg, msg)
b.Log.Debugf("<= Message is %#v", rmsg)
b.Remote <- rmsg
}