| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- /************************************************************
- * * Hyphenate CONFIDENTIAL
- * __________________
- * Copyright (C) 2016 Hyphenate Inc. All rights reserved.
- *
- * NOTICE: All information contained herein is, and remains
- * the property of Hyphenate Inc.
- * Dissemination of this information or reproduction of this material
- * is strictly forbidden unless prior written permission is obtained
- * from Hyphenate Inc.
- */
- #import "EaseUsersListViewController.h"
- #import "UIViewController+HUD.h"
- #import "EaseMessageViewController.h"
- @interface EaseUsersListViewController ()
- @property (strong, nonatomic) UISearchBar *searchBar;
- @end
- @implementation EaseUsersListViewController
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
-
- }
- return self;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self tableViewDidTriggerHeaderRefresh];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- #pragma mark - setter
- - (void)setShowSearchBar:(BOOL)showSearchBar
- {
- if (_showSearchBar != showSearchBar) {
- _showSearchBar = showSearchBar;
- }
- }
- #pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- // Return the number of sections.
- return 2;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- // Return the number of rows in the section.
- if (section == 0) {
- if ([_dataSource respondsToSelector:@selector(numberOfRowInUserListViewController:)]) {
- return [_dataSource numberOfRowInUserListViewController:self];
- }
- return 0;
- }
- return [self.dataArray count];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSString *CellIdentifier = [EaseUserCell cellIdentifierWithModel:nil];
- EaseUserCell *cell = (EaseUserCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
-
- // Configure the cell...
- if (cell == nil) {
- cell = [[EaseUserCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
- }
-
- if (indexPath.section == 0) {
- return nil;
- } else {
- id<IUserModel> model = nil;
- if ([_dataSource respondsToSelector:@selector(userListViewController:userModelForIndexPath:)]) {
- model = [_dataSource userListViewController:self userModelForIndexPath:indexPath];
- }
- else {
- model = [self.dataArray objectAtIndex:indexPath.row];
- }
-
- if (model) {
- cell.model = model;
- }
-
- return cell;
- }
- }
- #pragma mark - Table view delegate
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return [EaseUserCell cellHeightWithModel:nil];
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
-
- id<IUserModel> model = nil;
- if (_dataSource && [_dataSource respondsToSelector:@selector(userListViewController:userModelForIndexPath:)]) {
- model = [_dataSource userListViewController:self userModelForIndexPath:indexPath];
- }
- else {
- model = [self.dataArray objectAtIndex:indexPath.row];
- }
-
- if (model) {
- if (_delegate && [_delegate respondsToSelector:@selector(userListViewController:didSelectUserModel:)]) {
- [_delegate userListViewController:self didSelectUserModel:model];
- } else {
- EaseMessageViewController *viewController = [[EaseMessageViewController alloc] initWithConversationChatter:model.buddy conversationType:EMConversationTypeChat];
- viewController.title = model.nickname;
- [self.navigationController pushViewController:viewController animated:YES];
- }
- }}
- #pragma mark - data
- - (void)tableViewDidTriggerHeaderRefresh
- {
- __weak typeof(self) weakself = self;
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- EMError *error = nil;
- NSArray *buddyList = [[EMClient sharedClient].contactManager getContactsFromServerWithError:&error];
- if (!error) {
- NSMutableArray *contactsSource = [NSMutableArray arrayWithArray:buddyList];
- NSMutableArray *tempDataArray = [NSMutableArray array];
-
- // remove the contact that is currently in the black list
- NSArray *blockList = [[EMClient sharedClient].contactManager getBlackList];
- for (NSInteger i = 0; i < buddyList.count; i++) {
- NSString *buddy = [buddyList objectAtIndex:i];
- if (![blockList containsObject:buddy]) {
- [contactsSource addObject:buddy];
-
- id<IUserModel> model = nil;
- if (weakself.dataSource && [weakself.dataSource respondsToSelector:@selector(userListViewController:modelForBuddy:)]) {
- model = [weakself.dataSource userListViewController:self modelForBuddy:buddy];
- }
- else{
- model = [[EaseUserModel alloc] initWithBuddy:buddy];
- }
-
- if(model){
- [tempDataArray addObject:model];
- }
- }
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakself.dataArray removeAllObjects];
- [weakself.dataArray addObjectsFromArray:tempDataArray];
- [weakself.tableView reloadData];
- });
- }
- [weakself tableViewDidFinishTriggerHeader:YES reload:NO];
- });
- }
- - (void)dealloc
- {
- }
- @end
|