golang-im聊天
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

business_ext.go 2.9 KiB

il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package api
  2. import (
  3. "context"
  4. "gim/internal/business/app"
  5. comm "gim/internal/business/comm"
  6. "gim/internal/business/comm/utils"
  7. "gim/internal/business/domain/user/repo"
  8. "gim/internal/logic/domain/message/service"
  9. "gim/pkg/grpclib"
  10. "gim/pkg/pb"
  11. "strconv"
  12. )
  13. type BusinessExtServer struct{}
  14. func (s *BusinessExtServer) EmoticonList(ctx context.Context, empty *pb.Empty) (*pb.EmoticonListResp, error) {
  15. masterId, err := grpclib.GetCtxMasterId(ctx)
  16. if err != nil {
  17. return nil, err
  18. }
  19. list, err := service.EmoticonList(masterId)
  20. if err != nil {
  21. return nil, err
  22. }
  23. return &pb.EmoticonListResp{Emoticons: list}, err
  24. }
  25. func (s *BusinessExtServer) SignIn(ctx context.Context, req *pb.SignInReq) (*pb.SignInResp, error) {
  26. isNew, userId, token, masterId, err := app.AuthApp.SignIn(ctx, req.PhoneNumber, req.Code, req.MasterId, req.DeviceId, req.PushAlia)
  27. if err != nil {
  28. return nil, err
  29. }
  30. return &pb.SignInResp{
  31. IsNew: isNew,
  32. UserId: userId,
  33. Token: token,
  34. MasterId: masterId,
  35. }, nil
  36. }
  37. func (s *BusinessExtServer) GetUser(ctx context.Context, req *pb.GetUserReq) (*pb.GetUserResp, error) {
  38. var user *pb.User
  39. var err error
  40. if req.Phone != "" {
  41. masterId, err := grpclib.GetCtxMasterId(ctx)
  42. if err != nil {
  43. return nil, err
  44. }
  45. useInfo, err := repo.UserRepo.GetByPhoneNumber(req.Phone, utils.StrToInt64(masterId))
  46. user = &pb.User{
  47. UserId: useInfo.Id,
  48. Nickname: user.Nickname,
  49. Sex: user.Sex,
  50. AvatarUrl: user.AvatarUrl,
  51. CreateTime: user.CreateTime,
  52. UpdateTime: user.UpdateTime,
  53. MasterId: user.MasterId,
  54. IsAutoAddedFriends: user.IsAutoAddedFriends,
  55. }
  56. } else {
  57. userId, _, err := grpclib.GetCtxData(ctx)
  58. if err != nil {
  59. return nil, err
  60. }
  61. if req.UserId != 0 {
  62. userId = req.UserId
  63. }
  64. user, err = app.UserApp.Get(ctx, userId)
  65. }
  66. return &pb.GetUserResp{User: user}, err
  67. }
  68. func (s *BusinessExtServer) UpdateUser(ctx context.Context, req *pb.UpdateUserReq) (*pb.Empty, error) {
  69. userId, _, err := grpclib.GetCtxData(ctx)
  70. if err != nil {
  71. return nil, err
  72. }
  73. return new(pb.Empty), app.UserApp.Update(ctx, userId, req)
  74. }
  75. func (s *BusinessExtServer) SearchUser(ctx context.Context, req *pb.SearchUserReq) (*pb.SearchUserResp, error) {
  76. users, err := app.UserApp.Search(ctx, req.Key, req.MasterId)
  77. return &pb.SearchUserResp{Users: users}, err
  78. }
  79. func (s *BusinessExtServer) CloudUploadFile(ctx context.Context, req *pb.CloudUploadFileReq) (*pb.CloudUploadFileResp, error) {
  80. userId, _, err := grpclib.GetCtxData(ctx)
  81. if err != nil {
  82. return nil, err
  83. }
  84. upload, err := comm.CloudUpload.FileReqUpload(ctx, strconv.FormatInt(userId, 10), req.Dir, req.FileName, utils.StrToInt64(req.FileSize))
  85. data := utils.SerializeStr(upload)
  86. var result map[string]string
  87. utils.Unserialize([]byte(data), &result)
  88. return &pb.CloudUploadFileResp{
  89. Method: result["method"],
  90. Host: result["host"],
  91. Key: result["key"],
  92. Token: result["token"],
  93. }, err
  94. }