golang-im聊天
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

69 linhas
2.1 KiB

  1. package app
  2. import (
  3. "context"
  4. frienddomain "gim/internal/logic/domain/friend"
  5. "gim/pkg/pb"
  6. "time"
  7. )
  8. type friendApp struct{}
  9. var FriendApp = new(friendApp)
  10. // List 获取好友列表
  11. func (s *friendApp) List(ctx context.Context, userId int64) ([]*pb.Friend, error) {
  12. return frienddomain.FriendService.List(ctx, userId)
  13. }
  14. // AddFriend 添加好友
  15. func (*friendApp) AddFriend(ctx context.Context, userId, friendId int64, remarks, description string) error {
  16. return frienddomain.FriendService.AddFriend(ctx, userId, friendId, remarks, description)
  17. }
  18. // DeleteFriend 添加好友
  19. func (*friendApp) DeleteFriend(ctx context.Context, userId, friendId int64) error {
  20. return frienddomain.FriendService.DeleteFriend(ctx, userId, friendId)
  21. }
  22. // AgreeAddFriend 同意添加好友
  23. func (*friendApp) AgreeAddFriend(ctx context.Context, userId, friendId int64, remarks string) error {
  24. return frienddomain.FriendService.AgreeAddFriend(ctx, userId, friendId, remarks)
  25. }
  26. // SetFriend 设置好友信息
  27. func (*friendApp) SetFriend(ctx context.Context, userId int64, req *pb.SetFriendReq) error {
  28. friend, err := frienddomain.FriendRepo.Get(userId, req.FriendId)
  29. if err != nil {
  30. return err
  31. }
  32. if friend == nil {
  33. return nil
  34. }
  35. friend.Remarks = req.Remarks
  36. friend.Extra = req.Extra
  37. friend.UpdateTime = time.Now()
  38. err = frienddomain.FriendRepo.Save(friend)
  39. if err != nil {
  40. return err
  41. }
  42. return nil
  43. }
  44. // SendToFriend 消息发送至好友
  45. func (*friendApp) SendToFriend(ctx context.Context, sender *pb.Sender, req *pb.SendMessageReq) (int64, error) {
  46. return frienddomain.FriendService.SendToFriend(ctx, sender, req)
  47. }
  48. // RecallMessageSendToFriend 撤回消息发送至好友
  49. func (*friendApp) RecallMessageSendToFriend(ctx context.Context, sender *pb.Sender, req *pb.RecallMessageReq) (int64, error) {
  50. return frienddomain.FriendService.RecallMessageSendToFriend(ctx, sender, req)
  51. }
  52. // RedPackageMessageSendToFriend 红包发送至好友
  53. func (*friendApp) RedPackageMessageSendToFriend(ctx context.Context, sender *pb.Sender, req *pb.SendRedPacketReq) (int64, error) {
  54. return frienddomain.FriendService.RedPackageMessageSendToFriend(ctx, sender, req)
  55. }