Advertisement
Guest User

Untitled

a guest
May 19th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. ## Sub-Goals for blocking user
  2.  
  3. 10,000 feet view:
  4.  
  5. - [X] <b>Generate views
  6. - [X] Backend modification [change schema; add array]
  7. - [X] Frontend logic and alerts
  8. </b>
  9.  
  10. ### 1. Routes
  11. All routes used in for this module
  12.  
  13. ```
  14. enum APIEndpoint {
  15. case getAllBlockUserDetail(param:APIParams)
  16. case addBlockUser(param:APIParams)
  17. }
  18.  
  19. enum APIEndpoint2 {
  20. case getBlockList(param:APIParams)
  21. case isUserBlock(param:APIParams)
  22. case removeBlock(param:APIParams)
  23. }
  24.  
  25. ```
  26.  
  27. 2 Endpoints due to compiler throwing a memory leak error.
  28.  
  29.  
  30. ### 2. Blocked from profile:
  31. ---
  32. file: `ProfileUserViewC.swift`
  33.  
  34. endpoint: `.isUserBlock(param:APIParams)| .addBlockUser(param:APIParams)`
  35.  
  36.  
  37. ```
  38. /// Checks whether the userId associated with profile that is being visited has being nlcoked or not;
  39. /// Parameter: completionHandler
  40. /// returns :
  41. /// -isBlock: if the user is blocked or not
  42. /// -isBlockByCurrentUser: whether current user or blocked by the other user
  43.  
  44. fileprivate func updateBlock(completionHandler:@escaping((Bool,Bool))->()) {
  45. ...
  46. ...
  47. let params = ["otherUserId":userId as AnyObject]
  48. APIManager.shared.request(apiRouter: APIRouter.init(endpoint2: .isUserBlock(param: params))) { (data, isSuccess) in
  49. if(isSuccess){
  50. if let data = data["response"],let dicData = data as? [String:Bool],let isBlock = dicData["isBlock"],let isBlockByCurrentUser = dicData["isBlockByCurrentUser"]{
  51. self.isBlock = isBlock
  52. completionHandler((isBlock,isBlockByCurrentUser)) // isBlock,isBlockByCurrentUser
  53. }else{
  54. completionHandler((false,false)) // isBlock,isBlockByCurrentUser
  55. }
  56. }
  57. }
  58.  
  59. }
  60. ```
  61.  
  62. isBlockByCurrentUser if true will give ability to unblock the user since current user is the one who initiated the block action.
  63.  
  64.  
  65. ```
  66. let param = ["blockId":self.userId as AnyObject]
  67. APIManager.shared.request(apiRouter: APIRouter.init(endpoint: .addBlockUser(param: param))) {(response, success) in
  68. print(response)
  69. self.btnSettlyt.isEnabled = false
  70. self.lbSettlyt.isHidden = true
  71. self.btnSettlyt.setTitle("Blocked",for: .normal)
  72. self.lbSettlyt.backgroundColor = UIColor.appRedColor
  73. self.viewSettlyt.backgroundColor = UIColor.appRedColor
  74. }
  75. ```
  76.  
  77. blocking user is trigger with ` .addBlockUser(param: param)`
  78.  
  79.  
  80.  
  81.  
  82. ### 3. Blocked Screen via Setting pane
  83. ---
  84. file : `BlockedUserVC | BlockedUserViewModel`
  85.  
  86. endpoint: `.getBlockList(param:APIParams) | .getAllBlockUserDetail(param:APIParams) | .removeBlock(param:APIParams)`
  87.  
  88. Place where user will unblock any user that they initial block.
  89.  
  90. ```
  91. /// DataSource for ViewModel; consist of all the blocked user
  92. ///
  93. /// - Parameter completionHandler:
  94. func getDataSource(completionHandler:@escaping (Bool)->(Void)) {....}
  95. ```
  96.  
  97. Initally `.getBlockList(param:APIParams)` endpoint is used to get the concatinated string which is parsed to obtain blocked userid. This blocked userId is then used in `.getAllBlockUserDetail(param: params)` endpoint to gather detail information about user.
  98.  
  99. With data from ``.getAllBlockUserDetail(param: params)` endpoint we can populate row in tableView. Swiping or pressing on remove icon will trigger `.removeBlock(param:APIParams)` which will trigger removal of the blocked user from both users blocked group.
  100.  
  101. ---
  102.  
  103. ### Additional info:
  104.  
  105. Concatenated String format:
  106.  
  107. ```
  108. var concateUserIds = "5c902e0f4578476412e8d2f0,5c9043654578476412e8d306"" //req.userId (user2),blockedID(user1)
  109. ```
  110.  
  111. The concatenated format is written when user is blocked to database. Both user1 and user2 ID is populated but user2 has no capability to block user1. The concatenated string is done to leverage atomicity.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement