MM-21898 - Part 1: Generate and use an interface instead of *A… (#13840)
* Generate and use an interface instead of *App
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
66fc096768
Коммит
17523fa5d9
@@ -9,19 +9,19 @@ import (
|
||||
)
|
||||
|
||||
func (a *App) AddStatusCacheSkipClusterSend(status *model.Status) {
|
||||
a.Srv.statusCache.Add(status.UserId, status)
|
||||
a.Srv().statusCache.Add(status.UserId, status)
|
||||
}
|
||||
|
||||
func (a *App) AddStatusCache(status *model.Status) {
|
||||
a.AddStatusCacheSkipClusterSend(status)
|
||||
|
||||
if a.Cluster != nil {
|
||||
if a.Cluster() != nil {
|
||||
msg := &model.ClusterMessage{
|
||||
Event: model.CLUSTER_EVENT_UPDATE_STATUS,
|
||||
SendType: model.CLUSTER_SEND_BEST_EFFORT,
|
||||
Data: status.ToClusterJson(),
|
||||
}
|
||||
a.Cluster.SendClusterMessage(msg)
|
||||
a.Cluster().SendClusterMessage(msg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ func (a *App) GetAllStatuses() map[string]*model.Status {
|
||||
return map[string]*model.Status{}
|
||||
}
|
||||
|
||||
userIds := a.Srv.statusCache.Keys()
|
||||
userIds := a.Srv().statusCache.Keys()
|
||||
statusMap := map[string]*model.Status{}
|
||||
|
||||
for _, userId := range userIds {
|
||||
@@ -49,11 +49,11 @@ func (a *App) GetStatusesByIds(userIds []string) (map[string]interface{}, *model
|
||||
}
|
||||
|
||||
statusMap := map[string]interface{}{}
|
||||
metrics := a.Metrics
|
||||
metrics := a.Metrics()
|
||||
|
||||
missingUserIds := []string{}
|
||||
for _, userId := range userIds {
|
||||
if result, ok := a.Srv.statusCache.Get(userId); ok {
|
||||
if result, ok := a.Srv().statusCache.Get(userId); ok {
|
||||
statusMap[userId] = result.(*model.Status).Status
|
||||
if metrics != nil {
|
||||
metrics.IncrementMemCacheHitCounter("Status")
|
||||
@@ -67,7 +67,7 @@ func (a *App) GetStatusesByIds(userIds []string) (map[string]interface{}, *model
|
||||
}
|
||||
|
||||
if len(missingUserIds) > 0 {
|
||||
statuses, err := a.Srv.Store.Status().GetByIds(missingUserIds)
|
||||
statuses, err := a.Srv().Store.Status().GetByIds(missingUserIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -96,11 +96,11 @@ func (a *App) GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.Ap
|
||||
}
|
||||
|
||||
var statusMap []*model.Status
|
||||
metrics := a.Metrics
|
||||
metrics := a.Metrics()
|
||||
|
||||
missingUserIds := []string{}
|
||||
for _, userId := range userIds {
|
||||
if result, ok := a.Srv.statusCache.Get(userId); ok {
|
||||
if result, ok := a.Srv().statusCache.Get(userId); ok {
|
||||
statusMap = append(statusMap, result.(*model.Status))
|
||||
if metrics != nil {
|
||||
metrics.IncrementMemCacheHitCounter("Status")
|
||||
@@ -114,7 +114,7 @@ func (a *App) GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.Ap
|
||||
}
|
||||
|
||||
if len(missingUserIds) > 0 {
|
||||
statuses, err := a.Srv.Store.Status().GetByIds(missingUserIds)
|
||||
statuses, err := a.Srv().Store.Status().GetByIds(missingUserIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -203,11 +203,11 @@ func (a *App) SetStatusOnline(userId string, manual bool) {
|
||||
// or enough time has passed since the previous action
|
||||
if status.Status != oldStatus || status.Manual != oldManual || status.LastActivityAt-oldTime > model.STATUS_MIN_UPDATE_TIME {
|
||||
if broadcast {
|
||||
if err := a.Srv.Store.Status().SaveOrUpdate(status); err != nil {
|
||||
if err := a.Srv().Store.Status().SaveOrUpdate(status); err != nil {
|
||||
mlog.Error("Failed to save status", mlog.String("user_id", userId), mlog.Err(err), mlog.String("user_id", userId))
|
||||
}
|
||||
} else {
|
||||
if err := a.Srv.Store.Status().UpdateLastActivityAt(status.UserId, status.LastActivityAt); err != nil {
|
||||
if err := a.Srv().Store.Status().UpdateLastActivityAt(status.UserId, status.LastActivityAt); err != nil {
|
||||
mlog.Error("Failed to save status", mlog.String("user_id", userId), mlog.Err(err), mlog.String("user_id", userId))
|
||||
}
|
||||
}
|
||||
@@ -219,7 +219,7 @@ func (a *App) SetStatusOnline(userId string, manual bool) {
|
||||
}
|
||||
|
||||
func (a *App) BroadcastStatus(status *model.Status) {
|
||||
if a.Srv.Busy.IsBusy() {
|
||||
if a.Srv().Busy.IsBusy() {
|
||||
// this is considered a non-critical service and will be disabled when server busy.
|
||||
return
|
||||
}
|
||||
@@ -296,7 +296,7 @@ func (a *App) SetStatusDoNotDisturb(userId string) {
|
||||
func (a *App) SaveAndBroadcastStatus(status *model.Status) {
|
||||
a.AddStatusCache(status)
|
||||
|
||||
if err := a.Srv.Store.Status().SaveOrUpdate(status); err != nil {
|
||||
if err := a.Srv().Store.Status().SaveOrUpdate(status); err != nil {
|
||||
mlog.Error("Failed to save status", mlog.String("user_id", status.UserId), mlog.Err(err))
|
||||
}
|
||||
|
||||
@@ -321,7 +321,7 @@ func (a *App) SetStatusOutOfOffice(userId string) {
|
||||
}
|
||||
|
||||
func (a *App) GetStatusFromCache(userId string) *model.Status {
|
||||
if result, ok := a.Srv.statusCache.Get(userId); ok {
|
||||
if result, ok := a.Srv().statusCache.Get(userId); ok {
|
||||
status := result.(*model.Status)
|
||||
statusCopy := &model.Status{}
|
||||
*statusCopy = *status
|
||||
@@ -341,7 +341,7 @@ func (a *App) GetStatus(userId string) (*model.Status, *model.AppError) {
|
||||
return status, nil
|
||||
}
|
||||
|
||||
return a.Srv.Store.Status().Get(userId)
|
||||
return a.Srv().Store.Status().Get(userId)
|
||||
}
|
||||
|
||||
func (a *App) IsUserAway(lastActivityAt int64) bool {
|
||||
|
||||
Ссылка в новой задаче
Block a user