golang-im聊天
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

friend_app.go 1.6 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. }