operate.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package feed
  2. import (
  3. "context"
  4. "go-common/app/interface/main/app-card/model"
  5. "go-common/app/interface/main/app-card/model/card/operate"
  6. )
  7. func (s *Service) convergeCard(c context.Context, limit int, ids ...int64) (cardm map[int64]*operate.Card, aids, roomIDs, metaIDs []int64) {
  8. if len(ids) == 0 {
  9. return
  10. }
  11. cardm = make(map[int64]*operate.Card, len(ids))
  12. for i, id := range ids {
  13. if o, ok := s.convergeCache[id]; ok {
  14. card := &operate.Card{}
  15. card.FromConverge(o)
  16. cardm[id] = card
  17. for _, item := range card.Items {
  18. switch item.Goto {
  19. case model.GotoAv:
  20. if item.ID != 0 {
  21. aids = append(aids, item.ID)
  22. }
  23. case model.GotoLive:
  24. if item.ID != 0 {
  25. roomIDs = append(roomIDs, item.ID)
  26. }
  27. case model.GotoArticle:
  28. if item.ID != 0 {
  29. metaIDs = append(metaIDs, item.ID)
  30. }
  31. }
  32. if i == limit-1 {
  33. break
  34. }
  35. }
  36. }
  37. }
  38. return
  39. }
  40. func (s *Service) downloadCard(c context.Context, ids ...int64) (cardm map[int64]*operate.Card) {
  41. if len(ids) == 0 {
  42. return
  43. }
  44. cardm = make(map[int64]*operate.Card, len(ids))
  45. for _, id := range ids {
  46. if o, ok := s.downloadCache[id]; ok {
  47. card := &operate.Card{}
  48. card.FromDownload(o)
  49. cardm[id] = card
  50. }
  51. }
  52. return
  53. }
  54. func (s *Service) subscribeCard(c context.Context, ids ...int64) (cardm map[int64]*operate.Card, upIDs, tids []int64) {
  55. if len(ids) == 0 {
  56. return
  57. }
  58. cardm = make(map[int64]*operate.Card, len(ids))
  59. for _, id := range ids {
  60. if o, ok := s.followCache[id]; ok {
  61. card := &operate.Card{}
  62. card.FromFollow(o)
  63. cardm[id] = card
  64. for _, item := range card.Items {
  65. switch item.Goto {
  66. case model.GotoMid:
  67. if item.ID != 0 {
  68. upIDs = append(upIDs, item.ID)
  69. }
  70. case model.GotoTag:
  71. if item.ID != 0 {
  72. tids = append(tids, item.ID)
  73. }
  74. }
  75. }
  76. }
  77. }
  78. return
  79. }
  80. func (s *Service) channelRcmdCard(c context.Context, ids ...int64) (cardm map[int64]*operate.Card, aids, tids []int64) {
  81. if len(ids) == 0 {
  82. return
  83. }
  84. cardm = make(map[int64]*operate.Card, len(ids))
  85. for _, id := range ids {
  86. if o, ok := s.followCache[id]; ok {
  87. card := &operate.Card{}
  88. card.FromFollow(o)
  89. cardm[id] = card
  90. switch card.Goto {
  91. case model.GotoAv:
  92. if card.ID != 0 {
  93. aids = append(aids, card.ID)
  94. }
  95. if card.Tid != 0 {
  96. tids = append(tids, card.Tid)
  97. }
  98. }
  99. }
  100. }
  101. return
  102. }
  103. func (s *Service) specialCard(c context.Context, ids ...int64) (cardm map[int64]*operate.Card) {
  104. if len(ids) == 0 {
  105. return
  106. }
  107. cardm = make(map[int64]*operate.Card, len(ids))
  108. for _, id := range ids {
  109. if o, ok := s.specialCache[id]; ok {
  110. card := &operate.Card{}
  111. card.FromSpecial(o)
  112. cardm[id] = card
  113. }
  114. }
  115. return
  116. }