thumbup.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/interface/main/dm2/model"
  5. account "go-common/app/service/main/account/api"
  6. thumbUpApi "go-common/app/service/main/thumbup/api"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. "go-common/library/net/metadata"
  10. )
  11. // ThumbupDM like or cancel like a dm
  12. func (s *Service) ThumbupDM(c context.Context, oid, dmid, mid int64, op int8) (err error) {
  13. if !model.CheckThumbup(op) {
  14. err = ecode.RequestErr
  15. return
  16. }
  17. // check dm state
  18. idxMap, _, err := s.dao.IndexsByid(c, model.SubTypeVideo, oid, []int64{dmid})
  19. if err != nil {
  20. log.Error("s.dao.IndexsByid(tp:%d,oid:%d,dmid:%d), error(%v)", 1, oid, dmid, err)
  21. return
  22. }
  23. if len(idxMap) <= 0 || !model.IsDMVisible(idxMap[dmid].State) {
  24. err = ecode.DMNotFound
  25. return
  26. }
  27. reply, err := s.accountRPC.Profile3(c, &account.MidReq{
  28. Mid: mid,
  29. })
  30. if err != nil {
  31. log.Error("s.accountRPC.Profile3(arg:%+v), error(%v)", mid, err)
  32. return
  33. }
  34. if reply.GetProfile().GetEmailStatus() == 0 && reply.GetProfile().GetTelStatus() == 0 {
  35. err = ecode.UserCheckNoPhone
  36. return
  37. }
  38. if reply.GetProfile().GetSilence() == 1 {
  39. err = ecode.DMActSilence
  40. return
  41. }
  42. sub, err := s.subject(c, model.SubTypeVideo, oid)
  43. if err != nil {
  44. return
  45. }
  46. arg2 := &thumbUpApi.LikeReq{
  47. Mid: mid,
  48. UpMid: sub.Mid,
  49. Business: "danmu",
  50. OriginID: oid,
  51. MessageID: dmid,
  52. Action: thumbUpApi.Action(op),
  53. }
  54. _, err = s.thumbupRPC.Like(c, arg2)
  55. if err != nil {
  56. log.Error("dmAct s.thumbupRPC.Like(arg:%+v), error(%v)", arg2, err)
  57. return
  58. }
  59. return
  60. }
  61. // ThumbupList get list
  62. func (s *Service) ThumbupList(c context.Context, oid, mid int64, dmids []int64) (res map[int64]*model.ThumbupStat, err error) {
  63. var (
  64. statsReply *thumbUpApi.StatsReply
  65. )
  66. if statsReply, err = s.thumbupRPC.Stats(c, &thumbUpApi.StatsReq{
  67. Business: "danmu",
  68. OriginID: oid,
  69. MessageIds: dmids,
  70. Mid: mid,
  71. IP: metadata.String(c, metadata.RemoteIP),
  72. }); err != nil {
  73. log.Error("dmAct s.thumbupRPC.StatsWithLike(oid:%+v,dmids:%+v), error(%v)", oid, dmids, err)
  74. return
  75. }
  76. res = make(map[int64]*model.ThumbupStat)
  77. if statsReply == nil {
  78. return
  79. }
  80. for id, li := range statsReply.Stats {
  81. st := new(model.ThumbupStat)
  82. st.Likes = li.LikeNumber
  83. st.UserLike = int8(li.LikeState)
  84. res[id] = st
  85. }
  86. return
  87. }