feat(push): add JPush integration for offline message push
Add JPush (极光推送) integration to enable push notifications for offline users. This includes: - New jpush client package with API for batch push notifications - Configuration for jpush (enabled, app_key, master_secret, production mode) - Updated push service to send messages via JPush when users are offline - Added PushChatMessage method with do-not-disturb checking - Integrated push service with chat service to notify offline users of new messages - Updated deployment workflow with JPush and related environment variables
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package wire
|
||||
package wire
|
||||
|
||||
import (
|
||||
"with_you/internal/cache"
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"with_you/internal/pkg/crypto"
|
||||
"with_you/internal/pkg/email"
|
||||
"with_you/internal/pkg/hook"
|
||||
"with_you/internal/pkg/jpush"
|
||||
"with_you/internal/pkg/openai"
|
||||
"with_you/internal/pkg/redis"
|
||||
"with_you/internal/pkg/s3"
|
||||
@@ -53,6 +54,7 @@ var InfrastructureSet = wire.NewSet(
|
||||
ProvideTencentClient,
|
||||
ProvideEmailClient,
|
||||
ProvideS3Client,
|
||||
ProvideJPushClient,
|
||||
|
||||
// 消息加密器
|
||||
ProvideMessageEncryptor,
|
||||
@@ -193,6 +195,23 @@ func ProvideS3Client(cfg *config.Config) (*s3.Client, error) {
|
||||
return s3.New(&cfg.S3)
|
||||
}
|
||||
|
||||
// ProvideJPushClient 提供极光推送客户端
|
||||
func ProvideJPushClient(cfg *config.Config, logger *zap.Logger) *jpush.Client {
|
||||
if !cfg.JPush.Enabled {
|
||||
logger.Info("JPush is disabled")
|
||||
return nil
|
||||
}
|
||||
if cfg.JPush.AppKey == "" || cfg.JPush.MasterSecret == "" {
|
||||
logger.Warn("JPush is enabled but app_key or master_secret is not configured")
|
||||
return nil
|
||||
}
|
||||
client := jpush.NewClient(cfg.JPush.AppKey, cfg.JPush.MasterSecret, cfg.JPush.Production, logger)
|
||||
logger.Info("JPush client initialized",
|
||||
zap.Bool("production", cfg.JPush.Production),
|
||||
)
|
||||
return client
|
||||
}
|
||||
|
||||
// ProvideTransactionManager 提供事务管理器
|
||||
func ProvideTransactionManager(db *gorm.DB) repository.TransactionManager {
|
||||
return repository.NewTransactionManager(db)
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"with_you/internal/grpc/runner"
|
||||
"with_you/internal/pkg/email"
|
||||
"with_you/internal/pkg/hook"
|
||||
"with_you/internal/pkg/jpush"
|
||||
"with_you/internal/pkg/openai"
|
||||
"with_you/internal/pkg/redis"
|
||||
"with_you/internal/pkg/s3"
|
||||
@@ -105,8 +106,9 @@ func ProvidePushService(
|
||||
deviceTokenRepo repository.DeviceTokenRepository,
|
||||
messageRepo repository.MessageRepository,
|
||||
wsHub *ws.Hub,
|
||||
jpushClient *jpush.Client,
|
||||
) service.PushService {
|
||||
return service.NewPushService(pushRepo, deviceTokenRepo, messageRepo, wsHub)
|
||||
return service.NewPushService(pushRepo, deviceTokenRepo, messageRepo, wsHub, jpushClient)
|
||||
}
|
||||
|
||||
// ProvideSystemMessageService 提供系统消息服务
|
||||
@@ -206,8 +208,9 @@ func ProvideChatService(
|
||||
wsHub *ws.Hub,
|
||||
cacheBackend cache.Cache,
|
||||
uploadService *service.UploadService,
|
||||
pushService service.PushService,
|
||||
) service.ChatService {
|
||||
return service.NewChatService(messageRepo, userRepo, nil, wsHub, cacheBackend, uploadService)
|
||||
return service.NewChatService(messageRepo, userRepo, nil, wsHub, cacheBackend, uploadService, pushService)
|
||||
}
|
||||
|
||||
// ProvideScheduleService 提供日程服务
|
||||
|
||||
Reference in New Issue
Block a user