From 6e958a5f101edbdb4c7d08a33cc5acc512ec7c8a Mon Sep 17 00:00:00 2001 From: Christopher Poile Date: Tue, 14 Nov 2023 11:07:16 -0500 Subject: [PATCH 1/5] update server dep; use PushSubTypeCalls --- go.mod | 2 +- go.sum | 2 ++ server/push_notifications.go | 8 ++------ 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 1c435cd63..40d2c1d4d 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/mattermost/calls-recorder v0.4.2 github.com/mattermost/logr/v2 v2.0.16 github.com/mattermost/mattermost-plugin-calls/server/public v0.0.1 - github.com/mattermost/mattermost/server/public v0.0.10-0.20231109142142-8ffda2b73ea8 + github.com/mattermost/mattermost/server/public v0.0.10-0.20231114142547-f0c94858133b github.com/mattermost/rtcd v0.12.0 github.com/mattermost/squirrel v0.2.0 github.com/pion/interceptor v0.1.25 diff --git a/go.sum b/go.sum index ba3237293..13acc7f17 100644 --- a/go.sum +++ b/go.sum @@ -297,6 +297,8 @@ github.com/mattermost/logr/v2 v2.0.16 h1:jnePX4cPskC3WDFvUardh/xZfxNdsFXbEERJQ1k github.com/mattermost/logr/v2 v2.0.16/go.mod h1:1dm/YhTpozsqANXxo5Pi5zYLBsal2xY0pX+JZNbzYJY= github.com/mattermost/mattermost/server/public v0.0.10-0.20231109142142-8ffda2b73ea8 h1:tZhcvX1k526YLHeO8lQpFa8J2Ejr7sHEYdzst5xrIjA= github.com/mattermost/mattermost/server/public v0.0.10-0.20231109142142-8ffda2b73ea8/go.mod h1:AMuKlAabVFnLvf5bXg+69EdvtLIfty4ahFossB34LM4= +github.com/mattermost/mattermost/server/public v0.0.10-0.20231114142547-f0c94858133b h1:B2PNC1Mjq7LC2h2d0bkgo5pPZP3b7ik6U13LFsRXRi8= +github.com/mattermost/mattermost/server/public v0.0.10-0.20231114142547-f0c94858133b/go.mod h1:AMuKlAabVFnLvf5bXg+69EdvtLIfty4ahFossB34LM4= github.com/mattermost/rtcd v0.12.0 h1:T/07JYExpwMmWq58QIp8KU08FWOzVmmatzLaEOIMP4A= github.com/mattermost/rtcd v0.12.0/go.mod h1:s0J7u93n2e2YPATEWCiiJ19iQf2TTHJapXQR2POE8KA= github.com/mattermost/squirrel v0.2.0 h1:8ZWeyf+MWQ2cL7hu9REZgLtz2IJi51qqZEovI3T3TT8= diff --git a/server/push_notifications.go b/server/push_notifications.go index 47a308f5a..556142bc9 100644 --- a/server/push_notifications.go +++ b/server/push_notifications.go @@ -60,11 +60,6 @@ func (p *Plugin) sendPushNotifications(channelID, createdPostID, threadID string return } - pushType := model.PushTypeMessage - if err := checkMinVersion(minPushProxyVersionWithCalls, p.pushProxyVersion); err == nil { - pushType = model.PushTypeCalls - } - for _, member := range members { if member.Id == sender.Id { continue @@ -72,7 +67,8 @@ func (p *Plugin) sendPushNotifications(channelID, createdPostID, threadID string msg := &model.PushNotification{ Version: model.PushMessageV2, - Type: pushType, + Type: model.PushTypeMessage, + SubType: model.PushSubTypeCalls, TeamId: channel.TeamId, ChannelId: channelID, PostId: createdPostID, From 54002edf72be55ff4d89a83f62a4bc9ea3334a42 Mon Sep 17 00:00:00 2001 From: Christopher Poile Date: Tue, 14 Nov 2023 11:14:47 -0500 Subject: [PATCH 2/5] ripping out loadPushProxyVersion and tests to merge with prev commit --- server/activate.go | 2 - server/plugin.go | 3 -- server/push_notifications.go | 2 - server/utils.go | 53 ------------------------ server/utils_test.go | 79 ------------------------------------ 5 files changed, 139 deletions(-) diff --git a/server/activate.go b/server/activate.go index 35c573481..3367e86d4 100644 --- a/server/activate.go +++ b/server/activate.go @@ -124,8 +124,6 @@ func (p *Plugin) OnActivate() error { }() } - p.loadPushProxyVersion() - if rtcdURL := cfg.getRTCDURL(); rtcdURL != "" && p.licenseChecker.RTCDAllowed() { rtcdManager, err := p.newRTCDClientManager(rtcdURL) if err != nil { diff --git a/server/plugin.go b/server/plugin.go index fe1b29235..7881157a3 100644 --- a/server/plugin.go +++ b/server/plugin.go @@ -67,9 +67,6 @@ type Plugin struct { // Database handle to the writer DB node wDB *sql.DB driverName string - - // Push-proxy's version, refreshed when the plugin activates - pushProxyVersion string } func (p *Plugin) startSession(us *session, senderID string) { diff --git a/server/push_notifications.go b/server/push_notifications.go index 556142bc9..6b342fb32 100644 --- a/server/push_notifications.go +++ b/server/push_notifications.go @@ -5,8 +5,6 @@ import ( "github.com/mattermost/mattermost/server/public/model" ) -const minPushProxyVersionWithCalls = "5.27.0" - func (p *Plugin) NotificationWillBePushed(notification *model.PushNotification, userID string) (*model.PushNotification, string) { // We will use our own notifications if: // 1. This is a call start post diff --git a/server/utils.go b/server/utils.go index 65b387fc7..460795493 100644 --- a/server/utils.go +++ b/server/utils.go @@ -6,7 +6,6 @@ package main import ( "bytes" "compress/zlib" - "encoding/json" "errors" "fmt" "github.com/mattermost/mattermost/server/public/model" @@ -65,58 +64,6 @@ func (p *Plugin) getNotificationNameFormat(userID string) string { return *config.TeamSettings.TeammateNameDisplay } -func (p *Plugin) loadPushProxyVersion() { - config := p.API.GetConfig() - if err := p.canSendPushNotifications(config, p.API.GetLicense()); err != nil { - p.LogWarn(err.Error()) - return - } - - client := NewClient() - var err error - p.pushProxyVersion, err = getPushProxyVersion(client, config) - if err != nil { - p.LogError(err.Error()) - } -} - -// getPushProxyVersion will return the version if the push proxy is reachable and version >= 5.27.0 -// which is when the "/version" endpoint was added. Otherwise it will return "" for lower versions and for -// failed attempts to get the version (which could mean only that the push proxy was unavailable temporarily) -func getPushProxyVersion(client *http.Client, config *model.Config) (string, error) { - if config == nil || - config.EmailSettings.PushNotificationServer == nil || - *config.EmailSettings.PushNotificationServer == "" { - return "", nil - } - serverURL := strings.TrimRight(*config.EmailSettings.PushNotificationServer, "/") + "/version" - req, err := http.NewRequest("GET", serverURL, nil) - if err != nil { - return "", fmt.Errorf("failed to build request, err: %w", err) - } - - resp, err := client.Do(req) - if err != nil { - return "", fmt.Errorf("http request failed, err: %w", err) - } - defer resp.Body.Close() - - if resp.StatusCode == http.StatusOK { - var respData = struct { - Version string - Hash string - }{} - if err := json.NewDecoder(resp.Body).Decode(&respData); err != nil { - return "", fmt.Errorf("failed to decode http response, err: %w", err) - } - - return respData.Version, nil - } - - // Must not be newer version of push proxy - return "", nil -} - func (p *Plugin) canSendPushNotifications(config *model.Config, license *model.License) error { if config == nil || config.EmailSettings.SendPushNotifications == nil || diff --git a/server/utils_test.go b/server/utils_test.go index b8fce13c7..724f9c59f 100644 --- a/server/utils_test.go +++ b/server/utils_test.go @@ -232,82 +232,3 @@ func TestPlugin_canSendPushNotifications(t *testing.T) { }) } } - -func TestPlugin_getPushProxyVersion(t *testing.T) { - config := &model.Config{ - EmailSettings: model.EmailSettings{ - PushNotificationServer: model.NewString(model.MHPNS), - }, - } - - tests := []struct { - name string - config *model.Config - want string - handler func(http.ResponseWriter) - }{ - { - name: "config nil", - config: nil, - want: "", - }, - { - name: "no push server", - config: &model.Config{ - EmailSettings: model.EmailSettings{ - PushNotificationServer: model.NewString(""), - }, - }, - want: "", - }, - { - name: "nil push server", - config: &model.Config{ - EmailSettings: model.EmailSettings{ - PushNotificationServer: nil, - }, - }, - want: "", - }, - { - name: "404 (old push proxy)", - config: config, - want: "", - handler: func(w http.ResponseWriter) { - w.WriteHeader(http.StatusNotFound) - }, - }, - { - name: "got a version", - config: config, - want: "5.37.0", - handler: func(w http.ResponseWriter) { - _, _ = w.Write([]byte(`{"version": "5.37.0", "hash": "abcde3445"}`)) - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - assert.Equal(t, "/version", req.URL.String()) - if tt.handler != nil { - tt.handler(w) - } - })) - defer server.Close() - - // Do we have a push server url? if so, rewrite it for the test. - // Why are we doing it this way? We want to test the variety of different states the config - // can be in, as well as the responses the push proxy can give us. - if tt.config != nil && - tt.config.EmailSettings.PushNotificationServer != nil && - *tt.config.EmailSettings.PushNotificationServer != "" { - tt.config.EmailSettings.PushNotificationServer = model.NewString(server.URL) - } - ret, err := getPushProxyVersion(server.Client(), tt.config) - - assert.NoError(t, err) - assert.Equalf(t, tt.want, ret, "test name: %s", tt.name) - }) - } -} From 6cc3af77f33ce463bf7aaf2d8e15ce10451adcfd Mon Sep 17 00:00:00 2001 From: Christopher Poile Date: Tue, 14 Nov 2023 13:32:42 -0500 Subject: [PATCH 3/5] update server dep again (for correct calls sub_type) --- go.mod | 2 +- go.sum | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 40d2c1d4d..7dd5887ad 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/mattermost/calls-recorder v0.4.2 github.com/mattermost/logr/v2 v2.0.16 github.com/mattermost/mattermost-plugin-calls/server/public v0.0.1 - github.com/mattermost/mattermost/server/public v0.0.10-0.20231114142547-f0c94858133b + github.com/mattermost/mattermost/server/public v0.0.11-0.20231114165607-9c6bfd527dee github.com/mattermost/rtcd v0.12.0 github.com/mattermost/squirrel v0.2.0 github.com/pion/interceptor v0.1.25 diff --git a/go.sum b/go.sum index 13acc7f17..2167629e2 100644 --- a/go.sum +++ b/go.sum @@ -295,10 +295,8 @@ github.com/mattermost/ldap v3.0.4+incompatible h1:SOeNnz+JNR+foQ3yHkYqijb9MLPhXN github.com/mattermost/ldap v3.0.4+incompatible/go.mod h1:b4reDCcGpBxJ4WX0f224KFY+OR0npin7or7EFpeIko4= github.com/mattermost/logr/v2 v2.0.16 h1:jnePX4cPskC3WDFvUardh/xZfxNdsFXbEERJQ1kUEDE= github.com/mattermost/logr/v2 v2.0.16/go.mod h1:1dm/YhTpozsqANXxo5Pi5zYLBsal2xY0pX+JZNbzYJY= -github.com/mattermost/mattermost/server/public v0.0.10-0.20231109142142-8ffda2b73ea8 h1:tZhcvX1k526YLHeO8lQpFa8J2Ejr7sHEYdzst5xrIjA= -github.com/mattermost/mattermost/server/public v0.0.10-0.20231109142142-8ffda2b73ea8/go.mod h1:AMuKlAabVFnLvf5bXg+69EdvtLIfty4ahFossB34LM4= -github.com/mattermost/mattermost/server/public v0.0.10-0.20231114142547-f0c94858133b h1:B2PNC1Mjq7LC2h2d0bkgo5pPZP3b7ik6U13LFsRXRi8= -github.com/mattermost/mattermost/server/public v0.0.10-0.20231114142547-f0c94858133b/go.mod h1:AMuKlAabVFnLvf5bXg+69EdvtLIfty4ahFossB34LM4= +github.com/mattermost/mattermost/server/public v0.0.11-0.20231114165607-9c6bfd527dee h1:1JNMIDcmGYHnRLgqzCGfxe/7nU5Lq5V0B0UU9A7Es9U= +github.com/mattermost/mattermost/server/public v0.0.11-0.20231114165607-9c6bfd527dee/go.mod h1:AMuKlAabVFnLvf5bXg+69EdvtLIfty4ahFossB34LM4= github.com/mattermost/rtcd v0.12.0 h1:T/07JYExpwMmWq58QIp8KU08FWOzVmmatzLaEOIMP4A= github.com/mattermost/rtcd v0.12.0/go.mod h1:s0J7u93n2e2YPATEWCiiJ19iQf2TTHJapXQR2POE8KA= github.com/mattermost/squirrel v0.2.0 h1:8ZWeyf+MWQ2cL7hu9REZgLtz2IJi51qqZEovI3T3TT8= From 3634a522f6ec38c44e14fad138128e8e566afc72 Mon Sep 17 00:00:00 2001 From: Christopher Poile Date: Tue, 14 Nov 2023 15:41:10 -0500 Subject: [PATCH 4/5] goodbye old friend --- server/utils.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/server/utils.go b/server/utils.go index 460795493..cde134a9f 100644 --- a/server/utils.go +++ b/server/utils.go @@ -195,11 +195,3 @@ func mapKeys[K comparable, V any](m map[K]V) []K { } return keys } - -// NewClient creates a SimpleClient intended for one-off requests, like getPushProxyVersion. -// If we end up needing something more long term, we should consider storing it. -func NewClient() *http.Client { - return &http.Client{ - Timeout: 10 * time.Second, - } -} From 4808ed38f2022ef0b70937b4fcc727c0a2a4711a Mon Sep 17 00:00:00 2001 From: Christopher Poile Date: Thu, 16 Nov 2023 07:44:20 -0500 Subject: [PATCH 5/5] update to master branch commit of mattermost server --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 7dd5887ad..b71331cd4 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/mattermost/calls-recorder v0.4.2 github.com/mattermost/logr/v2 v2.0.16 github.com/mattermost/mattermost-plugin-calls/server/public v0.0.1 - github.com/mattermost/mattermost/server/public v0.0.11-0.20231114165607-9c6bfd527dee + github.com/mattermost/mattermost/server/public v0.0.11-0.20231115180603-759bb70b2f44 github.com/mattermost/rtcd v0.12.0 github.com/mattermost/squirrel v0.2.0 github.com/pion/interceptor v0.1.25 diff --git a/go.sum b/go.sum index 2167629e2..2a423b94c 100644 --- a/go.sum +++ b/go.sum @@ -295,8 +295,8 @@ github.com/mattermost/ldap v3.0.4+incompatible h1:SOeNnz+JNR+foQ3yHkYqijb9MLPhXN github.com/mattermost/ldap v3.0.4+incompatible/go.mod h1:b4reDCcGpBxJ4WX0f224KFY+OR0npin7or7EFpeIko4= github.com/mattermost/logr/v2 v2.0.16 h1:jnePX4cPskC3WDFvUardh/xZfxNdsFXbEERJQ1kUEDE= github.com/mattermost/logr/v2 v2.0.16/go.mod h1:1dm/YhTpozsqANXxo5Pi5zYLBsal2xY0pX+JZNbzYJY= -github.com/mattermost/mattermost/server/public v0.0.11-0.20231114165607-9c6bfd527dee h1:1JNMIDcmGYHnRLgqzCGfxe/7nU5Lq5V0B0UU9A7Es9U= -github.com/mattermost/mattermost/server/public v0.0.11-0.20231114165607-9c6bfd527dee/go.mod h1:AMuKlAabVFnLvf5bXg+69EdvtLIfty4ahFossB34LM4= +github.com/mattermost/mattermost/server/public v0.0.11-0.20231115180603-759bb70b2f44 h1:aTq8Vvdme0N8G2ZYEbKNlEBuXDr8MACPUmImIieKELc= +github.com/mattermost/mattermost/server/public v0.0.11-0.20231115180603-759bb70b2f44/go.mod h1:AMuKlAabVFnLvf5bXg+69EdvtLIfty4ahFossB34LM4= github.com/mattermost/rtcd v0.12.0 h1:T/07JYExpwMmWq58QIp8KU08FWOzVmmatzLaEOIMP4A= github.com/mattermost/rtcd v0.12.0/go.mod h1:s0J7u93n2e2YPATEWCiiJ19iQf2TTHJapXQR2POE8KA= github.com/mattermost/squirrel v0.2.0 h1:8ZWeyf+MWQ2cL7hu9REZgLtz2IJi51qqZEovI3T3TT8=