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:
25
internal/pkg/jpush/vendor/params.go
vendored
25
internal/pkg/jpush/vendor/params.go
vendored
@@ -120,32 +120,11 @@ func (f *Factory) Build(params MessageParams, cfg config.ChannelConfig) *PushPay
|
||||
if m == nil {
|
||||
continue
|
||||
}
|
||||
switch c.VendorName() {
|
||||
case "xiaomi":
|
||||
tpc.Xiaomi = m
|
||||
case "huawei":
|
||||
tpc.Huawei = m
|
||||
case "oppo":
|
||||
tpc.OPPO = m
|
||||
case "vivo":
|
||||
tpc.VIVO = m
|
||||
case "meizu":
|
||||
tpc.Meizu = m
|
||||
case "honor":
|
||||
tpc.Honor = m
|
||||
case "fcm":
|
||||
tpc.FCM = m
|
||||
}
|
||||
}
|
||||
|
||||
// 全部厂商字段为空则置 nil,避免序列化出空的 third_party_channel
|
||||
if tpc.Xiaomi == nil && tpc.Huawei == nil && tpc.OPPO == nil &&
|
||||
tpc.VIVO == nil && tpc.Meizu == nil && tpc.Honor == nil && tpc.FCM == nil {
|
||||
tpc = nil
|
||||
tpc.Set(c.VendorName(), m)
|
||||
}
|
||||
|
||||
return &PushPayload{
|
||||
Notification: notification,
|
||||
TPC: tpc,
|
||||
TPC: tpc.Normalize(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user