relation.go 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. package relation
  2. import (
  3. "context"
  4. "go-common/app/service/main/relation/model"
  5. "go-common/library/net/rpc"
  6. )
  7. const (
  8. // relation
  9. _relation = "RPC.Relation"
  10. _relations = "RPC.Relations"
  11. _stat = "RPC.Stat"
  12. _stats = "RPC.Stats"
  13. _followings = "RPC.Followings"
  14. _sameFollowings = "RPC.SameFollowings"
  15. _whispers = "RPC.Whispers"
  16. _blacks = "RPC.Blacks"
  17. _followers = "RPC.Followers"
  18. _addFollowing = "RPC.AddFollowing"
  19. _delFollowing = "RPC.DelFollowing"
  20. _addWhisper = "RPC.AddWhisper"
  21. _delWhisper = "RPC.DelWhisper"
  22. _addBlack = "RPC.AddBlack"
  23. _delBlack = "RPC.DelBlack"
  24. _delFollower = "RPC.DelFollower"
  25. // relation tag
  26. _tag = "RPC.Tag"
  27. _tags = "RPC.Tags"
  28. _userTag = "RPC.UserTag"
  29. _createTag = "RPC.CreateTag"
  30. _updateTag = "RPC.UpdateTag"
  31. _delTag = "RPC.DelTag"
  32. _tagsAddUsers = "RPC.TagsAddUsers"
  33. _tagsCopyUsers = "RPC.TagsCopyUsers"
  34. _tagsMoveUsers = "RPC.TagsMoveUsers"
  35. _AddSpecial = "RPC.AddSpecial"
  36. _DelSpecial = "RPC.DelSpecial"
  37. _Special = "RPC.Special"
  38. // prompt
  39. _prompt = "RPC.Prompt"
  40. _closePrompt = "RPC.ClosePrompt"
  41. // followers incr notify
  42. _FollowersUnread = "RPC.FollowersUnread"
  43. _FollowersUnreadCount = "RPC.FollowersUnreadCount"
  44. _ResetFollowersUnread = "RPC.ResetFollowersUnread"
  45. _ResetFollowersUnreadCount = "RPC.ResetFollowersUnreadCount"
  46. _DisableFollowerNotify = "RPC.DisableFollowerNotify"
  47. _EnableFollowerNotify = "RPC.EnableFollowerNotify"
  48. _FollowerNotifySetting = "RPC.FollowerNotifySetting"
  49. // achieve
  50. _AchieveGet = "RPC.AchieveGet"
  51. _Achieve = "RPC.Achieve"
  52. )
  53. var (
  54. _noRes = &struct{}{}
  55. )
  56. const (
  57. _appid = "account.service.relation"
  58. )
  59. // Service struct info.
  60. type Service struct {
  61. client *rpc.Client2
  62. }
  63. // New new service instance and return.
  64. func New(c *rpc.ClientConfig) (s *Service) {
  65. s = &Service{}
  66. s.client = rpc.NewDiscoveryCli(_appid, c)
  67. return
  68. }
  69. // Relation get relation info.
  70. func (s *Service) Relation(c context.Context, arg *model.ArgRelation) (res *model.Following, err error) {
  71. res = new(model.Following)
  72. err = s.client.Call(c, _relation, arg, res)
  73. return
  74. }
  75. // Relations get relation infos.
  76. func (s *Service) Relations(c context.Context, arg *model.ArgRelations) (res map[int64]*model.Following, err error) {
  77. err = s.client.Call(c, _relations, arg, &res)
  78. return
  79. }
  80. // Followings get followings infos.
  81. func (s *Service) Followings(c context.Context, arg *model.ArgMid) (res []*model.Following, err error) {
  82. err = s.client.Call(c, _followings, arg, &res)
  83. return
  84. }
  85. // Whispers get whispers infos.
  86. func (s *Service) Whispers(c context.Context, arg *model.ArgMid) (res []*model.Following, err error) {
  87. err = s.client.Call(c, _whispers, arg, &res)
  88. return
  89. }
  90. // Blacks get black list.
  91. func (s *Service) Blacks(c context.Context, arg *model.ArgMid) (res []*model.Following, err error) {
  92. err = s.client.Call(c, _blacks, arg, &res)
  93. return
  94. }
  95. // Followers get followers list.
  96. func (s *Service) Followers(c context.Context, arg *model.ArgMid) (res []*model.Following, err error) {
  97. err = s.client.Call(c, _followers, arg, &res)
  98. return
  99. }
  100. // Stat get user relation stat.
  101. func (s *Service) Stat(c context.Context, arg *model.ArgMid) (res *model.Stat, err error) {
  102. res = new(model.Stat)
  103. err = s.client.Call(c, _stat, arg, &res)
  104. return
  105. }
  106. // Stats get users relation stat.
  107. func (s *Service) Stats(c context.Context, arg *model.ArgMids) (res map[int64]*model.Stat, err error) {
  108. err = s.client.Call(c, _stats, arg, &res)
  109. return
  110. }
  111. // ModifyRelation modify user relation.
  112. func (s *Service) ModifyRelation(c context.Context, arg *model.ArgFollowing) (err error) {
  113. switch arg.Action {
  114. case model.ActAddBlack:
  115. err = s.client.Call(c, _addBlack, arg, _noRes)
  116. case model.ActAddFollowing:
  117. err = s.client.Call(c, _addFollowing, arg, _noRes)
  118. case model.ActAddWhisper:
  119. err = s.client.Call(c, _addWhisper, arg, _noRes)
  120. case model.ActDelBalck:
  121. err = s.client.Call(c, _delBlack, arg, _noRes)
  122. case model.ActDelFollower:
  123. err = s.client.Call(c, _delFollower, arg, _noRes)
  124. case model.ActDelFollowing:
  125. err = s.client.Call(c, _delFollowing, arg, _noRes)
  126. case model.ActDelWhisper:
  127. err = s.client.Call(c, _delWhisper, arg, _noRes)
  128. default:
  129. }
  130. return
  131. }
  132. // Tag tag
  133. func (s *Service) Tag(c context.Context, arg *model.ArgTagId) (res []int64, err error) {
  134. err = s.client.Call(c, _tag, arg, &res)
  135. return
  136. }
  137. // Tags tags
  138. func (s *Service) Tags(c context.Context, arg *model.ArgMid) (res []*model.TagCount, err error) {
  139. err = s.client.Call(c, _tags, arg, &res)
  140. return
  141. }
  142. // UserTag user tag
  143. func (s *Service) UserTag(c context.Context, arg *model.ArgRelation) (res map[int64]string, err error) {
  144. err = s.client.Call(c, _userTag, arg, &res)
  145. return
  146. }
  147. // CreateTag create tag
  148. func (s *Service) CreateTag(c context.Context, arg *model.ArgTag) (res int64, err error) {
  149. err = s.client.Call(c, _createTag, arg, &res)
  150. return
  151. }
  152. // UpdateTag update tag
  153. func (s *Service) UpdateTag(c context.Context, arg *model.ArgTagUpdate) (err error) {
  154. err = s.client.Call(c, _updateTag, arg, _noRes)
  155. return
  156. }
  157. // DelTag del tag
  158. func (s *Service) DelTag(c context.Context, arg *model.ArgTagDel) (err error) {
  159. err = s.client.Call(c, _delTag, arg, _noRes)
  160. return
  161. }
  162. // TagsAddUsers tags add users
  163. func (s *Service) TagsAddUsers(c context.Context, arg *model.ArgTagsMoveUsers) (err error) {
  164. err = s.client.Call(c, _tagsAddUsers, arg, _noRes)
  165. return
  166. }
  167. // TagsCopyUsers tags copy users
  168. func (s *Service) TagsCopyUsers(c context.Context, arg *model.ArgTagsMoveUsers) (err error) {
  169. err = s.client.Call(c, _tagsCopyUsers, arg, _noRes)
  170. return
  171. }
  172. // TagsMoveUsers tags move users
  173. func (s *Service) TagsMoveUsers(c context.Context, arg *model.ArgTagsMoveUsers) (err error) {
  174. err = s.client.Call(c, _tagsMoveUsers, arg, _noRes)
  175. return
  176. }
  177. // Prompt rpc rpompt client
  178. func (s *Service) Prompt(c context.Context, arg *model.ArgPrompt) (b bool, err error) {
  179. err = s.client.Call(c, _prompt, arg, &b)
  180. return
  181. }
  182. // ClosePrompt close prompt client.
  183. func (s *Service) ClosePrompt(c context.Context, arg *model.ArgPrompt) (err error) {
  184. err = s.client.Call(c, _closePrompt, arg, _noRes)
  185. return
  186. }
  187. // AddSpecial add specail.
  188. func (s *Service) AddSpecial(c context.Context, arg *model.ArgFollowing) (err error) {
  189. err = s.client.Call(c, _AddSpecial, arg, &_noRes)
  190. return
  191. }
  192. // DelSpecial del special.
  193. func (s *Service) DelSpecial(c context.Context, arg *model.ArgFollowing) (err error) {
  194. err = s.client.Call(c, _DelSpecial, arg, &_noRes)
  195. return
  196. }
  197. // Special get special.
  198. func (s *Service) Special(c context.Context, arg *model.ArgMid) (res []int64, err error) {
  199. err = s.client.Call(c, _Special, arg, &res)
  200. return
  201. }
  202. // FollowersUnread check unread status, for the 'show red point' function.
  203. func (s *Service) FollowersUnread(c context.Context, arg *model.ArgMid) (show bool, err error) {
  204. err = s.client.Call(c, _FollowersUnread, arg, &show)
  205. return
  206. }
  207. // FollowersUnreadCount unread count.
  208. func (s *Service) FollowersUnreadCount(c context.Context, arg *model.ArgMid) (count int64, err error) {
  209. err = s.client.Call(c, _FollowersUnreadCount, arg, &count)
  210. return
  211. }
  212. // AchieveGet is
  213. func (s *Service) AchieveGet(c context.Context, arg *model.ArgAchieveGet) (*model.AchieveGetReply, error) {
  214. reply := &model.AchieveGetReply{}
  215. err := s.client.Call(c, _AchieveGet, arg, &reply)
  216. return reply, err
  217. }
  218. // Achieve is
  219. func (s *Service) Achieve(c context.Context, arg *model.ArgAchieve) (*model.Achieve, error) {
  220. reply := &model.Achieve{}
  221. err := s.client.Call(c, _Achieve, arg, &reply)
  222. return reply, err
  223. }
  224. // ResetFollowersUnread is
  225. func (s *Service) ResetFollowersUnread(c context.Context, arg *model.ArgMid) (err error) {
  226. err = s.client.Call(c, _ResetFollowersUnread, arg, &_noRes)
  227. return
  228. }
  229. // ResetFollowersUnreadCount is
  230. func (s *Service) ResetFollowersUnreadCount(c context.Context, arg *model.ArgMid) (err error) {
  231. err = s.client.Call(c, _ResetFollowersUnreadCount, arg, &_noRes)
  232. return
  233. }
  234. // DisableFollowerNotify set followerNotify as disabled.
  235. func (s *Service) DisableFollowerNotify(c context.Context, arg *model.ArgMid) (err error) {
  236. err = s.client.Call(c, _DisableFollowerNotify, arg, &_noRes)
  237. return
  238. }
  239. // EnableFollowerNotify set followerNotify as disabled.
  240. func (s *Service) EnableFollowerNotify(c context.Context, arg *model.ArgMid) (err error) {
  241. err = s.client.Call(c, _EnableFollowerNotify, arg, &_noRes)
  242. return
  243. }
  244. // FollowerNotifySetting get followerNotify setting.
  245. func (s *Service) FollowerNotifySetting(c context.Context, arg *model.ArgMid) (followerNotify *model.FollowerNotifySetting, err error) {
  246. followerNotify = &model.FollowerNotifySetting{}
  247. err = s.client.Call(c, _FollowerNotifySetting, arg, followerNotify)
  248. return
  249. }
  250. // SameFollowings is
  251. func (s *Service) SameFollowings(c context.Context, arg *model.ArgSameFollowing) (res []*model.Following, err error) {
  252. err = s.client.Call(c, _sameFollowings, arg, &res)
  253. return
  254. }