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.
This commit is contained in:
61
internal/pkg/jpush/vendor/text_renderer.go
vendored
Normal file
61
internal/pkg/jpush/vendor/text_renderer.go
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
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),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user