Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit 58512b9a571e23119eb032bd6ff96444a843a3ab Author: Wim <wim@42.be> Date: Wed Jan 01 22:08:11 2020 +0000 Make linter happy and cleanup (msteams) diff --git a/bridge/msteams/handler.go b/bridge/msteams/handler.go index 3283588..8cccfe0 100644 --- a/bridge/msteams/handler.go +++ b/bridge/msteams/handler.go @@ -56 +57 @@ 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) { @@ -443 +4515 @@ 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 8c9fa26..f6e556f 100644 --- a/bridge/msteams/msteams.go +++ b/bridge/msteams/msteams.go @@ -198 +198 @@ 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 @@ -1217 +1216 @@ 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) @@ -17317 +1727 @@ 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   }