Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MI-3650] Added the metric for MS Graph client method time #371

Merged
merged 38 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8788616
[MI-3624] Add some additional metrics
ayusht2810 Oct 18, 2023
9e4298d
[MI-3624] Remove extra comments
ayusht2810 Oct 18, 2023
f57a0f6
Merge branch 'main' of github.com:mattermost/mattermost-plugin-msteam…
ayusht2810 Oct 18, 2023
6406197
[MI-3624] Fix testcases
ayusht2810 Oct 18, 2023
5c9dffd
[MI-3642] Add metrics to count upstream users
ayusht2810 Oct 18, 2023
4a75b85
[MI-3643] Add metrics to show messages confirmed count
ayusht2810 Oct 18, 2023
939a058
[MI-3624] Update variable names and add new
ayusht2810 Oct 18, 2023
a2c750e
[MI-3644] Add metrics of subscription count for different actions
ayusht2810 Oct 19, 2023
4a9e5d1
[MI-3644] Revert extra changes
ayusht2810 Oct 19, 2023
8b9a011
[MI-3646] Added metrics for MS Graph API time
manojmalik20 Oct 20, 2023
8388f5c
Merge branch 'main' of github.com:mattermost/mattermost-plugin-msteam…
ayusht2810 Oct 23, 2023
9a4f727
[MI-3624] Update function, added util and minor review fixes
ayusht2810 Oct 23, 2023
4a66aa0
[MI-3644] Update help text
ayusht2810 Oct 23, 2023
41e1fe5
[MI-3646] Did some refactoring and fixed failing lint checks
manojmalik20 Oct 23, 2023
6628939
[MI-3624] Reuse constants from other packages
ayusht2810 Oct 23, 2023
7ac96b9
[MI-3642] Add comments in metrics interface
ayusht2810 Oct 23, 2023
9ddcb34
Merge branch 'MI-3624' of github.com:mattermost/mattermost-plugin-mst…
ayusht2810 Oct 23, 2023
cb2e025
Merge branch 'MI-3642' of github.com:mattermost/mattermost-plugin-mst…
ayusht2810 Oct 23, 2023
5ed51db
Merge branch 'MI-3643' of github.com:mattermost/mattermost-plugin-mst…
ayusht2810 Oct 23, 2023
05e6988
[MI-3650] Added the metric for MS Graph client method time
manojmalik20 Oct 23, 2023
8a82cc6
[MI-3650] Fixed the failing unit tests
manojmalik20 Oct 23, 2023
bf17c3d
[MI-3624] Update function arguments type
ayusht2810 Oct 24, 2023
1bc0839
Merge branch 'main' of github.com:mattermost/mattermost-plugin-msteam…
ayusht2810 Oct 24, 2023
945c9cf
[MI-3642] Remove extra debug log and re-organize interface methods
ayusht2810 Oct 24, 2023
da34aba
[MI-3624] Fix lint
ayusht2810 Oct 24, 2023
4991a27
Merge branch 'MI-3624' of github.com:mattermost/mattermost-plugin-mst…
ayusht2810 Oct 24, 2023
423b7cc
[MI-3642] Reverting removal of extra information from debug log
ayusht2810 Oct 24, 2023
750f251
Merge branch 'MI-3642' of github.com:mattermost/mattermost-plugin-mst…
ayusht2810 Oct 24, 2023
0dc738d
[MI-3643] Move constants from handlers to metrics package and update …
ayusht2810 Oct 24, 2023
799096f
Merge branch 'MI-3643' of github.com:mattermost/mattermost-plugin-mst…
ayusht2810 Oct 24, 2023
7ac83f3
Merge branch 'MI-3644' of github.com:mattermost/mattermost-plugin-mst…
manojmalik20 Oct 24, 2023
b2afc23
Merge branch 'MI-3646' of github.com:mattermost/mattermost-plugin-mst…
manojmalik20 Oct 24, 2023
f60dc22
[MI-3650] Removed unnecessary logs and function mocks from unit tests
manojmalik20 Oct 24, 2023
78e3e15
[MI-3650] Changed the order of functions in the Metrics interface
manojmalik20 Oct 24, 2023
5a95ba0
Merge branch 'main' of github.com:mattermost/mattermost-plugin-msteam…
manojmalik20 Oct 25, 2023
17a7c17
[MI-3650] Removed unnecessary changes for this PR
manojmalik20 Oct 25, 2023
4e843c1
[MI-3650] Added nil check for metrics in the timerlayer for client
manojmalik20 Oct 25, 2023
a7631f7
Merge branch 'main' of github.com:mattermost/mattermost-plugin-msteam…
manojmalik20 Oct 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/mattermost/mattermost-server/v6 v6.0.0-20230901142735-ccceee77061a
github.com/mattn/godown v0.0.1
github.com/microsoft/kiota-abstractions-go v1.2.2
github.com/microsoft/kiota-http-go v1.1.0
github.com/microsoftgraph/msgraph-sdk-go v1.20.0
github.com/microsoftgraph/msgraph-sdk-go-core v1.0.0
github.com/pborman/uuid v1.2.1
Expand Down Expand Up @@ -81,7 +82,6 @@ require (
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/microsoft/kiota-authentication-azure-go v1.0.0 // indirect
github.com/microsoft/kiota-http-go v1.1.0 // indirect
github.com/microsoft/kiota-serialization-form-go v1.0.0 // indirect
github.com/microsoft/kiota-serialization-json-go v1.0.4 // indirect
github.com/microsoft/kiota-serialization-multipart-go v1.0.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func (a *API) oauthRedirectHandler(w http.ResponseWriter, r *http.Request) {
return
}

client := msteams.NewTokenClient(a.p.GetURL()+"/oauth-redirect", a.p.configuration.TenantID, a.p.configuration.ClientID, a.p.configuration.ClientSecret, token, &a.p.apiClient.Log)
client := msteams.NewTokenClient(a.p.GetURL()+"/oauth-redirect", a.p.configuration.TenantID, a.p.configuration.ClientID, a.p.configuration.ClientSecret, token, &a.p.apiClient.Log, a.p.metricsService)
if err = client.Connect(); err != nil {
a.p.API.LogError("Unable to connect to the client", "error", err.Error())
http.Error(w, "failed to connect to the client", http.StatusInternalServerError)
Expand Down
110 changes: 92 additions & 18 deletions server/api_test.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"

"github.com/mattermost/mattermost-plugin-api/experimental/command"
"github.com/mattermost/mattermost-plugin-msteams-sync/server/metrics"
"github.com/mattermost/mattermost-plugin-msteams-sync/server/msteams"
"github.com/mattermost/mattermost-plugin-msteams-sync/server/store/storemodels"
"github.com/mattermost/mattermost-server/v6/model"
Expand Down Expand Up @@ -202,6 +203,7 @@ func (p *Plugin) executeLinkCommand(args *model.CommandArgs, parameters []string
return p.cmdError(args.UserId, args.ChannelId, "Unable to subscribe to the channel")
}

p.metricsService.ObserveSubscriptionsCount(metrics.SubscriptionConnected)
if err = p.store.StoreChannelLink(&channelLink); err != nil {
p.API.LogDebug("Unable to create the new link", "error", err.Error())
return p.cmdError(args.UserId, args.ChannelId, "Unable to create new link.")
Expand Down
71 changes: 49 additions & 22 deletions server/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"testing"
"time"

"github.com/mattermost/mattermost-plugin-msteams-sync/server/msteams"
"github.com/mattermost/mattermost-plugin-msteams-sync/server/metrics"
mockMetrics "github.com/mattermost/mattermost-plugin-msteams-sync/server/metrics/mocks"
"github.com/mattermost/mattermost-plugin-msteams-sync/server/msteams/clientmodels"
mockClient "github.com/mattermost/mattermost-plugin-msteams-sync/server/msteams/mocks"
mockStore "github.com/mattermost/mattermost-plugin-msteams-sync/server/store/mocks"
"github.com/mattermost/mattermost-plugin-msteams-sync/server/store/storemodels"
Expand Down Expand Up @@ -232,8 +234,8 @@ func TestExecuteShowCommand(t *testing.T) {
}, nil).Times(1)
},
setupClient: func(c *mockClient.Client) {
c.On("GetTeam", "Valid-MSTeamsTeam").Return(&msteams.Team{}, nil).Times(1)
c.On("GetChannelInTeam", mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return(&msteams.Channel{}, nil).Times(1)
c.On("GetTeam", "Valid-MSTeamsTeam").Return(&clientmodels.Team{}, nil).Times(1)
c.On("GetChannelInTeam", mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return(&clientmodels.Channel{}, nil).Times(1)
},
},
{
Expand Down Expand Up @@ -304,8 +306,8 @@ func TestExecuteShowLinksCommand(t *testing.T) {
s.On("ListChannelLinksWithNames").Return(testutils.GetChannelLinks(1), nil).Times(1)
},
setupClient: func(c *mockClient.Client) {
c.On("GetTeams", mock.AnythingOfType("string")).Return([]*msteams.Team{{ID: testutils.GetTeamsTeamID(), DisplayName: "Test MS team"}}, nil).Times(1)
c.On("GetChannelsInTeam", testutils.GetTeamsTeamID(), mock.AnythingOfType("string")).Return([]*msteams.Channel{{ID: testutils.GetTeamsChannelID(), DisplayName: "Test MS channel"}}, nil).Times(1)
c.On("GetTeams", mock.AnythingOfType("string")).Return([]*clientmodels.Team{{ID: testutils.GetTeamsTeamID(), DisplayName: "Test MS team"}}, nil).Times(1)
c.On("GetChannelsInTeam", testutils.GetTeamsTeamID(), mock.AnythingOfType("string")).Return([]*clientmodels.Channel{{ID: testutils.GetTeamsChannelID(), DisplayName: "Test MS channel"}}, nil).Times(1)
},
},
{
Expand Down Expand Up @@ -544,12 +546,13 @@ func TestExecuteLinkCommand(t *testing.T) {
mockAPI := &plugintest.API{}

for _, testCase := range []struct {
description string
parameters []string
args *model.CommandArgs
setupAPI func(*plugintest.API)
setupStore func(*mockStore.Store)
setupClient func(*mockClient.Client, *mockClient.Client)
description string
parameters []string
args *model.CommandArgs
setupAPI func(*plugintest.API)
setupStore func(*mockStore.Store)
setupClient func(*mockClient.Client, *mockClient.Client)
setupMetrics func(mockmetrics *mockMetrics.Metrics)
}{
{
description: "Successfully executed link command",
Expand Down Expand Up @@ -583,7 +586,11 @@ func TestExecuteLinkCommand(t *testing.T) {
s.On("CommitTx", &sql.Tx{}).Return(nil).Times(1)
},
setupClient: func(c *mockClient.Client, uc *mockClient.Client) {
uc.On("GetChannelInTeam", testutils.GetTeamsUserID(), testutils.GetChannelID()).Return(&msteams.Channel{}, nil)
uc.On("GetChannelInTeam", testutils.GetTeamsUserID(), testutils.GetChannelID()).Return(&clientmodels.Channel{}, nil)
},
setupMetrics: func(mockmetrics *mockMetrics.Metrics) {
mockmetrics.On("ObserveSubscriptionsCount", metrics.SubscriptionConnected).Times(1)
mockmetrics.On("ObserveMSGraphClientMethodDuration", "Client.GetChannelInTeam", "true", mock.AnythingOfType("float64")).Once()
},
},
{
Expand Down Expand Up @@ -617,7 +624,11 @@ func TestExecuteLinkCommand(t *testing.T) {
s.On("BeginTx").Return(nil, errors.New("error in beginning the database transaction")).Times(1)
},
setupClient: func(c *mockClient.Client, uc *mockClient.Client) {
uc.On("GetChannelInTeam", testutils.GetTeamsUserID(), testutils.GetChannelID()).Return(&msteams.Channel{}, nil)
uc.On("GetChannelInTeam", testutils.GetTeamsUserID(), testutils.GetChannelID()).Return(&clientmodels.Channel{}, nil)
},
setupMetrics: func(mockmetrics *mockMetrics.Metrics) {
mockmetrics.On("ObserveSubscriptionsCount", metrics.SubscriptionConnected).Times(1)
mockmetrics.On("ObserveMSGraphClientMethodDuration", "Client.GetChannelInTeam", "true", mock.AnythingOfType("float64")).Once()
},
},
{
Expand Down Expand Up @@ -653,7 +664,11 @@ func TestExecuteLinkCommand(t *testing.T) {
s.On("CommitTx", &sql.Tx{}).Return(errors.New("error in committing transaction")).Times(1)
},
setupClient: func(c *mockClient.Client, uc *mockClient.Client) {
uc.On("GetChannelInTeam", testutils.GetTeamsUserID(), testutils.GetChannelID()).Return(&msteams.Channel{}, nil)
uc.On("GetChannelInTeam", testutils.GetTeamsUserID(), testutils.GetChannelID()).Return(&clientmodels.Channel{}, nil)
},
setupMetrics: func(mockmetrics *mockMetrics.Metrics) {
mockmetrics.On("ObserveSubscriptionsCount", metrics.SubscriptionConnected).Times(1)
mockmetrics.On("ObserveMSGraphClientMethodDuration", "Client.GetChannelInTeam", "true", mock.AnythingOfType("float64")).Once()
},
},
{
Expand All @@ -679,7 +694,10 @@ func TestExecuteLinkCommand(t *testing.T) {
s.On("StoreChannelLink", mock.Anything).Return(nil).Times(1)
},
setupClient: func(c *mockClient.Client, uc *mockClient.Client) {
uc.On("GetChannelInTeam", testutils.GetTeamsUserID(), testutils.GetChannelID()).Return(&msteams.Channel{}, nil)
uc.On("GetChannelInTeam", testutils.GetTeamsUserID(), testutils.GetChannelID()).Return(&clientmodels.Channel{}, nil)
},
setupMetrics: func(metrics *mockMetrics.Metrics) {
metrics.On("ObserveMSGraphClientMethodDuration", "Client.GetChannelInTeam", "true", mock.AnythingOfType("float64")).Once()
},
},
{
Expand All @@ -696,8 +714,9 @@ func TestExecuteLinkCommand(t *testing.T) {
api.On("HasPermissionToChannel", testutils.GetUserID(), testutils.GetChannelID(), model.PermissionManageChannelRoles).Return(true).Times(1)
api.On("SendEphemeralPost", testutils.GetUserID(), testutils.GetEphemeralPost("bot-user-id", testutils.GetChannelID(), "Invalid link command, please pass the MS Teams team id and channel id as parameters.")).Return(testutils.GetPost(testutils.GetChannelID(), testutils.GetUserID(), time.Now().UnixMicro())).Times(1)
},
setupStore: func(s *mockStore.Store) {},
setupClient: func(c *mockClient.Client, uc *mockClient.Client) {},
setupStore: func(s *mockStore.Store) {},
setupClient: func(c *mockClient.Client, uc *mockClient.Client) {},
setupMetrics: func(mockmetrics *mockMetrics.Metrics) {},
},
{
description: "Team is not enabled for MS Teams sync",
Expand All @@ -713,7 +732,8 @@ func TestExecuteLinkCommand(t *testing.T) {
setupStore: func(s *mockStore.Store) {
s.On("CheckEnabledTeamByTeamID", "").Return(false).Times(1)
},
setupClient: func(c *mockClient.Client, uc *mockClient.Client) {},
setupClient: func(c *mockClient.Client, uc *mockClient.Client) {},
setupMetrics: func(mockmetrics *mockMetrics.Metrics) {},
},
{
description: "Unable to get the current channel information",
Expand All @@ -728,7 +748,8 @@ func TestExecuteLinkCommand(t *testing.T) {
setupStore: func(s *mockStore.Store) {
s.On("CheckEnabledTeamByTeamID", testutils.GetTeamsUserID()).Return(true).Times(1)
},
setupClient: func(c *mockClient.Client, uc *mockClient.Client) {},
setupClient: func(c *mockClient.Client, uc *mockClient.Client) {},
setupMetrics: func(mockmetrics *mockMetrics.Metrics) {},
},
{
description: "Unable to link the channel as only channel admin can link it",
Expand All @@ -747,7 +768,8 @@ func TestExecuteLinkCommand(t *testing.T) {
setupStore: func(s *mockStore.Store) {
s.On("CheckEnabledTeamByTeamID", testutils.GetTeamsUserID()).Return(true).Times(1)
},
setupClient: func(c *mockClient.Client, uc *mockClient.Client) {},
setupClient: func(c *mockClient.Client, uc *mockClient.Client) {},
setupMetrics: func(mockmetrics *mockMetrics.Metrics) {},
},
{
description: "Unable to link channel as channel is either a direct or group message",
Expand All @@ -765,7 +787,8 @@ func TestExecuteLinkCommand(t *testing.T) {
setupStore: func(s *mockStore.Store) {
s.On("CheckEnabledTeamByTeamID", testutils.GetTeamsUserID()).Return(true).Times(1)
},
setupClient: func(c *mockClient.Client, uc *mockClient.Client) {},
setupClient: func(c *mockClient.Client, uc *mockClient.Client) {},
setupMetrics: func(mockmetrics *mockMetrics.Metrics) {},
},
{
description: "Unable to find MS Teams channel as user don't have the permissions to access it",
Expand Down Expand Up @@ -796,14 +819,18 @@ func TestExecuteLinkCommand(t *testing.T) {
setupClient: func(c *mockClient.Client, uc *mockClient.Client) {
uc.On("GetChannelInTeam", testutils.GetTeamsUserID(), "").Return(nil, errors.New("Error while getting the channel"))
},
setupMetrics: func(metrics *mockMetrics.Metrics) {
metrics.On("ObserveMSGraphClientMethodDuration", "Client.GetChannelInTeam", "false", mock.AnythingOfType("float64")).Once()
},
},
} {
t.Run(testCase.description, func(t *testing.T) {
p.SetAPI(mockAPI)
testCase.setupAPI(mockAPI)

testCase.setupStore(p.store.(*mockStore.Store))
testCase.setupClient(p.msteamsAppClient.(*mockClient.Client), p.clientBuilderWithToken("", "", "", "", nil, nil).(*mockClient.Client))
testCase.setupClient(p.msteamsAppClient.(*mockClient.Client), p.clientBuilderWithToken("", "", "", "", nil, nil, nil).(*mockClient.Client))
testCase.setupMetrics(p.metricsService.(*mockMetrics.Metrics))
_, _ = p.executeLinkCommand(testCase.args, testCase.parameters)
})
}
Expand Down
31 changes: 24 additions & 7 deletions server/handlers/attachments.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import (
"strings"
"time"

"github.com/mattermost/mattermost-plugin-msteams-sync/server/metrics"
"github.com/mattermost/mattermost-plugin-msteams-sync/server/msteams"
"github.com/mattermost/mattermost-plugin-msteams-sync/server/msteams/clientmodels"
"github.com/mattermost/mattermost-server/v6/app/imaging"
"github.com/mattermost/mattermost-server/v6/model"
)

func GetResourceIDsFromURL(weburl string) (*msteams.ActivityIds, error) {
func GetResourceIDsFromURL(weburl string) (*clientmodels.ActivityIds, error) {
parsedURL, err := url.Parse(weburl)
if err != nil {
return nil, err
Expand All @@ -25,7 +27,7 @@ func GetResourceIDsFromURL(weburl string) (*msteams.ActivityIds, error) {
path := strings.TrimPrefix(parsedURL.Path, "/beta/")
path = strings.TrimPrefix(path, "/v1.0/")
urlParts := strings.Split(path, "/")
activityIDs := &msteams.ActivityIds{}
activityIDs := &clientmodels.ActivityIds{}
if urlParts[0] == "chats" && len(urlParts) >= 6 {
activityIDs.ChatID = urlParts[1]
activityIDs.MessageID = urlParts[3]
Expand Down Expand Up @@ -91,11 +93,12 @@ func (ah *ActivityHandler) ProcessAndUploadFileToMM(attachmentData []byte, attac
return fileInfo.Id, false
}

func (ah *ActivityHandler) handleAttachments(channelID, userID, text string, msg *msteams.Message, chat *msteams.Chat, isUpdatedActivity bool) (string, model.StringArray, string, bool) {
func (ah *ActivityHandler) handleAttachments(channelID, userID, text string, msg *clientmodels.Message, chat *clientmodels.Chat, isUpdatedActivity bool) (string, model.StringArray, string, bool) {
attachments := []string{}
newText := text
parentID := ""
countAttachments := 0
countFileAttachments := 0
var client msteams.Client
if chat == nil {
client = ah.plugin.GetClientForApp()
Expand All @@ -114,19 +117,26 @@ func (ah *ActivityHandler) handleAttachments(channelID, userID, text string, msg
return "", nil, "", errorFound
}

isDirectMessage := false
if chat != nil {
isDirectMessage = true
}

for _, a := range msg.Attachments {
// remove the attachment tags from the text
newText = attachRE.ReplaceAllString(newText, "")

// handle a code snippet (code block)
if a.ContentType == "application/vnd.microsoft.card.codesnippet" {
newText = ah.handleCodeSnippet(client, a, newText)
countAttachments++
continue
}

// handle a message reference (reply)
if a.ContentType == "messageReference" {
parentID, newText = ah.handleMessageReference(a, msg.ChatID+msg.ChannelID, newText)
countAttachments++
continue
}

Expand All @@ -143,19 +153,22 @@ func (ah *ActivityHandler) handleAttachments(channelID, userID, text string, msg
attachmentData, err = ah.handleDownloadFile(a.ContentURL, client)
if err != nil {
ah.plugin.GetAPI().LogError("failed to download the file", "filename", a.Name, "error", err.Error())
ah.plugin.GetMetrics().ObserveFilesCount(metrics.ActionCreated, metrics.ActionSourceMSTeams, discardedReasonUnableToGetTeamsData, isDirectMessage, int64(IncreaseFileCountByOne))
continue
}
} else {
fileSize, downloadURL, err = client.GetFileSizeAndDownloadURL(a.ContentURL)
if err != nil {
ah.plugin.GetAPI().LogError("failed to get file size and download URL", "error", err.Error())
ah.plugin.GetMetrics().ObserveFilesCount(metrics.ActionCreated, metrics.ActionSourceMSTeams, discardedReasonUnableToGetTeamsData, isDirectMessage, int64(IncreaseFileCountByOne))
continue
}

fileSizeAllowed := *ah.plugin.GetAPI().GetConfig().FileSettings.MaxFileSize
if fileSize > fileSizeAllowed {
ah.plugin.GetAPI().LogError("skipping file download from MS Teams because the file size is greater than the allowed size")
errorFound = true
ah.plugin.GetMetrics().ObserveFilesCount(metrics.ActionCreated, metrics.ActionSourceMSTeams, discardedReasonMaxFileSizeExceeded, isDirectMessage, int64(IncreaseFileCountByOne))
continue
}

Expand All @@ -164,6 +177,7 @@ func (ah *ActivityHandler) handleAttachments(channelID, userID, text string, msg
attachmentData, err = client.GetFileContent(downloadURL)
if err != nil {
ah.plugin.GetAPI().LogError("failed to get file content", "error", err.Error())
ah.plugin.GetMetrics().ObserveFilesCount(metrics.ActionCreated, metrics.ActionSourceMSTeams, discardedReasonUnableToGetTeamsData, isDirectMessage, int64(IncreaseFileCountByOne))
continue
}
}
Expand All @@ -184,12 +198,15 @@ func (ah *ActivityHandler) handleAttachments(channelID, userID, text string, msg
}

if fileInfoID == "" {
ah.plugin.GetMetrics().ObserveFilesCount(metrics.ActionCreated, metrics.ActionSourceMSTeams, discardedReasonEmptyFileID, isDirectMessage, int64(IncreaseFileCountByOne))
continue
}
attachments = append(attachments, fileInfoID)
countAttachments++
if countAttachments == 10 {
ah.plugin.GetMetrics().ObserveFilesCount(metrics.ActionCreated, metrics.ActionSourceMSTeams, "", isDirectMessage, int64(IncreaseFileCountByOne))
countFileAttachments++
if countFileAttachments == maxFileAttachmentsSupported {
ah.plugin.GetAPI().LogDebug("discarding the rest of the attachments as Mattermost supports only 10 attachments per post")
ah.plugin.GetMetrics().ObserveFilesCount(metrics.ActionCreated, metrics.ActionSourceMSTeams, discardedReasonFileLimitReached, isDirectMessage, int64(len(msg.Attachments)-countAttachments-countFileAttachments))
break
}
}
Expand All @@ -215,7 +232,7 @@ func (ah *ActivityHandler) GetFileFromTeamsAndUploadToMM(downloadURL string, cli
return fileInfo.Id
}

func (ah *ActivityHandler) handleCodeSnippet(client msteams.Client, attach msteams.Attachment, text string) string {
func (ah *ActivityHandler) handleCodeSnippet(client msteams.Client, attach clientmodels.Attachment, text string) string {
var content struct {
Language string `json:"language"`
CodeSnippetURL string `json:"codeSnippetUrl"`
Expand Down Expand Up @@ -245,7 +262,7 @@ func (ah *ActivityHandler) handleCodeSnippet(client msteams.Client, attach mstea
return newText
}

func (ah *ActivityHandler) handleMessageReference(attach msteams.Attachment, chatOrChannelID string, text string) (string, string) {
func (ah *ActivityHandler) handleMessageReference(attach clientmodels.Attachment, chatOrChannelID string, text string) (string, string) {
var content struct {
MessageID string `json:"messageId"`
}
Expand Down
Loading
Loading