fix: accept jpush token metadata fields

This commit is contained in:
richjohnrambo
2026-09-14 17:34:12 +08:00
parent 2581d7b8f0
commit 02eddb6010
4 changed files with 47 additions and 27 deletions
+3
View File
@@ -1372,6 +1372,9 @@ func createIMUserProductTables(tx *sql.Tx) error {
token VARCHAR(512) NOT NULL,
app_version VARCHAR(64) NOT NULL DEFAULT '',
platform VARCHAR(32) NOT NULL DEFAULT '',
sdk_version VARCHAR(64) NOT NULL DEFAULT '',
push_env VARCHAR(32) NOT NULL DEFAULT '',
notification_permission VARCHAR(32) NOT NULL DEFAULT '',
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
PRIMARY KEY(id),
+9 -4
View File
@@ -6281,16 +6281,21 @@ func (a *adapter) TenantDevicePushTokenUpsert(id t.TenantID, token *t.DevicePush
token.Token = strings.TrimSpace(token.Token)
token.AppVersion = strings.TrimSpace(token.AppVersion)
token.Platform = strings.ToLower(strings.TrimSpace(token.Platform))
token.SDKVersion = strings.TrimSpace(token.SDKVersion)
token.PushEnv = strings.ToLower(strings.TrimSpace(token.PushEnv))
token.NotificationPermission = strings.ToLower(strings.TrimSpace(token.NotificationPermission))
tokenID, err := nextSnowflakeID()
if err != nil {
return nil, err
}
_, err = a.db.ExecContext(ctx,
`INSERT INTO im_device_push_tokens(id,device_id,user_id,provider,token,app_version,platform,created_at,updated_at)
VALUES(?,?,?,?,?,?,?,?,?)
`INSERT INTO im_device_push_tokens(id,device_id,user_id,provider,token,app_version,platform,sdk_version,push_env,notification_permission,created_at,updated_at)
VALUES(?,?,?,?,?,?,?,?,?,?,?,?)
ON DUPLICATE KEY UPDATE device_id=VALUES(device_id),user_id=VALUES(user_id),provider=VALUES(provider),token=VALUES(token),
app_version=VALUES(app_version),platform=VALUES(platform),updated_at=VALUES(updated_at)`,
tokenID, token.DeviceID, decodeUID(token.UserID), token.Provider, token.Token, token.AppVersion, token.Platform, now, now)
app_version=VALUES(app_version),platform=VALUES(platform),sdk_version=VALUES(sdk_version),push_env=VALUES(push_env),
notification_permission=VALUES(notification_permission),updated_at=VALUES(updated_at)`,
tokenID, token.DeviceID, decodeUID(token.UserID), token.Provider, token.Token, token.AppVersion, token.Platform,
token.SDKVersion, token.PushEnv, token.NotificationPermission, now, now)
if err != nil {
return nil, err
}
+24 -15
View File
@@ -319,10 +319,13 @@ type imYouthModeEnableRequest struct {
}
type imDevicePushTokenRequest struct {
Provider string `json:"provider"`
Token string `json:"token"`
AppVersion string `json:"app_version,omitempty"`
Platform string `json:"platform,omitempty"`
Provider string `json:"provider"`
Token string `json:"token"`
AppVersion string `json:"app_version,omitempty"`
Platform string `json:"platform,omitempty"`
SDKVersion string `json:"sdk_version,omitempty"`
PushEnv string `json:"push_env,omitempty"`
NotificationPermission string `json:"notification_permission,omitempty"`
}
type imP2PConversationRequest struct {
@@ -3356,12 +3359,15 @@ func serveIMDevicePushToken(wrt http.ResponseWriter, req *http.Request) {
return
}
token, err := store.DevicePushTokens.Upsert(principal.TenantID, &types.DevicePushToken{
UserID: principal.Uid,
DeviceID: deviceID,
Provider: body.Provider,
Token: body.Token,
AppVersion: body.AppVersion,
Platform: body.Platform,
UserID: principal.Uid,
DeviceID: deviceID,
Provider: body.Provider,
Token: body.Token,
AppVersion: body.AppVersion,
Platform: body.Platform,
SDKVersion: body.SDKVersion,
PushEnv: body.PushEnv,
NotificationPermission: body.NotificationPermission,
})
if err != nil {
writeIMRelationError(wrt, req, err)
@@ -9664,11 +9670,14 @@ func youthModeRestrictionItems(restrictions []string) []map[string]any {
func devicePushTokenPayload(token *types.DevicePushToken) map[string]any {
return map[string]any{
"device_id": token.DeviceID,
"provider": token.Provider,
"app_version": token.AppVersion,
"platform": token.Platform,
"updated_at": token.UpdatedAt.UTC().Format(time.RFC3339Nano),
"device_id": token.DeviceID,
"provider": token.Provider,
"app_version": token.AppVersion,
"platform": token.Platform,
"sdk_version": token.SDKVersion,
"push_env": token.PushEnv,
"notification_permission": token.NotificationPermission,
"updated_at": token.UpdatedAt.UTC().Format(time.RFC3339Nano),
}
}
+11 -8
View File
@@ -79,12 +79,15 @@ type YouthModeSettings struct {
}
type DevicePushToken struct {
UserID Uid
DeviceID string
Provider string
Token string
AppVersion string
Platform string
UpdatedAt time.Time
CreatedAt time.Time
UserID Uid
DeviceID string
Provider string
Token string
AppVersion string
Platform string
SDKVersion string
PushEnv string
NotificationPermission string
UpdatedAt time.Time
CreatedAt time.Time
}