golang-im聊天
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

54 lines
1.4 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. // AgreeAddFriend 同意添加好友
  19. func (*friendApp) AgreeAddFriend(ctx context.Context, userId, friendId int64, remarks string) error {
  20. return frienddomain.FriendService.AgreeAddFriend(ctx, userId, friendId, remarks)
  21. }
  22. // SetFriend 设置好友信息
  23. func (*friendApp) SetFriend(ctx context.Context, userId int64, req *pb.SetFriendReq) error {
  24. friend, err := frienddomain.FriendRepo.Get(userId, req.FriendId)
  25. if err != nil {
  26. return err
  27. }
  28. if friend == nil {
  29. return nil
  30. }
  31. friend.Remarks = req.Remarks
  32. friend.Extra = req.Extra
  33. friend.UpdateTime = time.Now()
  34. err = frienddomain.FriendRepo.Save(friend)
  35. if err != nil {
  36. return err
  37. }
  38. return nil
  39. }
  40. // SendToFriend 消息发送至好友
  41. func (*friendApp) SendToFriend(ctx context.Context, sender *pb.Sender, req *pb.SendMessageReq) (int64, error) {
  42. return frienddomain.FriendService.SendToFriend(ctx, sender, req)
  43. }