2020-10-14 17:18:58 +03:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2020 Ivan Sein <ivan@nextcloud.com>
|
|
|
|
*
|
|
|
|
* @author Ivan Sein <ivan@nextcloud.com>
|
|
|
|
*
|
|
|
|
* @license GNU GPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2018-10-01 19:10:06 +03:00
|
|
|
|
|
|
|
#import "RoomSearchTableViewController.h"
|
|
|
|
|
2021-05-27 17:08:41 +03:00
|
|
|
#import "NSDate+DateTools.h"
|
|
|
|
#import "UIImageView+AFNetworking.h"
|
|
|
|
|
2018-10-01 19:10:06 +03:00
|
|
|
#import "NCAPIController.h"
|
2020-11-11 19:52:31 +03:00
|
|
|
#import "NCAppBranding.h"
|
2021-05-26 22:58:50 +03:00
|
|
|
#import "NCDatabaseManager.h"
|
2018-10-01 19:10:06 +03:00
|
|
|
#import "NCRoom.h"
|
|
|
|
#import "NCSettingsController.h"
|
|
|
|
#import "PlaceholderView.h"
|
|
|
|
#import "RoomTableViewCell.h"
|
|
|
|
|
|
|
|
@interface RoomSearchTableViewController ()
|
|
|
|
{
|
|
|
|
PlaceholderView *_roomSearchBackgroundView;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RoomSearchTableViewController
|
|
|
|
|
|
|
|
- (void)viewDidLoad
|
|
|
|
{
|
|
|
|
[super viewDidLoad];
|
|
|
|
[self.tableView registerNib:[UINib nibWithNibName:kRoomTableCellNibName bundle:nil] forCellReuseIdentifier:kRoomCellIdentifier];
|
|
|
|
// Align header's title to ContactsTableViewCell's label
|
|
|
|
self.tableView.separatorInset = UIEdgeInsetsMake(0, 72, 0, 0);
|
|
|
|
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
|
|
|
|
// Contacts placeholder view
|
|
|
|
_roomSearchBackgroundView = [[PlaceholderView alloc] init];
|
2021-01-19 20:55:57 +03:00
|
|
|
[_roomSearchBackgroundView setImage:[UIImage imageNamed:@"conversations-placeholder"]];
|
2021-09-03 14:05:44 +03:00
|
|
|
[_roomSearchBackgroundView.placeholderTextView setText:NSLocalizedString(@"No results found", nil)];
|
2018-10-01 19:10:06 +03:00
|
|
|
[_roomSearchBackgroundView.placeholderView setHidden:YES];
|
|
|
|
[_roomSearchBackgroundView.loadingView startAnimating];
|
|
|
|
self.tableView.backgroundView = _roomSearchBackgroundView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)didReceiveMemoryWarning
|
|
|
|
{
|
|
|
|
[super didReceiveMemoryWarning];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setRooms:(NSArray *)rooms
|
|
|
|
{
|
|
|
|
_rooms = rooms;
|
|
|
|
[_roomSearchBackgroundView.loadingView stopAnimating];
|
|
|
|
[_roomSearchBackgroundView.loadingView setHidden:YES];
|
|
|
|
[_roomSearchBackgroundView.placeholderView setHidden:(rooms.count > 0)];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Utils
|
|
|
|
|
|
|
|
- (NSString *)getDateLabelStringForDate:(NSDate *)date
|
|
|
|
{
|
|
|
|
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
|
|
|
|
if ([date isToday]) {
|
|
|
|
[formatter setDateFormat:@"HH:mm"];
|
|
|
|
} else if ([date isYesterday]) {
|
2020-10-13 20:33:09 +03:00
|
|
|
return NSLocalizedString(@"Yesterday", nil);
|
2018-10-01 19:10:06 +03:00
|
|
|
} else {
|
|
|
|
[formatter setDateFormat:@"dd/MM/yy"];
|
|
|
|
}
|
|
|
|
return [formatter stringFromDate:date];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Table view data source
|
|
|
|
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
|
|
return _rooms.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
2018-12-06 13:15:18 +03:00
|
|
|
return kRoomTableCellHeight;
|
2018-10-01 19:10:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
|
|
|
|
//{
|
|
|
|
// return [_indexes objectAtIndex:section];
|
|
|
|
//}
|
|
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
|
|
|
NCRoom *room = [_rooms objectAtIndex:indexPath.row];
|
|
|
|
RoomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kRoomCellIdentifier];
|
|
|
|
if (!cell) {
|
|
|
|
cell = [[RoomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kRoomCellIdentifier];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set room name
|
|
|
|
cell.titleLabel.text = room.displayName;
|
|
|
|
|
2020-01-10 16:31:29 +03:00
|
|
|
// Set last activity
|
2020-01-14 21:12:37 +03:00
|
|
|
if (room.lastMessage) {
|
2020-01-10 16:31:29 +03:00
|
|
|
cell.titleOnly = NO;
|
2020-01-15 15:44:27 +03:00
|
|
|
cell.subtitleLabel.text = room.lastMessageString;
|
2018-10-01 19:10:06 +03:00
|
|
|
} else {
|
2020-01-10 16:31:29 +03:00
|
|
|
cell.titleOnly = YES;
|
2018-10-01 19:10:06 +03:00
|
|
|
}
|
2020-01-10 16:31:29 +03:00
|
|
|
NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:room.lastActivity];
|
|
|
|
cell.dateLabel.text = [self getDateLabelStringForDate:date];
|
2018-10-01 19:10:06 +03:00
|
|
|
|
|
|
|
// Set unread messages
|
2021-09-24 19:14:51 +03:00
|
|
|
if ([[NCDatabaseManager sharedInstance] serverHasTalkCapability:kCapabilityDirectMentionFlag]) {
|
|
|
|
BOOL mentioned = room.unreadMentionDirect || room.type == kNCRoomTypeOneToOne;
|
|
|
|
BOOL groupMentioned = room.unreadMention && !room.unreadMentionDirect;
|
|
|
|
[cell setUnreadMessages:room.unreadMessages mentioned:mentioned groupMentioned:groupMentioned];
|
|
|
|
} else {
|
|
|
|
BOOL mentioned = room.unreadMention || room.type == kNCRoomTypeOneToOne;
|
|
|
|
[cell setUnreadMessages:room.unreadMessages mentioned:mentioned groupMentioned:NO];
|
|
|
|
}
|
2018-10-01 19:10:06 +03:00
|
|
|
|
|
|
|
// Set room image
|
|
|
|
switch (room.type) {
|
2019-04-02 15:13:35 +03:00
|
|
|
case kNCRoomTypeOneToOne:
|
2019-10-11 19:50:43 +03:00
|
|
|
[cell.roomImage setImageWithURLRequest:[[NCAPIController sharedInstance] createAvatarRequestForUser:room.name andSize:96 usingAccount:[[NCDatabaseManager sharedInstance] activeAccount]]
|
2018-10-01 19:10:06 +03:00
|
|
|
placeholderImage:nil success:nil failure:nil];
|
2021-01-19 17:09:39 +03:00
|
|
|
[cell.roomImage setContentMode:UIViewContentModeScaleToFill];
|
2018-10-01 19:10:06 +03:00
|
|
|
break;
|
|
|
|
|
2019-04-02 15:13:35 +03:00
|
|
|
case kNCRoomTypeGroup:
|
2021-01-19 17:09:39 +03:00
|
|
|
[cell.roomImage setImage:[UIImage imageNamed:@"group"]];
|
2018-10-01 19:10:06 +03:00
|
|
|
break;
|
|
|
|
|
2019-04-02 15:13:35 +03:00
|
|
|
case kNCRoomTypePublic:
|
2021-01-19 17:09:39 +03:00
|
|
|
[cell.roomImage setImage:[UIImage imageNamed:@"public"]];
|
2018-10-01 19:10:06 +03:00
|
|
|
break;
|
|
|
|
|
2019-04-02 18:52:12 +03:00
|
|
|
case kNCRoomTypeChangelog:
|
|
|
|
[cell.roomImage setImage:[UIImage imageNamed:@"changelog"]];
|
2021-01-19 17:09:39 +03:00
|
|
|
[cell.roomImage setContentMode:UIViewContentModeScaleToFill];
|
2019-04-02 18:52:12 +03:00
|
|
|
break;
|
|
|
|
|
2018-10-01 19:10:06 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-11 14:26:15 +03:00
|
|
|
// Set objectType image
|
|
|
|
if ([room.objectType isEqualToString:NCRoomObjectTypeFile]) {
|
2021-01-19 17:09:39 +03:00
|
|
|
[cell.roomImage setImage:[UIImage imageNamed:@"file"]];
|
2018-12-11 14:26:15 +03:00
|
|
|
} else if ([room.objectType isEqualToString:NCRoomObjectTypeSharePassword]) {
|
2021-01-19 17:09:39 +03:00
|
|
|
[cell.roomImage setImage:[UIImage imageNamed:@"password"]];
|
2018-12-11 14:26:15 +03:00
|
|
|
}
|
|
|
|
|
2018-10-01 19:10:06 +03:00
|
|
|
// Set favorite image
|
|
|
|
if (room.isFavorite) {
|
|
|
|
[cell.favoriteImage setImage:[UIImage imageNamed:@"favorite-room"]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|