refactor(jpush): move vendor field handling into ThirdPartyChannel struct
Move the vendor switch logic into the ThirdPartyChannel struct as Set/IsEmpty/Normalize methods to improve encapsulation and eliminate code duplication in the vendor params builder. Also simplify messageToParams to reuse buildMessagePayload results and remove unused notification_type extras from push notifications.
This commit is contained in:
@@ -617,17 +617,18 @@ func (s *pushServiceImpl) buildPayload(params vendor.MessageParams) *vendor.Push
|
||||
|
||||
// messageToParams 从 model.Message 提取厂商无关的统一参数
|
||||
// 用于 PushToUser / worker / retry 等通用路径
|
||||
// 复用 buildMessagePayload 的计算结果,避免重复解析 message
|
||||
func (s *pushServiceImpl) messageToParams(message *model.Message) vendor.MessageParams {
|
||||
_ = message.Decrypt()
|
||||
payload := buildMessagePayload(message)
|
||||
scene := s.resolveChannelScene(message)
|
||||
|
||||
// senderName 复用 payload.Extras 中已提取的 actor_name,无需再次访问 ExtraData
|
||||
senderName := ""
|
||||
if message.ExtraData != nil {
|
||||
senderName = message.ExtraData.ActorName
|
||||
if name, ok := payload.Extras["actor_name"]; ok {
|
||||
if n, ok := name.(string); ok {
|
||||
senderName = n
|
||||
}
|
||||
}
|
||||
return vendor.MessageParams{
|
||||
Scene: scene,
|
||||
Scene: s.resolveChannelScene(message),
|
||||
Title: payload.Title,
|
||||
Body: payload.Content,
|
||||
SenderName: senderName,
|
||||
@@ -787,7 +788,6 @@ func (s *pushServiceImpl) PushChatMessage(ctx context.Context, userID string, co
|
||||
content = "[非文本消息]"
|
||||
}
|
||||
extras := map[string]any{
|
||||
"notification_type": "chat_message",
|
||||
"message_id": message.ID,
|
||||
"conversation_id": message.ConversationID,
|
||||
"conversation_type": string(convType),
|
||||
@@ -900,8 +900,7 @@ func (s *pushServiceImpl) PushSystemNotification(ctx context.Context, userID str
|
||||
title = string(notification.Type)
|
||||
}
|
||||
extras := map[string]any{
|
||||
"notification_id": fmt.Sprintf("%d", notification.ID),
|
||||
"notification_type": string(notification.Type),
|
||||
"notification_id": fmt.Sprintf("%d", notification.ID),
|
||||
}
|
||||
if notification.ExtraData != nil {
|
||||
extras["actor_id"] = notification.ExtraData.ActorIDStr
|
||||
|
||||
Reference in New Issue
Block a user