fix: normalize jpush aliases

This commit is contained in:
richjohnrambo
2026-09-11 11:43:48 +08:00
parent 05f4087240
commit bafaf2d7b9
5 changed files with 32 additions and 8 deletions
+7 -1
View File
@@ -360,7 +360,7 @@ func preparePayloads(rcpt *push.Receipt, config *configType) ([]*jpushPayload, [
}
var audience map[string][]string
if useAlias {
audience = map[string][]string{"alias": {uid.UserId()}}
audience = map[string][]string{"alias": {aliasForUid(uid)}}
} else {
var registrationIDs []string
for _, device := range devices[uid] {
@@ -584,6 +584,12 @@ func containsString(values []string, target string) bool {
return false
}
func aliasForUid(uid t.Uid) string {
// JPush alias does not accept '-' or '_'. Tinode user IDs are base64url-like,
// so map them to legal characters which never appear in the original alphabet.
return strings.NewReplacer("-", ".", "_", "|").Replace(uid.UserId())
}
func providerDevicesForUsers(tenantID t.TenantID, provider string, uids ...t.Uid) (map[t.Uid][]t.DeviceDef, int, error) {
if tokens, ok := store.DevicePushTokens.(store.DevicePushTokenProviderQueryInterface); ok {
return tokens.GetAllByProvider(tenantID, provider, uids...)