Skip to content

Commit

Permalink
Make linter happy and cleanup (msteams)
Browse files Browse the repository at this point in the history
  • Loading branch information
42wim committed Jan 9, 2020
1 parent 15d571f commit a0596ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
13 changes: 13 additions & 0 deletions bridge/msteams/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}
}
17 changes: 3 additions & 14 deletions bridge/msteams/msteams.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit a0596ab

Please sign in to comment.