MM-14289 & MM-14884 Push notification acknowledge id and include sender name (#10736)

* MM-14289 Add Push notification acknowledge identifier and store tracing logs

* MM-14884 include SenderName property in Push Notifications

* Remove @ sign from channel Name in push notifications

* Fix i18n

* Fix push notification model

* fix TestPostNotificationGetChannelName

* Remove colon from model constant

* Fix Notification Registry tests

* Make postId optional for clear notifications

* Update http status when service is not available

Co-Authored-By: enahum <nahumhbl@gmail.com>
Этот коммит содержится в:
Elias Nahum
2019-04-30 18:15:29 -04:00
коммит произвёл GitHub
родитель e50b642e43
Коммит e6be06b3fc
18 изменённых файлов: 677 добавлений и 54 удалений

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

@@ -0,0 +1,81 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package sqlstore
import (
"net/http"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/store"
)
type SqlNotificationRegistryStore struct {
SqlStore
}
func NewSqlNotificationRegistryStore(sqlStore SqlStore) store.NotificationRegistryStore {
s := &SqlNotificationRegistryStore{sqlStore}
for _, db := range sqlStore.GetAllConns() {
table := db.AddTableWithName(model.NotificationRegistry{}, "NotificationRegistry").SetKeys(false, "AckId")
table.ColMap("AckId").SetMaxSize(26)
table.ColMap("UserId").SetMaxSize(26)
table.ColMap("PostId").SetMaxSize(26)
table.ColMap("DeviceId").SetMaxSize(512)
table.ColMap("Type").SetMaxSize(26)
table.ColMap("SendStatus").SetMaxSize(4096)
}
return s
}
func (s *SqlNotificationRegistryStore) CreateIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_notification_ack_id", "NotificationRegistry", "AckId")
s.CreateIndexIfNotExists("idx_notification_create_at", "NotificationRegistry", "CreateAt")
s.CreateIndexIfNotExists("idx_notification_receive_at", "NotificationRegistry", "ReceiveAt")
s.CreateIndexIfNotExists("idx_notification_post_id", "NotificationRegistry", "PostId")
s.CreateIndexIfNotExists("idx_notification_user_id", "NotificationRegistry", "UserId")
s.CreateIndexIfNotExists("idx_notification_type", "NotificationRegistry", "Type")
}
func (s *SqlNotificationRegistryStore) Save(notification *model.NotificationRegistry) (*model.NotificationRegistry, *model.AppError) {
notification.PreSave()
appErr := notification.IsValid()
if appErr != nil {
return nil, appErr
}
err := s.GetMaster().Insert(notification)
if err != nil {
appErr = model.NewAppError("SqlNotificationRegistryStore.Save", "store.sql_notification.save.app_error", nil, "id="+notification.AckId+", "+err.Error(), http.StatusInternalServerError)
return nil, appErr
}
return notification, nil
}
func (s *SqlNotificationRegistryStore) MarkAsReceived(ackId string, time int64) *model.AppError {
result, err := s.GetMaster().Exec("UPDATE NotificationRegistry SET ReceiveAt = :ReceiveAt WHERE AckId = :AckId AND ReceiveAt = 0", map[string]interface{}{"AckId": ackId, "ReceiveAt": time})
if err != nil {
return model.NewAppError("SqlNotificationRegistryStore.Save", "store.sql_notification.mark_as_received.app_error", nil, "id="+ackId+", "+err.Error(), http.StatusInternalServerError)
}
affected, err := result.RowsAffected()
if err != nil {
return model.NewAppError("SqlNotificationRegistryStore.Save", "store.sql_notification.mark_as_received.app_error", nil, "id="+ackId+", "+err.Error(), http.StatusInternalServerError)
} else if affected != 1 {
return model.NewAppError("SqlNotificationRegistryStore.Save", "store.sql_notification.mark_as_received.app_error", nil, "id="+ackId+", Message already received", http.StatusInternalServerError)
}
return nil
}
func (s *SqlNotificationRegistryStore) UpdateSendStatus(ackId, status string) *model.AppError {
_, err := s.GetMaster().Exec("UPDATE NotificationRegistry SET SendStatus = :Status WHERE AckId = :AckId", map[string]interface{}{"AckId": ackId, "Status": status})
if err != nil {
return model.NewAppError("SqlNotificationRegistryStore.Save", "store.sql_notification.update_status.app_error", nil, "id="+ackId+", "+err.Error(), http.StatusInternalServerError)
}
return nil
}

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

@@ -0,0 +1,14 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package sqlstore
import (
"testing"
"github.com/mattermost/mattermost-server/store/storetest"
)
func TestNotificationRegistryStore(t *testing.T) {
StoreTest(t, storetest.TestNotificationRegistryStore)
}

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

@@ -99,4 +99,5 @@ type SqlStore interface {
UserTermsOfService() store.UserTermsOfServiceStore
LinkMetadata() store.LinkMetadataStore
getQueryBuilder() sq.StatementBuilderType
NotificationRegistry() store.NotificationRegistryStore
}

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

@@ -99,6 +99,7 @@ type SqlSupplierOldStores struct {
group store.GroupStore
UserTermsOfService store.UserTermsOfServiceStore
linkMetadata store.LinkMetadataStore
notificationRegistry store.NotificationRegistryStore
}
type SqlSupplier struct {
@@ -151,6 +152,7 @@ func NewSqlSupplier(settings model.SqlSettings, metrics einterfaces.MetricsInter
supplier.oldStores.TermsOfService = NewSqlTermsOfServiceStore(supplier, metrics)
supplier.oldStores.UserTermsOfService = NewSqlUserTermsOfServiceStore(supplier)
supplier.oldStores.linkMetadata = NewSqlLinkMetadataStore(supplier)
supplier.oldStores.notificationRegistry = NewSqlNotificationRegistryStore(supplier)
initSqlSupplierReactions(supplier)
initSqlSupplierRoles(supplier)
@@ -1053,6 +1055,10 @@ func (ss *SqlSupplier) LinkMetadata() store.LinkMetadataStore {
return ss.oldStores.linkMetadata
}
func (ss *SqlSupplier) NotificationRegistry() store.NotificationRegistryStore {
return ss.oldStores.notificationRegistry
}
func (ss *SqlSupplier) DropAllTables() {
ss.master.TruncateTables()
}