Ignore ack and notification counts if notifications are blocked by the device (#27570)
* Ignore performance counts if notifications are blocked by the device * Change the endpoint to allow more information * Add tests and API description * Remove wrong test * Address feedback * Only update the cache when there is no error * Follow same casing as other props * use one single endpoint * Fix tests * Fix i18n --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b9debc75a0
Коммит
af503d9d45
@@ -1117,6 +1117,7 @@ type AppIface interface {
|
||||
SetChannels(ch *Channels)
|
||||
SetCustomStatus(c request.CTX, userID string, cs *model.CustomStatus) *model.AppError
|
||||
SetDefaultProfileImage(c request.CTX, user *model.User) *model.AppError
|
||||
SetExtraSessionProps(session *model.Session, newProps map[string]string) *model.AppError
|
||||
SetFileSearchableContent(rctx request.CTX, fileID string, data string) *model.AppError
|
||||
SetPhase2PermissionsMigrationStatus(isComplete bool) error
|
||||
SetPluginKey(pluginID string, key string, value []byte) *model.AppError
|
||||
|
||||
@@ -218,7 +218,10 @@ func (a *App) sendPushNotificationToAllSessions(rctx request.CTX, msg *model.Pus
|
||||
}
|
||||
|
||||
if msg.Type == model.PushTypeMessage {
|
||||
a.CountNotification(model.NotificationTypePush, tmpMessage.Platform)
|
||||
// If we are ignoring the ack, we don't count the send
|
||||
if session.Props[model.SessionPropDeviceNotificationDisabled] != "true" {
|
||||
a.CountNotification(model.NotificationTypePush, tmpMessage.Platform)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16673,6 +16673,28 @@ func (a *OpenTracingAppLayer) SetDefaultProfileImage(c request.CTX, user *model.
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SetExtraSessionProps(session *model.Session, newProps map[string]string) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SetExtraSessionProps")
|
||||
|
||||
a.ctx = newCtx
|
||||
a.app.Srv().Store().SetContext(newCtx)
|
||||
defer func() {
|
||||
a.app.Srv().Store().SetContext(origCtx)
|
||||
a.ctx = origCtx
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.SetExtraSessionProps(session, newProps)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SetFileSearchableContent(rctx request.CTX, fileID string, data string) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SetFileSearchableContent")
|
||||
|
||||
@@ -291,6 +291,29 @@ func (a *App) AttachDeviceId(sessionID string, deviceID string, expiresAt int64)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) SetExtraSessionProps(session *model.Session, newProps map[string]string) *model.AppError {
|
||||
changed := false
|
||||
for k, v := range newProps {
|
||||
if session.Props[k] == v {
|
||||
continue
|
||||
}
|
||||
|
||||
session.AddProp(k, v)
|
||||
changed = true
|
||||
}
|
||||
|
||||
if !changed {
|
||||
return nil
|
||||
}
|
||||
|
||||
err := a.Srv().Store().Session().UpdateProps(session)
|
||||
if err != nil {
|
||||
return model.NewAppError("SetExtraSessionProps", "app.session.set_extra_session_prop.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ExtendSessionExpiryIfNeeded extends Session.ExpiresAt based on session lengths in config.
|
||||
// A new ExpiresAt is only written if enough time has elapsed since last update.
|
||||
// Returns true only if the session was extended.
|
||||
|
||||
@@ -445,3 +445,48 @@ func TestSessionsLimit(t *testing.T) {
|
||||
require.Equal(t, sessions[i].Id, sess.Id)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetExtraSessionProps(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
r := &http.Request{}
|
||||
w := httptest.NewRecorder()
|
||||
session, _ := th.App.DoLogin(th.Context, w, r, th.BasicUser, "", false, false, false)
|
||||
|
||||
resetSession := func(session *model.Session) {
|
||||
session.AddProp("testProp", "")
|
||||
th.Server.Store().Session().UpdateProps(session)
|
||||
th.App.ClearSessionCacheForUser(session.UserId)
|
||||
}
|
||||
t.Run("do not update the session if there are no props", func(t *testing.T) {
|
||||
defer resetSession(session)
|
||||
th.App.SetExtraSessionProps(session, map[string]string{})
|
||||
updatedSession, _ := th.App.GetSession(session.Token)
|
||||
storeSession, _ := th.Server.Store().Session().Get(th.Context, session.Id)
|
||||
assert.Equal(t, session, updatedSession)
|
||||
assert.Equal(t, session, storeSession)
|
||||
})
|
||||
t.Run("update the session with the selected prop", func(t *testing.T) {
|
||||
defer resetSession(session)
|
||||
th.App.SetExtraSessionProps(session, map[string]string{"testProp": "true"})
|
||||
updatedSession, _ := th.App.GetSession(session.Token)
|
||||
storeSession, _ := th.Server.Store().Session().Get(th.Context, session.Id)
|
||||
assert.Equal(t, "true", updatedSession.Props["testProp"])
|
||||
assert.Equal(t, "true", storeSession.Props["testProp"])
|
||||
})
|
||||
t.Run("do not update the session if the prop is the same", func(t *testing.T) {
|
||||
defer resetSession(session)
|
||||
session.AddProp("testProp", "true")
|
||||
th.Server.Store().Session().UpdateProps(session)
|
||||
th.App.ClearSessionCacheForUser(session.UserId)
|
||||
|
||||
th.App.SetExtraSessionProps(session, map[string]string{"testProp": "true"})
|
||||
updatedSession, _ := th.App.GetSession(session.Token)
|
||||
storeSession, _ := th.Server.Store().Session().Get(th.Context, session.Id)
|
||||
assert.Equal(t, session, updatedSession)
|
||||
assert.Equal(t, session, storeSession)
|
||||
assert.Equal(t, "true", updatedSession.Props["testProp"])
|
||||
assert.Equal(t, "true", storeSession.Props["testProp"])
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user