mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
169 lines
5.6 KiB
Matlab
169 lines
5.6 KiB
Matlab
10 years ago
|
//
|
||
8 years ago
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||
10 years ago
|
//
|
||
|
|
||
|
#import "ShowGroupMembersViewController.h"
|
||
|
#import "SignalsViewController.h"
|
||
9 years ago
|
#import "OWSContactsManager.h"
|
||
10 years ago
|
#import "Environment.h"
|
||
9 years ago
|
#import "GroupContactsResult.h"
|
||
10 years ago
|
#import "UIUtil.h"
|
||
10 years ago
|
#import <AddressBookUI/AddressBookUI.h>
|
||
10 years ago
|
|
||
9 years ago
|
NS_ASSUME_NONNULL_BEGIN
|
||
|
|
||
9 years ago
|
static NSString *const kUnwindToMessagesViewSegue = @"UnwindToMessagesViewSegue";
|
||
10 years ago
|
|
||
10 years ago
|
@interface ShowGroupMembersViewController ()
|
||
|
|
||
|
@property GroupContactsResult *groupContacts;
|
||
9 years ago
|
@property TSGroupThread *thread;
|
||
8 years ago
|
@property (nonatomic, readonly) OWSContactsManager *_Nonnull contactsManager;
|
||
10 years ago
|
|
||
|
@end
|
||
10 years ago
|
|
||
10 years ago
|
@implementation ShowGroupMembersViewController
|
||
|
|
||
9 years ago
|
- (instancetype)init
|
||
|
{
|
||
|
self = [super init];
|
||
|
if (!self) {
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
_contactsManager = [Environment getCurrent].contactsManager;
|
||
|
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder
|
||
|
{
|
||
|
self = [super initWithCoder:aDecoder];
|
||
|
if (!self) {
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
_contactsManager = [Environment getCurrent].contactsManager;
|
||
|
|
||
|
return self;
|
||
|
}
|
||
|
|
||
9 years ago
|
- (void)configWithThread:(TSGroupThread *)gThread {
|
||
10 years ago
|
_thread = gThread;
|
||
|
}
|
||
|
|
||
|
- (void)viewDidLoad {
|
||
|
[super viewDidLoad];
|
||
10 years ago
|
[self.navigationController.navigationBar setTranslucent:NO];
|
||
|
|
||
10 years ago
|
self.title = _thread.groupModel.groupName;
|
||
9 years ago
|
|
||
10 years ago
|
[self initializeTableView];
|
||
9 years ago
|
|
||
|
self.groupContacts =
|
||
|
[[GroupContactsResult alloc] initWithMembersId:self.thread.groupModel.groupMemberIds without:nil];
|
||
|
|
||
9 years ago
|
[self.contactsManager.getObservableContacts watchLatestValue:^(id latestValue) {
|
||
|
self.groupContacts =
|
||
|
[[GroupContactsResult alloc] initWithMembersId:self.thread.groupModel.groupMemberIds without:nil];
|
||
|
[self.tableView reloadData];
|
||
9 years ago
|
}
|
||
9 years ago
|
onThread:[NSThread mainThread]
|
||
|
untilCancelled:nil];
|
||
10 years ago
|
}
|
||
|
|
||
|
#pragma mark - Initializers
|
||
|
|
||
9 years ago
|
- (void)initializeTableView {
|
||
|
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
|
||
10 years ago
|
}
|
||
|
|
||
|
#pragma mark - Actions
|
||
|
|
||
|
#pragma mark - Table view data source
|
||
|
|
||
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||
9 years ago
|
return (NSInteger)[self.groupContacts numberOfMembers] + 1;
|
||
10 years ago
|
}
|
||
|
|
||
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||
|
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SearchCell"];
|
||
9 years ago
|
|
||
10 years ago
|
if (cell == nil) {
|
||
9 years ago
|
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
|
||
|
reuseIdentifier:indexPath.row == 0 ? @"HeaderCell" : @"GroupSearchCell"];
|
||
10 years ago
|
}
|
||
|
if (indexPath.row > 0) {
|
||
9 years ago
|
NSIndexPath *relativeIndexPath = [NSIndexPath indexPathForRow:indexPath.row - 1 inSection:indexPath.section];
|
||
10 years ago
|
if ([self.groupContacts isContactAtIndexPath:relativeIndexPath]) {
|
||
9 years ago
|
Contact *contact = [self contactForIndexPath:relativeIndexPath];
|
||
9 years ago
|
cell.textLabel.attributedText =
|
||
|
[self.contactsManager formattedFullNameForContact:contact font:cell.textLabel.font];
|
||
9 years ago
|
} else {
|
||
10 years ago
|
cell.textLabel.text = [self.groupContacts identifierForIndexPath:relativeIndexPath];
|
||
|
}
|
||
10 years ago
|
} else {
|
||
9 years ago
|
cell.textLabel.text = NSLocalizedString(@"GROUP_MEMBERS_HEADER", @"header for table which lists the members of this group thread");
|
||
10 years ago
|
cell.textLabel.textColor = [UIColor lightGrayColor];
|
||
9 years ago
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
||
9 years ago
|
cell.userInteractionEnabled = NO;
|
||
10 years ago
|
}
|
||
9 years ago
|
|
||
10 years ago
|
tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
|
||
9 years ago
|
|
||
10 years ago
|
return cell;
|
||
|
}
|
||
|
|
||
9 years ago
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||
|
NSIndexPath *relativeIndexPath = [NSIndexPath indexPathForRow:indexPath.row - 1 inSection:indexPath.section];
|
||
|
|
||
|
if (indexPath.row > 0 && [self.groupContacts isContactAtIndexPath:relativeIndexPath]) {
|
||
10 years ago
|
ABPersonViewController *view = [[ABPersonViewController alloc] init];
|
||
9 years ago
|
|
||
|
Contact *contact = [self.groupContacts contactForIndexPath:relativeIndexPath];
|
||
10 years ago
|
ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, nil);
|
||
9 years ago
|
view.displayedPerson =
|
||
|
ABAddressBookGetPersonWithRecordID(addressBookRef, contact.recordID); // Assume person is already defined.
|
||
|
view.allowsActions = NO;
|
||
|
view.allowsEditing = YES;
|
||
|
|
||
10 years ago
|
[self.navigationController pushViewController:view animated:YES];
|
||
|
} else {
|
||
|
ABUnknownPersonViewController *view = [[ABUnknownPersonViewController alloc] init];
|
||
9 years ago
|
|
||
10 years ago
|
ABRecordRef aContact = ABPersonCreate();
|
||
9 years ago
|
CFErrorRef anError = NULL;
|
||
|
|
||
10 years ago
|
ABMultiValueRef phone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
|
||
9 years ago
|
ABMultiValueAddValueAndLabel(
|
||
|
phone,
|
||
|
(__bridge CFTypeRef)[self.tableView cellForRowAtIndexPath:indexPath].textLabel.text,
|
||
|
kABPersonPhoneMainLabel,
|
||
|
NULL);
|
||
|
|
||
10 years ago
|
ABRecordSetValue(aContact, kABPersonPhoneProperty, phone, &anError);
|
||
|
CFRelease(phone);
|
||
9 years ago
|
|
||
10 years ago
|
if (!anError && aContact) {
|
||
9 years ago
|
view.displayedPerson = aContact; // Assume person is already defined.
|
||
10 years ago
|
view.allowsAddingToAddressBook = YES;
|
||
|
[self.navigationController pushViewController:view animated:YES];
|
||
10 years ago
|
}
|
||
10 years ago
|
}
|
||
9 years ago
|
|
||
10 years ago
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
- (Contact *)contactForIndexPath:(NSIndexPath *)indexPath {
|
||
10 years ago
|
Contact *contact = [self.groupContacts contactForIndexPath:indexPath];
|
||
10 years ago
|
return contact;
|
||
|
}
|
||
|
|
||
10 years ago
|
@end
|
||
9 years ago
|
|
||
|
NS_ASSUME_NONNULL_END
|