MM-61947 Run DND expiry job more often and round expiry time to match interval (#29938)

* MM-61947 Run DND expiry job more often and round expiry time to match interval

* Move comment to make it godoc-compatible

* Change truncateDNDEndTime to work with seconds

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Harrison Healey
2025-02-25 16:20:00 -05:00
коммит произвёл GitHub
родитель e8ef26196c
Коммит 3902d00d0f
9 изменённых файлов: 55 добавлений и 13 удалений

Просмотреть файл

@@ -7,6 +7,7 @@ import (
"encoding/json"
"errors"
"net/http"
"time"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
@@ -417,7 +418,7 @@ func (ps *PlatformService) SetStatusDoNotDisturbTimed(userID string, endtime int
status.Status = model.StatusDnd
status.Manual = true
status.DNDEndTime = endtime
status.DNDEndTime = truncateDNDEndTime(endtime)
ps.SaveAndBroadcastStatus(status)
if ps.sharedChannelService != nil {
@@ -425,6 +426,19 @@ func (ps *PlatformService) SetStatusDoNotDisturbTimed(userID string, endtime int
}
}
// truncateDNDEndTime takes a user-provided timestamp (in seconds) for when their DND expiry should end and truncates
// it to line up with the DND expiry job so that the user's DND time doesn't expire late by an interval. The job to
// expire statuses runs every minute currently, so this trims the seconds and milliseconds off the given timestamp.
//
// This will result in statuses expiring slightly earlier than specified in the UI, but the status will expire at
// the correct time on the wall clock. For example, if the time is currently 13:04:29 and the user sets the expiry to
// 5 minutes, truncating will make the status will expire at 13:09:00 instead of at 13:10:00.
//
// Note that the timestamps used by this are in seconds, not milliseconds. This matches UserStatus.DNDEndTime.
func truncateDNDEndTime(endtime int64) int64 {
return time.Unix(endtime, 0).Truncate(model.DNDExpiryInterval).Unix()
}
func (ps *PlatformService) SetStatusDoNotDisturb(userID string) {
if !*ps.Config().ServiceSettings.EnableUserStatuses {
return

Просмотреть файл

@@ -6,6 +6,7 @@ package platform
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost/server/public/model"
@@ -37,3 +38,17 @@ func TestSaveStatus(t *testing.T) {
})
}
}
func TestTruncateDNDEndTime(t *testing.T) {
// 2025-Jan-20 at 17:13:32 GMT becomes 17:13:00
assert.Equal(t, int64(1737393180), truncateDNDEndTime(1737393212))
// 2025-Jan-20 at 17:13:00 GMT remains unchanged
assert.Equal(t, int64(1737393180), truncateDNDEndTime(1737393180))
// 2025-Jan-20 at 00:00:10 GMT becomes 00:00:00
assert.Equal(t, int64(1737331200), truncateDNDEndTime(1737331210))
// 2025-Jan-20 at 00:00:10 GMT remains unchanged
assert.Equal(t, int64(1737331200), truncateDNDEndTime(1737331200))
}