Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Sub-Goals for blocking user
- 10,000 feet view:
- - [X] <b>Generate views
- - [X] Backend modification [change schema; add array]
- - [X] Frontend logic and alerts
- </b>
- ### 1. Routes
- All routes used in for this module
- ```
- enum APIEndpoint {
- case getAllBlockUserDetail(param:APIParams)
- case addBlockUser(param:APIParams)
- }
- enum APIEndpoint2 {
- case getBlockList(param:APIParams)
- case isUserBlock(param:APIParams)
- case removeBlock(param:APIParams)
- }
- ```
- 2 Endpoints due to compiler throwing a memory leak error.
- ### 2. Blocked from profile:
- ---
- file: `ProfileUserViewC.swift`
- endpoint: `.isUserBlock(param:APIParams)| .addBlockUser(param:APIParams)`
- ```
- /// Checks whether the userId associated with profile that is being visited has being nlcoked or not;
- /// Parameter: completionHandler
- /// returns :
- /// -isBlock: if the user is blocked or not
- /// -isBlockByCurrentUser: whether current user or blocked by the other user
- fileprivate func updateBlock(completionHandler:@escaping((Bool,Bool))->()) {
- ...
- ...
- let params = ["otherUserId":userId as AnyObject]
- APIManager.shared.request(apiRouter: APIRouter.init(endpoint2: .isUserBlock(param: params))) { (data, isSuccess) in
- if(isSuccess){
- if let data = data["response"],let dicData = data as? [String:Bool],let isBlock = dicData["isBlock"],let isBlockByCurrentUser = dicData["isBlockByCurrentUser"]{
- self.isBlock = isBlock
- completionHandler((isBlock,isBlockByCurrentUser)) // isBlock,isBlockByCurrentUser
- }else{
- completionHandler((false,false)) // isBlock,isBlockByCurrentUser
- }
- }
- }
- }
- ```
- isBlockByCurrentUser if true will give ability to unblock the user since current user is the one who initiated the block action.
- ```
- let param = ["blockId":self.userId as AnyObject]
- APIManager.shared.request(apiRouter: APIRouter.init(endpoint: .addBlockUser(param: param))) {(response, success) in
- print(response)
- self.btnSettlyt.isEnabled = false
- self.lbSettlyt.isHidden = true
- self.btnSettlyt.setTitle("Blocked",for: .normal)
- self.lbSettlyt.backgroundColor = UIColor.appRedColor
- self.viewSettlyt.backgroundColor = UIColor.appRedColor
- }
- ```
- blocking user is trigger with ` .addBlockUser(param: param)`
- ### 3. Blocked Screen via Setting pane
- ---
- file : `BlockedUserVC | BlockedUserViewModel`
- endpoint: `.getBlockList(param:APIParams) | .getAllBlockUserDetail(param:APIParams) | .removeBlock(param:APIParams)`
- Place where user will unblock any user that they initial block.
- ```
- /// DataSource for ViewModel; consist of all the blocked user
- ///
- /// - Parameter completionHandler:
- func getDataSource(completionHandler:@escaping (Bool)->(Void)) {....}
- ```
- 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.
- 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.
- ---
- ### Additional info:
- Concatenated String format:
- ```
- var concateUserIds = "5c902e0f4578476412e8d2f0,5c9043654578476412e8d306"" //req.userId (user2),blockedID(user1)
- ```
- 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