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:
@@ -78,6 +78,42 @@ type ThirdPartyChannel struct {
|
||||
Honor map[string]any `json:"honor,omitempty"`
|
||||
}
|
||||
|
||||
// Set 按厂商标识写入对应厂商的私有字段
|
||||
// vendor 对应 third_party_channel 的 key(xiaomi/huawei/oppo/vivo/meizu/fcm/honor)
|
||||
// 未知厂商将被忽略
|
||||
func (t *ThirdPartyChannel) Set(vendor string, m map[string]any) {
|
||||
switch vendor {
|
||||
case "xiaomi":
|
||||
t.Xiaomi = m
|
||||
case "huawei":
|
||||
t.Huawei = m
|
||||
case "oppo":
|
||||
t.OPPO = m
|
||||
case "vivo":
|
||||
t.VIVO = m
|
||||
case "meizu":
|
||||
t.Meizu = m
|
||||
case "fcm":
|
||||
t.FCM = m
|
||||
case "honor":
|
||||
t.Honor = m
|
||||
}
|
||||
}
|
||||
|
||||
// IsEmpty 判断是否所有厂商字段均为空
|
||||
func (t *ThirdPartyChannel) IsEmpty() bool {
|
||||
return t.Xiaomi == nil && t.Huawei == nil && t.OPPO == nil &&
|
||||
t.VIVO == nil && t.Meizu == nil && t.Honor == nil && t.FCM == nil
|
||||
}
|
||||
|
||||
// Normalize 当所有厂商字段为空时返回 nil,避免序列化出空的 third_party_channel 对象
|
||||
func (t *ThirdPartyChannel) Normalize() *ThirdPartyChannel {
|
||||
if t == nil || t.IsEmpty() {
|
||||
return nil
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
type AndroidNotif struct {
|
||||
Alert string `json:"alert"`
|
||||
Title string `json:"title,omitempty"`
|
||||
|
||||
Reference in New Issue
Block a user