Files
backend/internal/pkg/jpush/vendor/text_renderer.go
lafay a0e210feab
All checks were successful
Build Backend / build (push) Successful in 3m1s
Build Backend / build-docker (push) Successful in 2m10s
feat(server): implement chat file TTL cleanup and enhance JPush vendor channel support
Add FileCleanupWorker for automatic expiration of chat files with configurable retention period and batch processing. Files uploaded via `/api/v1/uploads/files` are tracked in `uploaded_files` table with expiration timestamps, then deleted from S3 and database upon expiry. Expired file URLs are injected as `"expired": true` in message responses.

Extend JPush push notification configuration with vendor-specific channel_id support (xiaomi, huawei, oppo, vivo, meizu, honor, fcm) for differentiating system vs chat notifications. Add iOS APNs thread-id grouping configuration for notification categorization.
2026-06-17 20:41:55 +08:00

62 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package vendor
import (
"with_you/internal/config"
"with_you/internal/pkg/jpush"
)
// defaultRenderer 默认通用文本渲染器
type defaultRenderer struct{}
func newDefaultRenderer() *defaultRenderer {
return &defaultRenderer{}
}
// mergeExtras 合并基础 extras 与额外 extras返回新 map
func mergeExtras(messageType string, extra map[string]any) map[string]any {
out := make(map[string]any, len(extra)+1)
if messageType != "" {
out["notification_type"] = messageType
}
for k, v := range extra {
out[k] = v
}
return out
}
// RenderAndroid 渲染 Android 通用通知
// 所有 Android 厂商共享alert/title/channel_id/extras/large_icon/priority
func (r *defaultRenderer) RenderAndroid(params MessageParams, cfg config.ChannelConfig) *jpush.AndroidNotif {
channelID := cfg.Chat
if params.Scene == SceneSystem {
channelID = cfg.System
}
return &jpush.AndroidNotif{
Alert: params.Body,
Title: params.Title,
ChannelID: channelID,
LargeIcon: params.LargeIcon,
Extras: mergeExtras(params.MessageType, params.Extra),
Priority: 1,
}
}
// RenderIOS 渲染 iOS 通用通知
// iOS 走 APNs通过 thread-id 实现按场景的通知分组
func (r *defaultRenderer) RenderIOS(params MessageParams, cfg config.ChannelConfig) *jpush.IOSNotif {
threadID := cfg.IOS.ChatThreadID
if params.Scene == SceneSystem {
threadID = cfg.IOS.SystemThreadID
}
return &jpush.IOSNotif{
Alert: map[string]any{
"title": params.Title,
"body": params.Body,
},
Sound: "default",
Badge: "+1",
ThreadID: threadID,
Extras: mergeExtras(params.MessageType, params.Extra),
}
}