feat(push): add JPush integration for offline message push
Some checks failed
Build Backend / build-docker (push) Has been cancelled
Build Backend / build (push) Has been cancelled

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:
lafay
2026-04-27 23:20:24 +08:00
parent f03bbf6faa
commit fb85c9c20a
18 changed files with 919 additions and 66 deletions

View File

@@ -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
}