Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

111 строки
3.8 KiB

  1. package app
  2. import (
  3. "context"
  4. "egg-im/internal/logic/domain/message/service"
  5. "egg-im/pkg/pb"
  6. "time"
  7. "google.golang.org/protobuf/proto"
  8. )
  9. type messageApp struct{}
  10. var MessageApp = new(messageApp)
  11. // SendToUser 发送消息给用户
  12. func (*messageApp) SendToUser(ctx context.Context, sender *pb.Sender, toUserId int64, req *pb.SendMessageReq) (int64, error) {
  13. return service.MessageService.SendToUser(ctx, sender, toUserId, req)
  14. }
  15. // RecallMessageSendToUser 撤回消息发送给用户
  16. func (*messageApp) RecallMessageSendToUser(ctx context.Context, sender *pb.Sender, toUserId int64, req *pb.RecallMessageReq, sendTime time.Time) (int64, error) {
  17. return service.MessageService.RecallMessageSendToUser(ctx, sender, toUserId, req, sendTime)
  18. }
  19. // SendRedPackageToUser 发送红包给用户
  20. func (*messageApp) SendRedPackageToUser(ctx context.Context, sender *pb.Sender, toUserId int64, req *pb.SendRedPacketReq) (int64, error) {
  21. return service.MessageService.SendRedPackageToUser(ctx, sender, toUserId, req)
  22. }
  23. // PushToUser 推送消息给用户
  24. func (*messageApp) PushToUser(ctx context.Context, userId int64, code pb.PushCode, message proto.Message, isPersist bool) error {
  25. return service.PushService.PushToUser(ctx, userId, code, message, isPersist)
  26. }
  27. // PushAll 全服推送
  28. func (*messageApp) PushAll(ctx context.Context, req *pb.PushAllReq) error {
  29. return service.PushService.PushAll(ctx, req)
  30. }
  31. // Sync 消息同步
  32. func (*messageApp) Sync(ctx context.Context, userId, seq int64) (*pb.SyncResp, error) {
  33. return service.MessageService.Sync(ctx, userId, seq)
  34. }
  35. // MessageAck 收到消息回执
  36. func (*messageApp) MessageAck(ctx context.Context, userId, deviceId, ack int64) error {
  37. return service.DeviceAckService.Update(ctx, userId, deviceId, ack)
  38. }
  39. // SendMessage 发送消息
  40. func (s *messageApp) SendMessage(ctx context.Context, sender *pb.Sender, req *pb.SendMessageReq) (int64, error) {
  41. // 如果发送者是用户,需要补充用户的信息
  42. service.MessageService.AddSenderInfo(sender)
  43. switch req.ReceiverType {
  44. // 消息接收者为用户
  45. case pb.ReceiverType_RT_USER:
  46. // 发送者为用户
  47. if sender.SenderType == pb.SenderType_ST_USER {
  48. return FriendApp.SendToFriend(ctx, sender, req)
  49. } else {
  50. return s.SendToUser(ctx, sender, req.ReceiverId, req)
  51. }
  52. // 消息接收者是群组
  53. case pb.ReceiverType_RT_GROUP:
  54. return GroupApp.SendMessage(ctx, sender, req)
  55. }
  56. return 0, nil
  57. }
  58. // RecallMessage 撤回消息
  59. func (s *messageApp) RecallMessage(ctx context.Context, sender *pb.Sender, req *pb.RecallMessageReq) (int64, error) {
  60. // 如果发送者是用户,需要补充用户的信息
  61. service.MessageService.AddSenderInfo(sender)
  62. switch req.ReceiverType {
  63. // 消息接收者为用户
  64. case pb.ReceiverType_RT_USER:
  65. // 发送者为用户
  66. if sender.SenderType == pb.SenderType_ST_USER {
  67. return FriendApp.RecallMessageSendToFriend(ctx, sender, req)
  68. } else {
  69. //return s.RecallMessageSendToUser(ctx, sender, req.ReceiverId, req, true)
  70. }
  71. // 消息接收者是群组
  72. case pb.ReceiverType_RT_GROUP:
  73. return GroupApp.RecallSendMessage(ctx, sender, req)
  74. }
  75. return 0, nil
  76. }
  77. // SendRedPackage 发送红包消息
  78. func (s *messageApp) SendRedPackage(ctx context.Context, sender *pb.Sender, req *pb.SendRedPacketReq) (int64, error) {
  79. // 如果发送者是用户,需要补充用户的信息
  80. service.MessageService.AddSenderInfo(sender)
  81. switch req.ReceiverType {
  82. // 消息接收者为用户
  83. case pb.ReceiverType_RT_USER:
  84. // 发送者为用户
  85. if sender.SenderType == pb.SenderType_ST_USER {
  86. return FriendApp.RedPackageMessageSendToFriend(ctx, sender, req)
  87. } else {
  88. return s.SendRedPackageToUser(ctx, sender, req.ReceiverId, req)
  89. }
  90. // 消息接收者是群组
  91. case pb.ReceiverType_RT_GROUP:
  92. return GroupApp.SendRedPackage(ctx, sender, req)
  93. }
  94. return 0, nil
  95. }