FriendDataMgr.lua 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  1. local FriendDataMgr = class("FriendDataMgr",require("DataBase"))
  2. local FriendData = require("Friend/FriendData")
  3. local FriendRecruitData = require("Friend/FriendRecruitData")
  4. function FriendDataMgr:ctor()
  5. self.lastReqFriendListTime = 0
  6. self.lastReqFansListTime = 0
  7. self.lastReqBlackListTime = 0
  8. self.lastGetFriendRecommendTime = 0
  9. self.reqFriendListCDTime = 0
  10. self.reqFansListCDTime = 0
  11. self.reqBlackListCDTime = 0
  12. self.reqFriendRecommendCDTime = 1
  13. self.allInterestIds = nil --我关注的ID列表
  14. self.allFansIds = nil --我的粉丝的ID列表
  15. self.allBlackIds = nil --屏蔽名单的ID列表
  16. self.interestList = nil --我关注的列表
  17. self.fansList = nil --我的粉丝列表
  18. self.blackList = nil --屏蔽列表
  19. self.recommentList = {} --推荐列表
  20. self.maxFriendNum = 0 --我的关注数量上限
  21. self.maxFansNum = 0 --我的粉丝数量上限
  22. self.maxBlackNum = 0 --我的黑名单数量上限
  23. self.ExpeditionHelpList = nil --远征之门可求助列表(互相关注好友列表)
  24. self.AllExpeditionHelpIdList = nil
  25. self.totalFriendNum = 0
  26. self.totalFansNum = 0
  27. self.totalBlackNum = 0
  28. self.searchFriendPlayers = nil
  29. self.hasNewFans = false
  30. self.newFansIds = nil
  31. end
  32. function FriendDataMgr:Clear()
  33. self.allInterestIds = nil
  34. self.allFansIds = nil
  35. self.allBlackIds = nil
  36. self.interestList = nil
  37. self.fansList = nil
  38. self.blackList = nil
  39. self.ExpeditionHelpList = nil
  40. self.AllExpeditionHelpIdList = nil
  41. self.recommentList = {}
  42. self.searchFriendPlayers = nil
  43. self.hasNewFans = false
  44. self.newFansIds = nil
  45. if self.friendRecruitData then
  46. self.friendRecruitData:Clear()
  47. self.friendRecruitData = nil
  48. end
  49. end
  50. function FriendDataMgr:RegisterNetEvents()
  51. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_FRIEND_ACK,self.OnGetFriendListAck,self)
  52. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_GET_OTHER_PLAYER_BRIEF_INFO_ACK, self.OnGetFriendBriefInfoAck,self)
  53. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_FRIEND_RECOMMEND_ACK,self.OnGetFriendRecommendListAck,self)
  54. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_FRIEND_ADD_ACK,self.OnAddFriendAck,self)
  55. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_FRIEND_DEL_ACK,self.OnDeleteFriendAck,self)
  56. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_FRIEND_SEARCH_ACK,self.OnSearchFriendAck,self)
  57. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_FRIEND_BLACK_ACK,self.OnAddOrRemoveBlackAck,self)
  58. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_FRIEND_RECOMMEND_NTF,self.OnRecommendFriendNtf,self)
  59. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_FRIEND_ADD_NTF,self.OnAddFriendNtf,self)
  60. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_FRIEND_DEL_NTF,self.OnDeleteFriendNtf,self)
  61. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_INVITATION_STARTUP_NTF,self.InitInvitationData,self)
  62. if self.friendRecruitData then
  63. self.friendRecruitData:RegisterNetEvents()
  64. end
  65. end
  66. function FriendDataMgr:UnRegisterNetEvents()
  67. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_FRIEND_ACK)
  68. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_GET_OTHER_PLAYER_BRIEF_INFO_ACK)
  69. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_FRIEND_BLACK_ACK)
  70. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_FRIEND_RECOMMEND_ACK)
  71. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_FRIEND_ADD_ACK)
  72. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_FRIEND_DEL_ACK)
  73. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_FRIEND_SEARCH_ACK)
  74. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_FRIEND_ADD_NTF)
  75. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_FRIEND_DEL_NTF)
  76. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_INVITATION_STARTUP_NTF)
  77. if self.friendRecruitData then
  78. self.friendRecruitData:UnRegisterNetEvents()
  79. end
  80. end
  81. function FriendDataMgr:InitInterestData(data)
  82. self.totalFriendNum = data.total_count
  83. self.maxFriendNum = data.total_limit
  84. self.interestList = {}
  85. self.allInterestIds = {}
  86. if data.uid_list ~= nil then
  87. for i = 1,#data.uid_list do
  88. self.allInterestIds[#self.allInterestIds+1] = data.uid_list[i]
  89. end
  90. end
  91. end
  92. function FriendDataMgr:InitFansData(data)
  93. self.totalFansNum = data.total_count
  94. self.maxFansNum = data.total_limit
  95. self.fansList = {}
  96. self.allFansIds = {}
  97. if data.uid_list ~= nil then
  98. for i =1, #data.uid_list do
  99. self.allFansIds[#self.allFansIds+1] = data.uid_list[i]
  100. end
  101. end
  102. end
  103. function FriendDataMgr:InitBlackData(data)
  104. self.totalBlackNum = data.total_count
  105. self.maxBlackNum = data.total_limit
  106. self.blackList = {}
  107. self.allBlackIds = {}
  108. if data.uid_list ~= nil then
  109. for i = 1, #data.uid_list do
  110. self.allBlackIds[#self.allBlackIds+1] = data.uid_list[i]
  111. end
  112. end
  113. end
  114. function FriendDataMgr:RefreshInterestListData(briefListData)
  115. if briefListData == nil or #briefListData == 0 then return end
  116. for i = 1, #briefListData do
  117. self:AddInterestPlayer(briefListData[i])
  118. end
  119. -- self:SortInterestLit()
  120. end
  121. function FriendDataMgr:RefreshFansListData(briefListData)
  122. if briefListData == nil or #briefListData == 0 then
  123. return
  124. end
  125. for i = 1, #briefListData do
  126. self:AddFansPlayer(briefListData[i])
  127. end
  128. -- self:SortFansList()
  129. end
  130. function FriendDataMgr:RefreshBlackListData(briefListData)
  131. if briefListData == nil or #briefListData == 0 then return end
  132. for i = 1, #briefListData do
  133. self:AddBlackPlayer(briefListData[i])
  134. end
  135. -- self:SortBlackList()
  136. end
  137. function FriendDataMgr:GetDataListByType(type)
  138. if type == Enum.FriendTogglePageType.InterestList then
  139. return self.interestList
  140. elseif type == Enum.FriendTogglePageType.FansList then
  141. self:SetNewFansData(false)
  142. return self.fansList
  143. elseif type == Enum.FriendTogglePageType.BlackList then
  144. return self.blackList
  145. elseif type == Enum.FriendTogglePageType.FriendRecommend then
  146. return self.recommentList
  147. end
  148. return nil
  149. end
  150. function FriendDataMgr:GetUidListByType(type,cnt)
  151. local uids = {}
  152. if type == Enum.FriendTogglePageType.InterestList then
  153. if cnt > #self.allInterestIds then
  154. cnt = #self.allInterestIds
  155. end
  156. for i = 1, cnt do
  157. uids[#uids+1] = self.allInterestIds[i]
  158. end
  159. elseif type == Enum.FriendTogglePageType.FansList then
  160. if cnt > #self.allFansIds then
  161. cnt = #self.allFansIds
  162. end
  163. for i = 1, cnt do
  164. uids[#uids+1] = self.allFansIds[i]
  165. end
  166. elseif type == Enum.FriendTogglePageType.BlackList then
  167. if cnt > #self.allBlackIds then
  168. cnt = #self.allBlackIds
  169. end
  170. for i = 1, cnt do
  171. uids[#uids+1] = self.allBlackIds[i]
  172. end
  173. end
  174. return uids
  175. end
  176. function FriendDataMgr:GetInterestDataById(uid)
  177. if self.interestList then
  178. for i = 1, #self.interestList do
  179. local friend = self.interestList[i]
  180. if friend.uid == uid then
  181. return friend
  182. end
  183. end
  184. end
  185. return nil
  186. end
  187. function FriendDataMgr:GetFansDataById(uid)
  188. if self.fansList then
  189. for i = 1, #self.fansList do
  190. local fans = self.fansList[i]
  191. if fans.uid == uid then
  192. return fans
  193. end
  194. end
  195. end
  196. return nil
  197. end
  198. function FriendDataMgr:GetBlackDataById(uid)
  199. if self.blackList then
  200. for i = 1, #self.blackList do
  201. local black = self.blackList[i]
  202. if black.uid == uid then
  203. return black
  204. end
  205. end
  206. end
  207. return nil
  208. end
  209. function FriendDataMgr:GetStatus(uid)
  210. local state = 0
  211. if self:HasInterestPlayer(uid) then
  212. state = CommonUtil.Or(state,Enum.FriendStatusType.MyInterest)
  213. end
  214. if self:HasFansPlayer(uid) then
  215. state = CommonUtil.Or(state,Enum.FriendStatusType.MyFans)
  216. end
  217. return state
  218. end
  219. function FriendDataMgr:GetRecommendPlayerById(uid)
  220. if self.recommentList == nil then
  221. return nil
  222. end
  223. for i=1, #self.recommentList do
  224. if self.recommentList[i].uid == uid then
  225. return self.recommentList[i]
  226. end
  227. end
  228. return nil
  229. end
  230. function FriendDataMgr:GetSearchPlayerById(uid)
  231. if self.searchFriendPlayers == nil then
  232. return nil
  233. end
  234. for i=1, #self.searchFriendPlayers do
  235. if self.searchFriendPlayers[i].uid == uid then
  236. return self.searchFriendPlayers[i]
  237. end
  238. end
  239. return nil
  240. end
  241. function FriendDataMgr:AddInterestPlayer(briefInfo)
  242. if briefInfo == nil or self.interestList == nil then
  243. return
  244. end
  245. local obj = self:GetInterestDataById(briefInfo.uid)
  246. if obj ~= nil then
  247. obj:SetData(briefInfo)
  248. else
  249. obj = FriendData:new(briefInfo.uid)
  250. obj:SetData(briefInfo)
  251. self.interestList[#self.interestList+1] = obj
  252. end
  253. if self.AllExpeditionHelpIdList and self.ExpeditionHelpList then
  254. for i = 1, #self.AllExpeditionHelpIdList do
  255. if self.AllExpeditionHelpIdList[i] == obj.uid then
  256. table.remove(self.AllExpeditionHelpIdList, i)
  257. self.ExpeditionHelpList[#self.ExpeditionHelpList + 1] = obj
  258. break
  259. end
  260. end
  261. end
  262. self:RefreshPlayerStatus(briefInfo.uid)
  263. self:RemoveInterestId(briefInfo.uid)
  264. end
  265. function FriendDataMgr:AddFansPlayer(briefInfo)
  266. if briefInfo == nil or self.fansList == nil then
  267. return
  268. end
  269. local obj = self:GetFansDataById(briefInfo.uid)
  270. if obj ~= nil then
  271. obj:SetData(briefInfo)
  272. else
  273. obj = FriendData:new(briefInfo.uid)
  274. obj:SetData(briefInfo)
  275. if self:InRedPoint(briefInfo.uid) then
  276. obj:SetNewState(true)
  277. end
  278. self.fansList[#self.fansList+1] = obj
  279. end
  280. self:RefreshPlayerStatus(briefInfo.uid)
  281. self:RemoveFansId(briefInfo.uid)
  282. end
  283. function FriendDataMgr:AddBlackPlayer(briefInfo)
  284. if briefInfo == nil or self.blackList == nil then
  285. return
  286. end
  287. local obj = self:GetBlackDataById(briefInfo.uid)
  288. if obj ~= nil then
  289. obj:SetData(briefInfo)
  290. else
  291. obj = FriendData:new(briefInfo.uid)
  292. obj:SetData(briefInfo)
  293. self.blackList[#self.blackList+1] = obj
  294. end
  295. self:RefreshPlayerStatus(briefInfo.uid)
  296. self:RemoveBlackId(briefInfo.uid)
  297. end
  298. function FriendDataMgr:RemoveInterestById(uid)
  299. if not self.interestList then return end
  300. for i=1, #self.interestList do
  301. if self.interestList[i].uid == uid then
  302. table.remove(self.interestList, i)
  303. return
  304. end
  305. end
  306. end
  307. function FriendDataMgr:RemoveFansById(uid)
  308. if not self.fansList then return end
  309. for i = 1, #self.fansList do
  310. if self.fansList[i].uid == uid then
  311. table.remove(self.fansList,i)
  312. self.totalFansNum = self.totalFansNum - 1
  313. return
  314. end
  315. end
  316. end
  317. function FriendDataMgr:RemoveBlackById(uid)
  318. if not self.blackList then return end
  319. for i = 1, #self.blackList do
  320. if self.blackList[i].uid == uid then
  321. table.remove(self.blackList,i)
  322. self.totalBlackNum = self.totalBlackNum - 1
  323. return
  324. end
  325. end
  326. end
  327. function FriendDataMgr:RemoveRecommendById(uid)
  328. if self.recommentList == nil then
  329. return
  330. end
  331. for i = 1, #self.recommentList do
  332. if self.recommentList[i].uid == uid then
  333. table.remove(self.recommentList,i)
  334. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_FriendData,Enum.FriendTogglePageType.FriendRecommend)
  335. return
  336. end
  337. end
  338. end
  339. function FriendDataMgr:RemoveInterestId(uid)
  340. if not self.allInterestIds then return end
  341. for i = 1, #self.allInterestIds do
  342. if self.allInterestIds[i] == uid then
  343. table.remove(self.allInterestIds,i)
  344. return
  345. end
  346. end
  347. end
  348. function FriendDataMgr:RemoveFansId(uid)
  349. if not self.allFansIds then return end
  350. for i =1, #self.allFansIds do
  351. if self.allFansIds[i] == uid then
  352. table.remove(self.allFansIds,i)
  353. return
  354. end
  355. end
  356. end
  357. function FriendDataMgr:RemoveBlackId(uid)
  358. if not self.allBlackIds then return end
  359. for i=1, #self.allBlackIds do
  360. if self.allBlackIds[i] == uid then
  361. table.remove(self.allBlackIds,i)
  362. return
  363. end
  364. end
  365. end
  366. function FriendDataMgr:IsBlackPlayer(uid)
  367. if self.allBlackIds then
  368. for i = 1, #self.allBlackIds do
  369. if self.allBlackIds[i] == uid then
  370. return true
  371. end
  372. end
  373. end
  374. local data = self:GetBlackDataById(uid)
  375. if data ~= nil then
  376. return true
  377. end
  378. return false
  379. end
  380. function FriendDataMgr:HasInterestPlayer(uid)
  381. if self.allInterestIds then
  382. for i = 1, #self.allInterestIds do
  383. if self.allInterestIds[i] == uid then
  384. return true
  385. end
  386. end
  387. end
  388. local data = self:GetInterestDataById(uid)
  389. if data ~= nil then
  390. return true
  391. end
  392. return false
  393. end
  394. function FriendDataMgr:HasFansPlayer(uid)
  395. if self.allFansIds then
  396. for i =1, #self.allFansIds do
  397. if self.allFansIds[i] == uid then
  398. return true
  399. end
  400. end
  401. end
  402. local data = self:GetFansDataById(uid)
  403. if data ~= nil then
  404. return true
  405. end
  406. return false
  407. end
  408. function FriendDataMgr:HasBlackPlayer(uid)
  409. if self.allBlackIds then
  410. for i =1, #self.allBlackIds do
  411. if self.allBlackIds[i] == uid then
  412. return true
  413. end
  414. end
  415. end
  416. local data = self:GetBlackDataById(uid)
  417. if data ~= nil then
  418. return true
  419. end
  420. return false
  421. end
  422. function FriendDataMgr:GetSearchData()
  423. return self.searchFriendPlayers
  424. end
  425. function FriendDataMgr:SetExpedotopmHelpList(flag)
  426. if flag then
  427. self.ExpeditionHelpList = {};
  428. self.AllExpeditionHelpIdList = self:GetAllFriendIdList()
  429. else
  430. self.ExpeditionHelpList = nil;
  431. end
  432. end
  433. function FriendDataMgr:GetExpedotopmHelpList()
  434. return self.ExpeditionHelpList
  435. end
  436. function FriendDataMgr:GetAllExpedotopmHelpIDList()
  437. return self.AllExpeditionHelpIdList
  438. end
  439. function FriendDataMgr:RequestAllData()
  440. self:RequestDataList(Enum.FriendTogglePageType.InterestList)
  441. self:RequestDataList(Enum.FriendTogglePageType.FansList)
  442. self:RequestDataList(Enum.FriendTogglePageType.BlackList)
  443. end
  444. function FriendDataMgr:GetAllFriendIdList()
  445. local list = {}
  446. if self.interestList then
  447. for i = 1,#self.interestList do
  448. if self.interestList[i].status == 3 then
  449. list[#list+1] = self.interestList[i].uid
  450. end
  451. end
  452. end
  453. if self.allInterestIds then
  454. for i = 1, #self.allInterestIds do
  455. local bFans = self:HasFansPlayer(self.allInterestIds[i])
  456. if bFans then
  457. list[#list+1] = self.allInterestIds[i]
  458. end
  459. end
  460. end
  461. return list
  462. end
  463. function FriendDataMgr:GetFriendIdList()
  464. local idList = {}
  465. if self.allInterestIds then
  466. for i = 1, #self.allInterestIds do
  467. local bFans = self:HasFansPlayer(self.allInterestIds[i])
  468. if bFans then
  469. idList[#idList+1] = self.allInterestIds[i]
  470. end
  471. end
  472. end
  473. return idList
  474. end
  475. function FriendDataMgr:GetFriendDataList()
  476. local list = {}
  477. if self.interestList then
  478. for i = 1,#self.interestList do
  479. if self.interestList[i].status == 3 then
  480. list[#list+1] = self.interestList[i]
  481. end
  482. end
  483. end
  484. return list
  485. end
  486. -- type: FriendTogglePageType
  487. function FriendDataMgr:RequestDataList(reqType)
  488. if self:CanSendReq(reqType) then
  489. -- LogError("FriendDataMgr:RequestDataList:" .. reqType)
  490. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_FRIEND_REQ, {type = reqType})
  491. self:RecordReqTime(reqType)
  492. else
  493. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_FriendData,reqType)
  494. end
  495. end
  496. function FriendDataMgr:CanSendReq(reqType)
  497. local curTime = Time.realtimeSinceStartup
  498. if reqType == Enum.FriendTogglePageType.InterestList then
  499. return (curTime - self.lastReqFriendListTime) >= self.reqFriendListCDTime or self.lastReqFriendListTime == 0
  500. elseif reqType == Enum.FriendTogglePageType.FansList then
  501. return (curTime - self.lastReqFansListTime) >= self.reqFansListCDTime or self.lastReqFansListTime == 0
  502. elseif reqType == Enum.FriendTogglePageType.BlackList then
  503. return (curTime - self.lastReqBlackListTime) >= self.reqBlackListCDTime or self.lastReqBlackListTime == 0
  504. else
  505. return false
  506. end
  507. end
  508. function FriendDataMgr:RecordReqTime(reqType)
  509. local curTime = Time.realtimeSinceStartup
  510. if reqType == Enum.FriendTogglePageType.InterestList then
  511. self.lastReqFriendListTime = curTime
  512. elseif reqType == Enum.FriendTogglePageType.FansList then
  513. self.lastReqFriendListTime = curTime
  514. elseif reqType == Enum.FriendTogglePageType.BlackList then
  515. self.lastReqBlackListTime = curTime
  516. elseif reqType == Enum.FriendTogglePageType.FriendRecommend then
  517. self.lastGetFriendRecommendTime = curTime
  518. end
  519. end
  520. function FriendDataMgr:OnGetFriendListAck(data)
  521. -- LogError("OnGetFriendListAck : " .. Inspect(data))
  522. if data == nil then
  523. return
  524. end
  525. if data.type == Enum.FriendTogglePageType.InterestList then
  526. self:InitInterestData(data)
  527. elseif data.type == Enum.FriendTogglePageType.FansList then
  528. self:InitFansData(data)
  529. elseif data.type == Enum.FriendTogglePageType.BlackList then
  530. self:InitBlackData(data)
  531. end
  532. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Update_FriendDataList,data.type)
  533. end
  534. -- 获取好友简介信息
  535. function FriendDataMgr:ReqFriendBriefData(reqType,uids)
  536. if uids == nil or #uids == 0 then
  537. -- LogError("FriendDataMgr:ReqFriendBriefData:" .. reqType)
  538. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_FriendData,reqType)
  539. return
  540. end
  541. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_GET_OTHER_PLAYER_BRIEF_INFO_REQ, {type=reqType, player_list=uids})
  542. end
  543. -- message SCGetOtherPlayerBriefInfoAck {
  544. -- repeated CommonPlayerBriefInfo brief_info = 1;
  545. -- int32 type = 2;
  546. -- }
  547. function FriendDataMgr:OnGetFriendBriefInfoAck(data)
  548. if data.type == Enum.FriendTogglePageType.GuildPlayerBriefQuery then
  549. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.GUILD_GET_OTHER_PLAYER_BRIEF_INFO_ACK, data)
  550. return
  551. end
  552. if data.type == Enum.FriendTogglePageType.ClimbingTower then
  553. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_SC_GET_OTHER_PLAYER_BRIEF_INFO_ACK,data)
  554. return
  555. end
  556. if data.type == Enum.FriendTogglePageType.GuildDemonPlayerInfo or data.type == Enum.FriendTogglePageType.GuildDemonMvpInfo then
  557. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.GUILD_DEMON_GET_OTHER_PLAYER_BRIEF_INFO_ACK,data)
  558. return
  559. end
  560. if data.type == Enum.FriendTogglePageType.IdolRankInfo or data.type == Enum.FriendTogglePageType.IdolFansInfo or data.type == Enum.FriendTogglePageType.TempPlayerBirefInfos then
  561. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.IDOL_GET_OTHER_PLAYER_BRIEF_INFO_ACK,data)
  562. return
  563. end
  564. if data.type == Enum.FriendTogglePageType.ExpedtionHelpLog then
  565. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Expedition_GET_OTHER_PLAYER_BRIEF_INFO,data)
  566. return
  567. end
  568. if data.type == Enum.FriendTogglePageType.InterestList then
  569. self:RefreshInterestListData(data.brief_info)
  570. elseif data.type == Enum.FriendTogglePageType.FansList then
  571. self:RefreshFansListData(data.brief_info)
  572. elseif data.type == Enum.FriendTogglePageType.BlackList then
  573. self:RefreshBlackListData(data.brief_info)
  574. end
  575. if data.type >= Enum.FriendTogglePageType.InterestList and data.type <= Enum.FriendTogglePageType.BlackList then
  576. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_FriendData,data.type)
  577. elseif data.type == Enum.FriendTogglePageType.PrivateChatBriefQuery then
  578. if data.brief_info[1] then
  579. ManagerContainer.DataMgr.ChatData:RefreshChatTargetBriefInfo(data.brief_info)
  580. end
  581. elseif data.type == Enum.FriendTogglePageType.FriendInvitation then
  582. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.FRIEND_INVITATION_MASTER_INFO_REFRESH,data.brief_info[1])
  583. elseif data.type == Enum.FriendTogglePageType.InvitationStudentListQuery then
  584. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.FRIEND_INVITATION_QUERY_STUDENT_LIST_INFO,data.brief_info)
  585. elseif data.type == Enum.FriendTogglePageType.InvitationStudentSingleQuery then
  586. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.FRIEND_INVITATION_QUERY_STUDENT_SINGLE_INFO,data.brief_info[1])
  587. end
  588. end
  589. -- 获取推荐列表
  590. function FriendDataMgr:GetFriendRecommendReq()
  591. local curTime = Time.realtimeSinceStartup
  592. if ((curTime - self.lastGetFriendRecommendTime) >= self.reqFriendRecommendCDTime) or #self.recommentList == 0 then
  593. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_FRIEND_RECOMMEND_REQ, {})
  594. self.lastGetFriendRecommendTime = curTime
  595. else
  596. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(string.formatbykey("FrequentOperation"))
  597. end
  598. end
  599. function FriendDataMgr:OnGetFriendRecommendListAck(data)
  600. -- LogError("FriendDataMgr:OnGetFriendRecommendListAck:" .. Inspect(data))
  601. if data.error == Enum.NetErrorCode.ERROR_OK then
  602. if data.brief_info_list then
  603. self.recommentList = {}
  604. for i=1, #data.brief_info_list do
  605. local playerBriefInfo = data.brief_info_list[i]
  606. local obj = FriendData:new(playerBriefInfo.uid)
  607. obj:SetData(playerBriefInfo)
  608. self.recommentList[#self.recommentList+1] = obj
  609. obj:SetStatus(self:GetStatus(playerBriefInfo.uid))
  610. end
  611. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_FriendData,Enum.FriendTogglePageType.FriendRecommend)
  612. end
  613. else
  614. -- todo 提示error
  615. end
  616. end
  617. function FriendDataMgr:OnRecommendFriendNtf(data)
  618. if not data.brief_info_list then return end
  619. for i=1, #data.brief_info_list do
  620. local playerBriefInfo = data.brief_info_list[i]
  621. local obj = FriendData:new(playerBriefInfo.uid)
  622. obj:SetData(playerBriefInfo)
  623. self.recommentList[#self.recommentList+1] = obj
  624. obj:SetStatus(self:GetStatus(playerBriefInfo.uid))
  625. end
  626. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_FriendData,Enum.FriendTogglePageType.FriendRecommend)
  627. end
  628. -- 添加关注请求
  629. function FriendDataMgr:AddFriendReq(uid)
  630. if uid == 0 then
  631. return
  632. end
  633. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_FRIEND_ADD_REQ, {add_uid = uid})
  634. end
  635. function FriendDataMgr:OnAddFriendAck(data)
  636. -- LogError("FriendDataMgr:OnAddFriendAck:" .. Inspect(data))
  637. if data.error == Enum.NetErrorCode.ERROR_OK then
  638. self.totalFriendNum = self.totalFriendNum + 1
  639. self:AddInterestPlayer(data.brief_info)
  640. self:RemoveRecommendById(data.brief_info.uid)
  641. -- self:SortInterestLit()
  642. local player = self:GetFansDataById(data.brief_info.uid)
  643. if player~= nil then
  644. -- self:SortFansList()
  645. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_FriendData,Enum.FriendTogglePageType.FansList)
  646. end
  647. player = self:GetBlackDataById(data.brief_info.uid)
  648. if player ~= nil then
  649. -- self:SortBlackList()
  650. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_FriendData,Enum.FriendTogglePageType.BlackList)
  651. end
  652. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_FriendData,Enum.FriendTogglePageType.InterestList)
  653. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Show_SearchFriendData)
  654. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(string.formatbykey("FollowFriendsSuccess",CommonUtil.GetVaildNickName(data.brief_info.nick_name)))
  655. else
  656. -- ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("关注失败: " .. data.error)
  657. end
  658. end
  659. function FriendDataMgr:OnAddFriendNtf(nftData)
  660. -- LogError("OnAddFriendNtf: " .. Inspect(nftData))
  661. if not self.fansList then return end
  662. local briefInfo = nftData.brief_info
  663. local obj = self:GetFansDataById(briefInfo.uid)
  664. if obj ~= nil then
  665. obj:SetData(briefInfo)
  666. else
  667. obj = FriendData:new(briefInfo.uid)
  668. obj:SetData(briefInfo)
  669. obj:SetNewState(true)
  670. if self.newFansIds == nil then
  671. self.newFansIds = {}
  672. end
  673. self.newFansIds[#self.newFansIds+1] = briefInfo.uid
  674. self.fansList[#self.fansList+1] = obj
  675. end
  676. self:SetNewFansData(true)
  677. self:RefreshPlayerStatus(briefInfo.uid)
  678. -- self:SortFansList()
  679. local player = self:GetInterestDataById(nftData.brief_info.uid)
  680. if player~= nil then
  681. -- self:SortInterestLit()
  682. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_FriendData,Enum.FriendTogglePageType.InterestList)
  683. end
  684. player = self:GetBlackDataById(nftData.brief_info.uid)
  685. if player ~= nil then
  686. -- self:SortBlackList()
  687. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_FriendData,Enum.FriendTogglePageType.BlackList)
  688. end
  689. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_FriendData,Enum.FriendTogglePageType.FansList)
  690. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Show_SearchFriendData)
  691. end
  692. function FriendDataMgr:DeleteFriendReq(uid)
  693. if uid == 0 then
  694. return
  695. end
  696. -- LogError("DeleteFriendReq:" .. tostring(uid))
  697. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_FRIEND_DEL_REQ, {del_uid = uid})
  698. end
  699. function FriendDataMgr:OnDeleteFriendAck(data)
  700. -- LogError("FriendDataMgr:OnDeleteFriendAck:" .. Inspect(data))
  701. if data.error == Enum.NetErrorCode.ERROR_OK then
  702. self.totalFriendNum = self.totalFriendNum - 1
  703. self:RemoveInterestId(data.del_uid)
  704. self:RemoveInterestById(data.del_uid)
  705. self:RefreshPlayerStatus(data.del_uid)
  706. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(string.formatbykey("RemoveFollowConfirm"))
  707. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_FriendData,Enum.FriendTogglePageType.InterestList)
  708. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_FriendData,Enum.FriendTogglePageType.FansList)
  709. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Show_SearchFriendData)
  710. else
  711. -- ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("取关失败: " .. data.error)
  712. end
  713. end
  714. function FriendDataMgr:OnDeleteFriendNtf(ntfData)
  715. -- LogError("OnDeleteFriendNtf: " .. tostring(ntfData.del_uid))
  716. self:RemoveFansById(ntfData.del_uid)
  717. self:RemoveFansId(ntfData.del_uid)
  718. self:RefreshPlayerStatus(ntfData.del_uid)
  719. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_FriendData,Enum.FriendTogglePageType.InterestList)
  720. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_FriendData,Enum.FriendTogglePageType.FansList)
  721. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_FriendData,Enum.FriendTogglePageType.BlackList)
  722. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Show_SearchFriendData)
  723. end
  724. function FriendDataMgr:AddBlackReq(uid)
  725. if uid == 0 then
  726. return
  727. end
  728. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_FRIEND_BLACK_REQ, {black_uid = uid})
  729. end
  730. -- 移除屏蔽名单
  731. function FriendDataMgr:RemoveBlackReq(uid)
  732. if uid == 0 then
  733. return
  734. end
  735. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_FRIEND_BLACK_REQ, {black_uid = uid})
  736. end
  737. function FriendDataMgr:OnAddOrRemoveBlackAck(data)
  738. -- LogError("FriendDataMgr:OnAddOrRemoveBlackAck:" .. Inspect(data))
  739. if data.error == Enum.NetErrorCode.ERROR_OK then
  740. local info = data.brief_info
  741. local black = self:GetBlackDataById(info.uid)
  742. if black ~= nil then
  743. self:RemoveBlackById(info.uid)
  744. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(string.formatbykey("CancelBlacklistSuccess"))
  745. else
  746. self:AddBlackPlayer(info)
  747. -- self:SortBlackList()
  748. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(string.formatbykey("AddBlackListSuccess",CommonUtil.GetVaildNickName(info.nick_name)))
  749. end
  750. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_FriendData,Enum.FriendTogglePageType.BlackList)
  751. else
  752. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("移除黑名单失败!!" .. data.error)
  753. end
  754. end
  755. function FriendDataMgr:SearchFriendReq(userName)
  756. self.searchFriendPlayers = nil
  757. -- LogError("SearchFriendReq = " .. userName)
  758. if userName == "新玩家" then
  759. userName = ""
  760. end
  761. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_FRIEND_SEARCH_REQ, {target_name = userName})
  762. end
  763. function FriendDataMgr:OnSearchFriendAck(data)
  764. -- LogError("OnSearchFriendAck = " .. Inspect(data))
  765. if data.error == Enum.NetErrorCode.ERROR_OK then
  766. self.searchFriendPlayers = {}
  767. for i = 1, #data.brief_info_list do
  768. local playerBriefInfo = data.brief_info_list[i]
  769. local obj = FriendData:new(playerBriefInfo.uid)
  770. obj:SetData(playerBriefInfo)
  771. self.searchFriendPlayers[#self.searchFriendPlayers+1] = obj
  772. obj:SetStatus(self:GetStatus(playerBriefInfo.uid))
  773. end
  774. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Show_SearchFriendData)
  775. else
  776. -- todo 提示检索失败
  777. end
  778. end
  779. function FriendDataMgr:RefreshPlayerStatus(uid)
  780. local status = self:GetStatus(uid)
  781. local player = self:GetInterestDataById(uid)
  782. if player~= nil then
  783. player:SetStatus(status)
  784. end
  785. player = self:GetFansDataById(uid)
  786. if player ~= nil then
  787. player:SetStatus(status)
  788. end
  789. player = self:GetBlackDataById(uid)
  790. if player ~= nil then
  791. player:SetStatus(status)
  792. end
  793. player = self:GetRecommendPlayerById(uid)
  794. if player ~= nil then
  795. player:SetStatus(status)
  796. end
  797. player = self:GetSearchPlayerById(uid)
  798. if player~= nil then
  799. player:SetStatus(status)
  800. end
  801. end
  802. function FriendDataMgr:HasNewFans()
  803. return self.hasNewFans
  804. end
  805. function FriendDataMgr:SetNewFansData(val)
  806. self.hasNewFans = val
  807. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.RED_POINT_MGR_NOTICE, Enum.RPNotifyType.Friend, self.hasNewFans)
  808. end
  809. function FriendDataMgr:CleanRedPoint()
  810. for i=1, #self.fansList do
  811. local fans = self.fansList[i]
  812. fans:SetNewState(false)
  813. end
  814. self.newFansIds = nil
  815. end
  816. function FriendDataMgr:InRedPoint(uid)
  817. if self.newFansIds == nil or #self.newFansIds == 0 then
  818. return false
  819. end
  820. for i = 1,#self.newFansIds do
  821. if self.newFansIds[i] == uid then
  822. return true
  823. end
  824. end
  825. return false
  826. end
  827. function FriendDataMgr:SortInterestLit()
  828. if self.interestList == nil or #self.interestList < 2 then
  829. return
  830. end
  831. table.sort(
  832. self.interestList,
  833. function(a, b)
  834. if a.onlineStatus and b.onlineStatus == false then
  835. return true
  836. end
  837. if a.onlineStatus == false and b.onlineStatus then
  838. return false
  839. end
  840. if a.onlineStatus and b.onlineStatus then
  841. if a.status == Enum.FriendStatusType.All and b.status ~= Enum.FriendStatusType.All then
  842. return true
  843. end
  844. if a.status ~= Enum.FriendStatusType.All and b.status == Enum.FriendStatusType.All then
  845. return false
  846. end
  847. if a.fightPower > b.fightPower then
  848. return true
  849. end
  850. if a.fightPower < b.fightPower then
  851. return false
  852. end
  853. return a.uid > b.uid
  854. end
  855. return a.lastOnlineTime > b.lastOnlineTime
  856. end
  857. )
  858. end
  859. function FriendDataMgr:SortFansList()
  860. if self.fansList == nil or #self.fansList < 2 then
  861. return
  862. end
  863. table.sort(
  864. self.fansList,
  865. function(a, b)
  866. if a.onlineStatus and b.onlineStatus == false then
  867. return true
  868. end
  869. if a.onlineStatus == false and b.onlineStatus then
  870. return false
  871. end
  872. if a.onlineStatus and b.onlineStatus then
  873. if a.status == Enum.FriendStatusType.All and b.status ~= Enum.FriendStatusType.All then
  874. return true
  875. end
  876. if a.status ~= Enum.FriendStatusType.All and b.status == Enum.FriendStatusType.All then
  877. return false
  878. end
  879. if a.fightPower > b.fightPower then
  880. return true
  881. end
  882. if a.fightPower < b.fightPower then
  883. return false
  884. end
  885. return a.uid > b.uid
  886. end
  887. return a.lastOnlineTime > b.lastOnlineTime
  888. end
  889. )
  890. end
  891. function FriendDataMgr:SortBlackList()
  892. if self.blackList == nil or #self.blackList < 2 then
  893. return
  894. end
  895. table.sort(
  896. self.blackList,
  897. function(a, b)
  898. if a.onlineStatus and b.onlineStatus == false then
  899. return true
  900. end
  901. if a.onlineStatus == false and b.onlineStatus then
  902. return false
  903. end
  904. if a.onlineStatus and b.onlineStatus then
  905. if a.status == Enum.FriendStatusType.All and b.status ~= Enum.FriendStatusType.All then
  906. return true
  907. end
  908. if a.status ~= Enum.FriendStatusType.All and b.status == Enum.FriendStatusType.All then
  909. return false
  910. end
  911. if a.fightPower > b.fightPower then
  912. return true
  913. end
  914. if a.fightPower < b.fightPower then
  915. return false
  916. end
  917. return a.uid > b.uid
  918. end
  919. return a.lastOnlineTime > b.lastOnlineTime
  920. end
  921. )
  922. end
  923. function FriendDataMgr:InitInvitationData(data)
  924. if self.friendRecruitData == nil then
  925. self.friendRecruitData = FriendRecruitData:new()
  926. end
  927. self.friendRecruitData:InitData(data)
  928. end
  929. function FriendDataMgr:GetMasterUId()
  930. if self.friendRecruitData then
  931. return self.friendRecruitData:GetMasterUId()
  932. end
  933. return 0
  934. end
  935. function FriendDataMgr:GetRecruitTaskDataByCfgId(cfgId)
  936. if self.friendRecruitData then
  937. return self.friendRecruitData:GetRecruitTaskDataByCfgId(cfgId)
  938. end
  939. return nil
  940. end
  941. function FriendDataMgr:InvitationTaskRewardReq(list)
  942. if self.friendRecruitData then
  943. self.friendRecruitData:InvitationTaskRewardReq(list)
  944. end
  945. end
  946. function FriendDataMgr:GetMyRecruitCode()
  947. if self.friendRecruitData then
  948. return self.friendRecruitData:GetMyRecruitCode()
  949. end
  950. return nil
  951. end
  952. function FriendDataMgr:InvitationNumberUserInfoReq(code)
  953. if self.friendRecruitData then
  954. self.friendRecruitData:InvitationNumberUserInfoReq(code)
  955. end
  956. end
  957. function FriendDataMgr:GetMyStudentInfoDatas()
  958. if self.friendRecruitData then
  959. return self.friendRecruitData:GetMyStudentInfoDatas()
  960. end
  961. end
  962. function FriendDataMgr:QueryNextStudentBriefInfo()
  963. if self.friendRecruitData then
  964. return self.friendRecruitData:QueryNextStudentBriefInfo()
  965. end
  966. return false
  967. end
  968. function FriendDataMgr:GetMyStudentCount()
  969. if self.friendRecruitData then
  970. return self.friendRecruitData:GetMyStudentCount()
  971. end
  972. return 0
  973. end
  974. function FriendDataMgr:GetMyStudentDataByUid(uid)
  975. if self.friendRecruitData then
  976. return self.friendRecruitData:GetMyStudentDataByUid(uid)
  977. end
  978. return 0
  979. end
  980. function FriendDataMgr:IsStudentClappedByUid(uid)
  981. if self.friendRecruitData then
  982. return self.friendRecruitData:IsStudentClappedByUid(uid)
  983. end
  984. return false
  985. end
  986. function FriendDataMgr:InvitationClickReq(list)
  987. if self.friendRecruitData then
  988. return self.friendRecruitData:InvitationClickReq(list)
  989. end
  990. end
  991. function FriendDataMgr:GetRemainClapCount()
  992. if self.friendRecruitData then
  993. return self.friendRecruitData:GetRemainClapCount()
  994. end
  995. return 0
  996. end
  997. function FriendDataMgr:ClearStudentDatas()
  998. if self.friendRecruitData then
  999. self.friendRecruitData:ClearStudentDatas()
  1000. end
  1001. end
  1002. function FriendDataMgr:IsStudentListWhole()
  1003. if self.friendRecruitData then
  1004. return self.friendRecruitData:IsStudentListWhole()
  1005. end
  1006. return false
  1007. end
  1008. return FriendDataMgr