123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- //
- // WFCUConversationFilesViewController.m
- // WFChatUIKit
- //
- // Created by dali on 2020/11/12.
- // Copyright © 2020 Wildfirechat. All rights reserved.
- //
- #import "WFCUConversationFilesViewController.h"
- #import <WFChatClient/WFCChatClient.h>
- #import "WFCUFilesViewController.h"
- #import <SDWebImage/SDWebImage.h>
- #import "WFCUImage.h"
- @interface WFCUConversationFilesViewController () <UITableViewDelegate, UITableViewDataSource>
- @property(nonatomic, strong)UITableView *tableView;
- @property(nonatomic, strong)NSArray<WFCCConversationInfo *> *conversations;
- @end
- @implementation WFCUConversationFilesViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
- self.tableView.dataSource = self;
- self.tableView.delegate = self;
- if (@available(iOS 15, *)) {
- self.tableView.sectionHeaderTopPadding = 0;
- }
- self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
- [self.view addSubview:self.tableView];
- self.conversations = [[WFCCIMService sharedWFCIMService] getConversationInfos:@[@(Single_Type),@(Group_Type),@(SecretChat_Type)] lines:@[@(0)]];
- [self.tableView reloadData];
- }
- #pragma mark - UITableViewDataSource
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.conversations.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
- if (!cell) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
- }
- WFCCConversationInfo *conv = self.conversations[indexPath.row];
- if (conv.conversation.type == Single_Type) {
- WFCCUserInfo *user = [[WFCCIMService sharedWFCIMService] getUserInfo:conv.conversation.target refresh:NO];
- if (user.friendAlias.length) {
- cell.textLabel.text = user.friendAlias;
- } else if(user.displayName.length) {
- cell.textLabel.text = user.displayName;
- } else {
- cell.textLabel.text = WFCString(@"User");
- }
- [cell.imageView sd_setImageWithURL:[NSURL URLWithString:user.portrait] placeholderImage: [WFCUImage imageNamed:@"PersonalChat"]];
- } else if (conv.conversation.type == Group_Type) {
- WFCCGroupInfo *group = [[WFCCIMService sharedWFCIMService] getGroupInfo:conv.conversation.target refresh:NO];
- if (group.displayName.length) {
- cell.textLabel.text = group.displayName;
- } else {
- cell.textLabel.text = WFCString(@"Group");
- }
- if (group.portrait.length) {
- [cell.imageView sd_setImageWithURL:[NSURL URLWithString:[group.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[WFCUImage imageNamed:@"group_default_portrait"]];
- } else {
- NSString *path = [WFCCUtilities getGroupGridPortrait:group.target width:80 generateIfNotExist:YES defaultUserPortrait:^UIImage *(NSString *userId) {
- return [WFCUImage imageNamed:@"PersonalChat"];
- }];
-
- if (path) {
- [cell.imageView sd_setImageWithURL:[NSURL fileURLWithPath:path] placeholderImage:[WFCUImage imageNamed:@"group_default_portrait"]];
- }
- }
- } else if (conv.conversation.type == SecretChat_Type) {
- NSString *userId = [[WFCCIMService sharedWFCIMService] getSecretChatInfo:conv.conversation.target].userId;
- WFCCUserInfo *user = [[WFCCIMService sharedWFCIMService] getUserInfo:userId refresh:NO];
- if (user.friendAlias.length) {
- cell.textLabel.text = user.friendAlias;
- } else if(user.displayName.length) {
- cell.textLabel.text = user.displayName;
- } else {
- cell.textLabel.text = WFCString(@"User");
- }
- [cell.imageView sd_setImageWithURL:[NSURL URLWithString:user.portrait] placeholderImage: [WFCUImage imageNamed:@"PersonalChat"]];
- }
-
- return cell;
- }
- #pragma mark - UITableViewDelegate
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- WFCCConversationInfo *conv = self.conversations[indexPath.row];
- WFCUFilesViewController *vc = [[WFCUFilesViewController alloc] init];
- vc.conversation = conv.conversation;
- [self.navigationController pushViewController:vc animated:YES];
- }
- @end
|