feed.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package client
  2. import (
  3. "context"
  4. artmdl "go-common/app/interface/openplatform/article/model"
  5. feedmdl "go-common/app/service/main/feed/model"
  6. "go-common/library/net/rpc"
  7. )
  8. const (
  9. _appFeed = "RPC.AppFeed"
  10. _webFeed = "RPC.WebFeed"
  11. _archiveFeed = "RPC.ArchiveFeed"
  12. _bangumiFeed = "RPC.BangumiFeed"
  13. _addArc = "RPC.AddArc"
  14. _delArc = "RPC.DelArc"
  15. _purgeFeedCache = "RPC.PurgeFeedCache"
  16. _fold = "RPC.Fold"
  17. _appUnreadCount = "RPC.AppUnreadCount"
  18. _webUnreadCount = "RPC.WebUnreadCount"
  19. _changeArcUpper = "RPC.ChangeArcUpper"
  20. _articleFeed = "RPC.ArticleFeed"
  21. _articleUnreadCount = "RPC.ArticleUnreadCount"
  22. )
  23. const (
  24. _appid = "community.service.feed"
  25. )
  26. var (
  27. _noArg = &struct{}{}
  28. )
  29. // Service struct info.
  30. type Service struct {
  31. client *rpc.Client2
  32. }
  33. // New new service instance and return.
  34. func New(c *rpc.ClientConfig) (s *Service) {
  35. s = &Service{}
  36. s.client = rpc.NewDiscoveryCli(_appid, c)
  37. return
  38. }
  39. // AppFeed receive ArgMid contains mid and real ip, then init app feed.
  40. func (s *Service) AppFeed(c context.Context, arg *feedmdl.ArgFeed) (res []*feedmdl.Feed, err error) {
  41. err = s.client.Call(c, _appFeed, arg, &res)
  42. return
  43. }
  44. // WebFeed receive ArgMid contains mid and real ip, then init web feed without fold.
  45. func (s *Service) WebFeed(c context.Context, arg *feedmdl.ArgFeed) (res []*feedmdl.Feed, err error) {
  46. err = s.client.Call(c, _webFeed, arg, &res)
  47. return
  48. }
  49. // ArchiveFeed receive ArgMid contains mid and real ip
  50. func (s *Service) ArchiveFeed(c context.Context, arg *feedmdl.ArgFeed) (res []*feedmdl.Feed, err error) {
  51. err = s.client.Call(c, _archiveFeed, arg, &res)
  52. return
  53. }
  54. // BangumiFeed receive ArgMid contains mid and real ip
  55. func (s *Service) BangumiFeed(c context.Context, arg *feedmdl.ArgFeed) (res []*feedmdl.Feed, err error) {
  56. err = s.client.Call(c, _bangumiFeed, arg, &res)
  57. return
  58. }
  59. // ArticleFeed receive ArgMid and return article feed.
  60. func (s *Service) ArticleFeed(c context.Context, arg *feedmdl.ArgFeed) (res []*artmdl.Meta, err error) {
  61. err = s.client.Call(c, _articleFeed, arg, &res)
  62. return
  63. }
  64. // ArticleUnreadCount return unread count of article feed.
  65. func (s *Service) ArticleUnreadCount(c context.Context, arg *feedmdl.ArgMid) (res int, err error) {
  66. err = s.client.Call(c, _articleUnreadCount, arg, &res)
  67. return
  68. }
  69. // AddArc add archive when archive passed. purge cache.
  70. func (s *Service) AddArc(c context.Context, arg *feedmdl.ArgArc) (err error) {
  71. err = s.client.Call(c, _addArc, arg, &struct{}{})
  72. return
  73. }
  74. // DelArc delete archive when archive not passed. purge cache.
  75. func (s *Service) DelArc(c context.Context, arg *feedmdl.ArgAidMid) (err error) {
  76. err = s.client.Call(c, _delArc, arg, &struct{}{})
  77. return
  78. }
  79. // PurgeFeedCache purge cache when attention/unattention upper
  80. func (s *Service) PurgeFeedCache(c context.Context, arg *feedmdl.ArgMid) (err error) {
  81. err = s.client.Call(c, _purgeFeedCache, arg, &struct{}{})
  82. return
  83. }
  84. // Fold receive ArgFold contains mid, then return upper's fold archives.
  85. func (s *Service) Fold(c context.Context, arg *feedmdl.ArgFold) (res []*feedmdl.Feed, err error) {
  86. err = s.client.Call(c, _fold, arg, &res)
  87. return
  88. }
  89. // AppUnreadCount receive ArgUnreadCount contains mid, and withoutBangumi then return unread count.
  90. func (s *Service) AppUnreadCount(c context.Context, arg *feedmdl.ArgUnreadCount) (res int, err error) {
  91. err = s.client.Call(c, _appUnreadCount, arg, &res)
  92. return
  93. }
  94. // WebUnreadCount receive ArgUnreadCount contains mid, then return unread count.
  95. func (s *Service) WebUnreadCount(c context.Context, arg *feedmdl.ArgMid) (res int, err error) {
  96. err = s.client.Call(c, _webUnreadCount, arg, &res)
  97. return
  98. }
  99. // ChangeArcUpper refresh feed cache when change archive's author
  100. func (s *Service) ChangeArcUpper(c context.Context, arg *feedmdl.ArgChangeUpper) (err error) {
  101. err = s.client.Call(c, _changeArcUpper, arg, &struct{}{})
  102. return
  103. }