feat: add tokenType and deviceId to push notification packet
Support FCM/VOIP_APNS token types and device identification for improved push notification routing.
This commit is contained in:
@@ -8,14 +8,24 @@ enum class PushNotificationAction(val value: Int) {
|
||||
UNSUBSCRIBE(1)
|
||||
}
|
||||
|
||||
/**
|
||||
* Token type for push notifications.
|
||||
*/
|
||||
enum class PushTokenType(val value: Int) {
|
||||
FCM(0),
|
||||
VOIP_APNS(1)
|
||||
}
|
||||
|
||||
/**
|
||||
* Push Notification packet (ID: 0x10)
|
||||
* Отправка FCM/APNS токена на сервер для push-уведомлений (новый формат)
|
||||
* Совместим с React Native версией
|
||||
* Отправка FCM/APNS токена на сервер для push-уведомлений
|
||||
* Передаёт tokenType (fcm/voip) и deviceId
|
||||
*/
|
||||
class PacketPushNotification : Packet() {
|
||||
var notificationsToken: String = ""
|
||||
var action: PushNotificationAction = PushNotificationAction.SUBSCRIBE
|
||||
var tokenType: PushTokenType = PushTokenType.FCM
|
||||
var deviceId: String = ""
|
||||
|
||||
override fun getPacketId(): Int = 0x10
|
||||
|
||||
@@ -25,6 +35,11 @@ class PacketPushNotification : Packet() {
|
||||
1 -> PushNotificationAction.UNSUBSCRIBE
|
||||
else -> PushNotificationAction.SUBSCRIBE
|
||||
}
|
||||
tokenType = when (stream.readInt8()) {
|
||||
1 -> PushTokenType.VOIP_APNS
|
||||
else -> PushTokenType.FCM
|
||||
}
|
||||
deviceId = stream.readString()
|
||||
}
|
||||
|
||||
override fun send(): Stream {
|
||||
@@ -32,6 +47,8 @@ class PacketPushNotification : Packet() {
|
||||
stream.writeInt16(getPacketId())
|
||||
stream.writeString(notificationsToken)
|
||||
stream.writeInt8(action.value)
|
||||
stream.writeInt8(tokenType.value)
|
||||
stream.writeString(deviceId)
|
||||
return stream
|
||||
}
|
||||
}
|
||||
|
||||
@@ -738,9 +738,12 @@ object ProtocolManager {
|
||||
return
|
||||
}
|
||||
|
||||
val deviceId = appContext?.let { getOrCreateDeviceId(it) } ?: ""
|
||||
val subPacket = PacketPushNotification().apply {
|
||||
notificationsToken = token
|
||||
action = PushNotificationAction.SUBSCRIBE
|
||||
tokenType = PushTokenType.FCM
|
||||
this.deviceId = deviceId
|
||||
}
|
||||
send(subPacket)
|
||||
lastSubscribedToken = token
|
||||
|
||||
Reference in New Issue
Block a user