mattermost/server/channels/app/post_priority.go
Pablo Vélez 71780f4e0a
MM-66909 - Fix BoR sender not seeing priority label on new post (#34964)
* MM-66909 - Fix BoR sender not seeing priority label on new post

* Use RequestContextWithMaster for BoR priority fetching

* fix linter

* Add BoR post priority unit test

* unique error code and remove webapp workaround

* fix translation

* remove unnecessary line

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
2026-02-17 20:10:30 -05:00

57 lines
2 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
import (
"database/sql"
"errors"
"net/http"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/request"
)
func (a *App) GetPriorityForPost(postId string) (*model.PostPriority, *model.AppError) {
priority, err := a.Srv().Store().PostPriority().GetForPost(postId)
if err != nil && err != sql.ErrNoRows {
return nil, model.NewAppError("GetPriorityForPost", "app.post_prority.get_for_post.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
return priority, nil
}
func (a *App) GetPriorityForPostWithContext(rctx request.CTX, postId string) (*model.PostPriority, *model.AppError) {
priority, err := a.Srv().Store().PostPriority().GetForPostWithContext(rctx, postId)
if err != nil && err != sql.ErrNoRows {
return nil, model.NewAppError("GetPriorityForPostWithContext", "app.post_prority.get_for_post_with_context.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
return priority, nil
}
func (a *App) GetPriorityForPostList(list *model.PostList) (map[string]*model.PostPriority, *model.AppError) {
priority, err := a.Srv().Store().PostPriority().GetForPosts(list.Order)
if err != nil {
return nil, model.NewAppError("GetPriorityForPost", "app.post_prority.get_for_post.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
priorityMap := make(map[string]*model.PostPriority)
for _, p := range priority {
priorityMap[p.PostId] = p
}
return priorityMap, nil
}
func (a *App) IsPostPriorityEnabled() bool {
return *a.Config().ServiceSettings.PostPriority
}
func (a *App) DeletePriorityForPost(postId string) *model.AppError {
err := a.Srv().Store().PostPriority().Delete(postId)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
return model.NewAppError("DeletePriorityForPost", "app.post_priority.delete_for_post.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
return nil
}