WFCUConversationFilesViewController.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // WFCUConversationFilesViewController.m
  3. // WFChatUIKit
  4. //
  5. // Created by dali on 2020/11/12.
  6. // Copyright © 2020 Wildfirechat. All rights reserved.
  7. //
  8. #import "WFCUConversationFilesViewController.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import "WFCUFilesViewController.h"
  11. #import <SDWebImage/SDWebImage.h>
  12. #import "WFCUImage.h"
  13. @interface WFCUConversationFilesViewController () <UITableViewDelegate, UITableViewDataSource>
  14. @property(nonatomic, strong)UITableView *tableView;
  15. @property(nonatomic, strong)NSArray<WFCCConversationInfo *> *conversations;
  16. @end
  17. @implementation WFCUConversationFilesViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
  21. self.tableView.dataSource = self;
  22. self.tableView.delegate = self;
  23. if (@available(iOS 15, *)) {
  24. self.tableView.sectionHeaderTopPadding = 0;
  25. }
  26. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  27. [self.view addSubview:self.tableView];
  28. self.conversations = [[WFCCIMService sharedWFCIMService] getConversationInfos:@[@(Single_Type),@(Group_Type),@(SecretChat_Type)] lines:@[@(0)]];
  29. [self.tableView reloadData];
  30. }
  31. #pragma mark - UITableViewDataSource
  32. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  33. return self.conversations.count;
  34. }
  35. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  36. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  37. if (!cell) {
  38. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  39. }
  40. WFCCConversationInfo *conv = self.conversations[indexPath.row];
  41. if (conv.conversation.type == Single_Type) {
  42. WFCCUserInfo *user = [[WFCCIMService sharedWFCIMService] getUserInfo:conv.conversation.target refresh:NO];
  43. if (user.friendAlias.length) {
  44. cell.textLabel.text = user.friendAlias;
  45. } else if(user.displayName.length) {
  46. cell.textLabel.text = user.displayName;
  47. } else {
  48. cell.textLabel.text = WFCString(@"User");
  49. }
  50. [cell.imageView sd_setImageWithURL:[NSURL URLWithString:user.portrait] placeholderImage: [WFCUImage imageNamed:@"PersonalChat"]];
  51. } else if (conv.conversation.type == Group_Type) {
  52. WFCCGroupInfo *group = [[WFCCIMService sharedWFCIMService] getGroupInfo:conv.conversation.target refresh:NO];
  53. if (group.displayName.length) {
  54. cell.textLabel.text = group.displayName;
  55. } else {
  56. cell.textLabel.text = WFCString(@"Group");
  57. }
  58. if (group.portrait.length) {
  59. [cell.imageView sd_setImageWithURL:[NSURL URLWithString:[group.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[WFCUImage imageNamed:@"group_default_portrait"]];
  60. } else {
  61. NSString *path = [WFCCUtilities getGroupGridPortrait:group.target width:80 generateIfNotExist:YES defaultUserPortrait:^UIImage *(NSString *userId) {
  62. return [WFCUImage imageNamed:@"PersonalChat"];
  63. }];
  64. if (path) {
  65. [cell.imageView sd_setImageWithURL:[NSURL fileURLWithPath:path] placeholderImage:[WFCUImage imageNamed:@"group_default_portrait"]];
  66. }
  67. }
  68. } else if (conv.conversation.type == SecretChat_Type) {
  69. NSString *userId = [[WFCCIMService sharedWFCIMService] getSecretChatInfo:conv.conversation.target].userId;
  70. WFCCUserInfo *user = [[WFCCIMService sharedWFCIMService] getUserInfo:userId refresh:NO];
  71. if (user.friendAlias.length) {
  72. cell.textLabel.text = user.friendAlias;
  73. } else if(user.displayName.length) {
  74. cell.textLabel.text = user.displayName;
  75. } else {
  76. cell.textLabel.text = WFCString(@"User");
  77. }
  78. [cell.imageView sd_setImageWithURL:[NSURL URLWithString:user.portrait] placeholderImage: [WFCUImage imageNamed:@"PersonalChat"]];
  79. }
  80. return cell;
  81. }
  82. #pragma mark - UITableViewDelegate
  83. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  84. WFCCConversationInfo *conv = self.conversations[indexPath.row];
  85. WFCUFilesViewController *vc = [[WFCUFilesViewController alloc] init];
  86. vc.conversation = conv.conversation;
  87. [self.navigationController pushViewController:vc animated:YES];
  88. }
  89. @end