Compare commits
2 Commits
51d818b10b
...
5c0228b186
Author | SHA1 | Date |
---|---|---|
|
5c0228b186 | |
|
7d6c85ad92 |
|
@ -393,3 +393,9 @@ const (
|
|||
ActivityBannerStatus_Expired = 2 // 已失效(外层封装逻辑)
|
||||
ActivityBannerStatus_Waiting = 3 // 待开始(外层封装逻辑)
|
||||
)
|
||||
|
||||
// 系统通知表是否有效
|
||||
const (
|
||||
NotifIsValid_Yes = 1
|
||||
NotifIsValid_No = 0
|
||||
)
|
||||
|
|
|
@ -2,7 +2,6 @@ package proto
|
|||
|
||||
import (
|
||||
"service/api/base"
|
||||
"service/dbstruct"
|
||||
)
|
||||
|
||||
// op 列表
|
||||
|
@ -14,9 +13,9 @@ type ApiListByMidReq struct {
|
|||
}
|
||||
|
||||
type ApiListByMidData struct {
|
||||
List []*dbstruct.Notification `json:"list"`
|
||||
Offset int `json:"offset"`
|
||||
More int `json:"more"`
|
||||
List []*NotificationApiVO `json:"list"`
|
||||
Offset int `json:"offset"`
|
||||
More int `json:"more"`
|
||||
}
|
||||
|
||||
type ApiListByMidResp struct {
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
package proto
|
||||
|
||||
import "service/dbstruct"
|
||||
|
||||
type NotificationUnreadApiVO struct {
|
||||
UnreadCnt int64 `json:"unread_cnt"`
|
||||
MostRecentNotif *dbstruct.Notification `json:"most_recent_notif"`
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package proto
|
||||
|
||||
import "service/dbstruct"
|
||||
|
||||
type NotificationApiVO struct {
|
||||
*dbstruct.Notification
|
||||
IsValid int64 `json:"is_valid"`
|
||||
}
|
||||
|
||||
func NewNotificationApiVO() *NotificationApiVO {
|
||||
return &NotificationApiVO{}
|
||||
}
|
||||
|
||||
func (vo *NotificationApiVO) CopyNotification(p *dbstruct.Notification) *NotificationApiVO {
|
||||
if vo == nil {
|
||||
return nil
|
||||
}
|
||||
vo.Notification = p
|
||||
return vo
|
||||
}
|
||||
|
||||
type NotificationUnreadApiVO struct {
|
||||
UnreadCnt int64 `json:"unread_cnt"`
|
||||
MostRecentNotif *dbstruct.Notification `json:"most_recent_notif"`
|
||||
}
|
|
@ -59,6 +59,7 @@ import (
|
|||
"service/library/mediafiller"
|
||||
"service/library/redis"
|
||||
interceptor "service/library/taginterceptor"
|
||||
"service/library/validator"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -435,10 +436,6 @@ func (s *Service) ApiUpdateAccount(ctx *gin.Context, req *accountproto.ApiUpdate
|
|||
// }
|
||||
//}
|
||||
|
||||
// 发送通知
|
||||
DefaultNotifBuilderHandler.Handle(ctx)(
|
||||
consts.AudNotifTemp_AvatarChangeApplied, consts.AudNotifTemp_NameChangeApplied)(req.Account)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -4605,9 +4602,11 @@ func (s *Service) ApiGetRavenIQTestList(ctx *gin.Context, req *Raven_IQ_testprot
|
|||
}
|
||||
|
||||
// Notification
|
||||
func (s *Service) ApiGetNotificationListByMid(ctx *gin.Context, req *notificationproto.ApiListByMidReq) (list []*dbstruct.Notification, ec errcode.ErrCode) {
|
||||
func (s *Service) ApiGetNotificationListByMid(ctx *gin.Context, req *notificationproto.ApiListByMidReq) (volist []*notificationproto.NotificationApiVO, ec errcode.ErrCode) {
|
||||
ec = errcode.ErrCodeNotificationSrvOk
|
||||
|
||||
volist = make([]*notificationproto.NotificationApiVO, 0)
|
||||
|
||||
// 查询得到已经拉取到的通知
|
||||
notifReceives, err := _DefaultNotifReceive.OpListByObjMid(ctx, ¬ificationproto.OpListNotifReceivesByMidReq{
|
||||
Uid: goproto.Int64(req.BaseRequest.Mid),
|
||||
|
@ -4626,12 +4625,33 @@ func (s *Service) ApiGetNotificationListByMid(ctx *gin.Context, req *notificatio
|
|||
}
|
||||
|
||||
// 获取通知信息
|
||||
list, err = _DefaultNotification.GetListByIds(ctx, nids)
|
||||
list, err := _DefaultNotification.GetListByIds(ctx, nids)
|
||||
if err != nil {
|
||||
logger.Error("GetListByIds fail, req: %v, err: %v", util.ToJson(req), err)
|
||||
ec = errcode.ErrCodeNotificationSrvFail
|
||||
return
|
||||
}
|
||||
|
||||
// 封装业务层信息
|
||||
for _, v := range list {
|
||||
vo := notificationproto.NewNotificationApiVO().CopyNotification(v)
|
||||
// 如果无需进行验证,则默认消息有效
|
||||
if len(v.ValidateParams) == 0 {
|
||||
vo.IsValid = consts.NotifIsValid_Yes
|
||||
} else { // 否则进行验证
|
||||
validatorId := v.ValidateParams[0].(int64)
|
||||
ok, err := validator.GetDefaultNotifValidator().Validate(validatorId, v.ValidateParams[1:]...)
|
||||
if err != nil {
|
||||
logger.Error("Notif validate fail, req: %v, err: %v", util.ToJson(req), err)
|
||||
}
|
||||
if ok {
|
||||
vo.IsValid = consts.NotifIsValid_Yes
|
||||
} else {
|
||||
vo.IsValid = consts.NotifIsValid_No
|
||||
}
|
||||
}
|
||||
volist = append(volist, vo)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"service/dbstruct"
|
||||
"service/library/logger"
|
||||
"service/library/mediafiller"
|
||||
"service/library/validator"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
goproto "google.golang.org/protobuf/proto"
|
||||
|
@ -577,6 +578,7 @@ func (handler *NotifBuilderHandler) handleAudMomentRejected() {
|
|||
argsMap["thumbnail"] = preview
|
||||
argsMap["build_hyperlink"] = DefaultService.utilBuildInwardHyperLink
|
||||
argsMap["hyperlink_params_map"] = util.NewHyperLinkParamsMapBuilder().NewEnds("app", "h5").WriteParamToAllEnd("id", moment.GetId()).Map()
|
||||
argsMap["validate_params"] = []any{validator.AudMoment, moment.GetId()}
|
||||
DefaultService.utilWriteNotifInfo(ctx, consts.AudNotifTemp_MomentRejected, moment.GetMid(), ctStr)
|
||||
}
|
||||
}
|
||||
|
@ -633,6 +635,7 @@ func (handler *NotifBuilderHandler) handleAudZoneMomentRejected() {
|
|||
argsMap["thumbnail"] = preview
|
||||
argsMap["build_hyperlink"] = DefaultService.utilBuildInwardHyperLink
|
||||
argsMap["hyperlink_params_map"] = util.NewHyperLinkParamsMapBuilder().NewEnds("app", "h5").WriteParamToAllEnd("id", zonemoment.GetId()).Map()
|
||||
argsMap["validate_params"] = []any{validator.AudZoneMoment, zonemoment.GetId()}
|
||||
|
||||
DefaultService.utilWriteNotifInfoByMap(ctx, consts.AudNotifTemp_ZoneMomentRejected, zonemoment.GetMid(), argsMap)
|
||||
}
|
||||
|
@ -690,6 +693,7 @@ func (handler *NotifBuilderHandler) handleAudZoneMomentReeditionRejected() {
|
|||
argsMap["thumbnail"] = preview
|
||||
argsMap["build_hyperlink"] = DefaultService.utilBuildInwardHyperLink
|
||||
argsMap["hyperlink_params_map"] = util.NewHyperLinkParamsMapBuilder().NewEnds("app", "h5").WriteParamToAllEnd("id", zonemoment.GetId()).Map()
|
||||
argsMap["validate_params"] = []any{validator.AudZoneMoment, zonemoment.GetId()}
|
||||
|
||||
DefaultService.utilWriteNotifInfoByMap(ctx, consts.AudNotifTemp_ZoneMomentReeditionRejected, zonemoment.GetMid(), argsMap)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"service/library/logger"
|
||||
"service/library/validator"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func (s *Service) InitDefaultNotifValidator() {
|
||||
validator.InitDefaultNotifValidator()
|
||||
ctx := &gin.Context{}
|
||||
|
||||
validator.GetDefaultNotifValidator().RegValidateFunc(validator.AudMoment, func(params ...any) (bool, error) {
|
||||
id := params[0].(int64)
|
||||
list, err := _DefaultMoment.GetByIds(ctx, []int64{id})
|
||||
if err != nil {
|
||||
logger.Error("_DefaultMoment GetByIds fail, id: %v, err: %v", id, err)
|
||||
return false, err
|
||||
}
|
||||
if len(list) == 0 {
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
|
||||
validator.GetDefaultNotifValidator().RegValidateFunc(validator.AudZoneMoment, func(params ...any) (bool, error) {
|
||||
id := params[0].(int64)
|
||||
zonemoment, err := _DefaultZoneMoment.GetById(ctx, id)
|
||||
if err != nil {
|
||||
logger.Error("_DefaultZoneMoment GetByIds fail, id: %v, err: %v", id, err)
|
||||
return false, err
|
||||
}
|
||||
if zonemoment == nil {
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
}
|
|
@ -309,6 +309,9 @@ func (s *Service) Init(c any) (err error) {
|
|||
_DefaultZoneDecrtByEs = logic.NewZoneDecrtByEs(_DefaultStreamerAcct, _DefaultZone)
|
||||
_DefaultVas.RegisterNotifBuilderHandler(DefaultNotifBuilderHandler)
|
||||
_DefaultShare = logic.NewShare(store)
|
||||
|
||||
s.InitDefaultNotifValidator()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2310,6 +2310,11 @@ func (s *Service) utilWriteNotifInfoByMap(ctx *gin.Context, notifTempId int64, o
|
|||
notifBuilder.HyperLinkParamsMap = hyperLinkParamsMap.(map[string]map[string]any)
|
||||
}
|
||||
|
||||
validateParams, ok := mp["validate_params"]
|
||||
if ok {
|
||||
notifBuilder.ValidateParams = validateParams.([]any)
|
||||
}
|
||||
|
||||
notifBuilders = append(notifBuilders, notifBuilder)
|
||||
ctx.Set("notif_builders", notifBuilders)
|
||||
}
|
||||
|
|
|
@ -7,22 +7,23 @@ import (
|
|||
)
|
||||
|
||||
type Notification struct {
|
||||
Id *int64 `json:"id" bson:"_id"` // 系统通知表id
|
||||
SubMid *int64 `json:"sub_mid" bson:"sub_mid"` // 通知发送人mid
|
||||
ObjType *int64 `json:"obj_type" bson:"obj_type"` // 通知接收人类型
|
||||
ObjMids []int64 `json:"obj_mids" bson:"obj_mids"` // 通知接收人mids
|
||||
NType *int64 `json:"n_type" bson:"n_type"` // 消息类型
|
||||
NDesc *string `json:"n_desc" bson:"n_desc"` // 消息描述
|
||||
Message *string `json:"message" bson:"message"` // 消息内容
|
||||
Title *string `json:"title" bson:"title"` // 主标题
|
||||
Thumbnail *MediaComponent `json:"thumbnail" bson:"thumbnail"` // 缩略图
|
||||
LinkText *string `json:"link_text" bson:"link_text"` // 链接文案
|
||||
HyperLinks []*NotifHyperlink `json:"hyperlinks" bson:"hyperlinks"` // 超链接数组
|
||||
PushTime *int64 `json:"push_time" bson:"push_time"` // 推送时间
|
||||
Status *int64 `json:"status" bson:"status"` // 推送状态
|
||||
Ct *int64 `json:"ct" bson:"ct"` // 创建时间
|
||||
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
|
||||
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记
|
||||
Id *int64 `json:"id" bson:"_id"` // 系统通知表id
|
||||
SubMid *int64 `json:"sub_mid" bson:"sub_mid"` // 通知发送人mid
|
||||
ObjType *int64 `json:"obj_type" bson:"obj_type"` // 通知接收人类型
|
||||
ObjMids []int64 `json:"obj_mids" bson:"obj_mids"` // 通知接收人mids
|
||||
NType *int64 `json:"n_type" bson:"n_type"` // 消息类型
|
||||
NDesc *string `json:"n_desc" bson:"n_desc"` // 消息描述
|
||||
Message *string `json:"message" bson:"message"` // 消息内容
|
||||
Title *string `json:"title" bson:"title"` // 主标题
|
||||
Thumbnail *MediaComponent `json:"thumbnail" bson:"thumbnail"` // 缩略图
|
||||
LinkText *string `json:"link_text" bson:"link_text"` // 链接文案
|
||||
HyperLinks []*NotifHyperlink `json:"hyperlinks" bson:"hyperlinks"` // 超链接数组
|
||||
ValidateParams []any `json:"validate_params" bson:"validate_params"` // 有效性验证参数
|
||||
PushTime *int64 `json:"push_time" bson:"push_time"` // 推送时间
|
||||
Status *int64 `json:"status" bson:"status"` // 推送状态
|
||||
Ct *int64 `json:"ct" bson:"ct"` // 创建时间
|
||||
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
|
||||
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记
|
||||
}
|
||||
|
||||
func (p *Notification) GetId() int64 {
|
||||
|
@ -152,6 +153,7 @@ type NotifBuilder struct {
|
|||
GetNid func() int64 // nid访问器
|
||||
BuildHyperLink func(ctx *gin.Context, frontendRouteId int64, argsMap map[string]map[string]any) ([]*NotifHyperlink, error) // 超链接组装函数
|
||||
HyperLinkParamsMap map[string]map[string]any // 超链接参数map
|
||||
ValidateParams []any // 有效性验证参数
|
||||
}
|
||||
|
||||
// 消息内超链接信息
|
||||
|
|
|
@ -204,6 +204,9 @@ func AssembleNotification(ctx *gin.Context, notifBuilder *dbstruct.NotifBuilder)
|
|||
}
|
||||
}
|
||||
|
||||
// 有效性验证参数
|
||||
notification.ValidateParams = notifBuilder.ValidateParams
|
||||
|
||||
// 推送时间
|
||||
notification.PushTime = goproto.Int64(notifBuilder.PushTime)
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package validator
|
||||
|
||||
var defaultNotifValidator *NotifValidator
|
||||
|
||||
type NotifValidateFunc func(...any) (bool, error)
|
||||
|
||||
type NotifValidator struct {
|
||||
validators map[int64]NotifValidateFunc
|
||||
}
|
||||
|
||||
func InitDefaultNotifValidator() {
|
||||
defaultNotifValidator = new(NotifValidator)
|
||||
defaultNotifValidator.init()
|
||||
}
|
||||
|
||||
func GetDefaultNotifValidator() *NotifValidator {
|
||||
return defaultNotifValidator
|
||||
}
|
||||
|
||||
func (p *NotifValidator) init() {
|
||||
p.validators = make(map[int64]NotifValidateFunc)
|
||||
}
|
||||
|
||||
func (p *NotifValidator) Validate(id int64, params ...any) (bool, error) {
|
||||
return p.validators[id](params...)
|
||||
}
|
||||
|
||||
func (p *NotifValidator) RegValidateFunc(id int64, fun NotifValidateFunc) {
|
||||
p.validators[id] = fun
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package validator
|
||||
|
||||
const (
|
||||
AudMoment = 0 // 广场动态审核
|
||||
AudZoneMoment = 1 // 空间动态审核
|
||||
)
|
Loading…
Reference in New Issue