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:
@@ -61,6 +61,7 @@ type chatServiceImpl struct {
|
||||
userRepo repository.UserRepository
|
||||
sensitive SensitiveService
|
||||
wsHub *ws.Hub
|
||||
pushSvc PushService
|
||||
|
||||
// 缓存相关字段
|
||||
conversationCache *cache.ConversationCache
|
||||
@@ -75,6 +76,7 @@ func NewChatService(
|
||||
wsHub *ws.Hub,
|
||||
cacheBackend cache.Cache,
|
||||
uploadService *UploadService,
|
||||
pushSvc PushService,
|
||||
) ChatService {
|
||||
// 创建适配器
|
||||
convRepoAdapter := cache.NewConversationRepositoryAdapter(repo)
|
||||
@@ -93,6 +95,7 @@ func NewChatService(
|
||||
userRepo: userRepo,
|
||||
sensitive: sensitive,
|
||||
wsHub: wsHub,
|
||||
pushSvc: pushSvc,
|
||||
conversationCache: conversationCache,
|
||||
uploadService: uploadService,
|
||||
}
|
||||
@@ -384,6 +387,34 @@ func (s *chatServiceImpl) SendMessage(ctx context.Context, senderID string, conv
|
||||
}
|
||||
}
|
||||
|
||||
// 对离线用户通过 JPush 推送聊天消息通知
|
||||
if s.pushSvc != nil && len(participants) > 0 {
|
||||
sender := ChatMessageSender{ID: senderID}
|
||||
if senderUser, sErr := s.userRepo.GetByID(senderID); sErr == nil {
|
||||
sender.Name = senderUser.Nickname
|
||||
sender.Avatar = senderUser.Avatar
|
||||
}
|
||||
convType := conv.Type
|
||||
convName := ""
|
||||
if conv.Type == model.ConversationTypeGroup && conv.Group != nil {
|
||||
convName = conv.Group.Name
|
||||
}
|
||||
for _, p := range participants {
|
||||
if p.UserID == senderID {
|
||||
continue
|
||||
}
|
||||
go func(userID string, sender ChatMessageSender) {
|
||||
if pushErr := s.pushSvc.PushChatMessage(context.Background(), userID, conversationID, &sender, convType, convName, message); pushErr != nil {
|
||||
zap.L().Debug("push chat message skipped or failed",
|
||||
zap.String("userID", userID),
|
||||
zap.String("conversationID", conversationID),
|
||||
zap.Error(pushErr),
|
||||
)
|
||||
}
|
||||
}(p.UserID, sender)
|
||||
}
|
||||
}
|
||||
|
||||
return message, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user