| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- //
- // TUIMessageCellData.m
- // TXIMSDK_TUIKit_iOS
- //
- // Created by annidyfeng on 2019/5/21.
- // Copyright © 2023 Tencent. All rights reserved.
- //
- #import "TUIMessageCellData.h"
- #import <TIMCommon/TIMDefine.h>
- @interface TUIMessageCellData ()
- @end
- @implementation TUIMessageCellData
- {
- NSString *_msgID;
- NSString *_identifier;
- NSURL *_avatarUrl;
- }
- + (TUIMessageCellData *)getCellData:(V2TIMMessage *)message {
- return nil;
- }
- + (NSString *)getDisplayString:(V2TIMMessage *)message {
- return nil;
- }
- - (Class)getReplyQuoteViewDataClass {
- return nil;
- }
- - (Class)getReplyQuoteViewClass {
- return nil;
- }
- - (instancetype)initWithDirection:(TMsgDirection)direction {
- self = [super init];
- if (self) {
- _direction = direction;
- _status = Msg_Status_Init;
- _source = Msg_Source_Unkown;
- _showReadReceipt = YES;
- _sameToNextMsgSender = NO;
- _showAvatar = YES;
- _cellLayout = [self cellLayout:direction];
- _additionalUserInfoResult = @{};
- }
- return self;
- }
- - (TUIMessageCellLayout *)cellLayout:(TMsgDirection)direction {
- if (direction == MsgDirectionIncoming) {
- return [TUIMessageCellLayout incommingMessageLayout];
- } else {
- return [TUIMessageCellLayout outgoingMessageLayout];
- }
- }
- - (void)setMsgID:(NSString *)msgID {
- _msgID = msgID;
- }
- - (NSString *)msgID {
- if (_msgID) {
- return _msgID;
- }
- if (self.innerMessage) {
- return self.innerMessage.msgID;
- }
- return nil;
- }
- - (void)setIdentifier:(NSString *)identifier {
- _identifier = identifier;
- }
- - (NSString *)identifier {
- if (_identifier) {
- return _identifier;
- }
- if (self.innerMessage) {
- return self.innerMessage.sender;
- }
- return nil;
- }
- - (NSString *)senderName {
- if (self.innerMessage) {
-
- if(self.innerMessage.localCustomData){
- NSDictionary *dict = [self dictionaryFromData:self.innerMessage.localCustomData];
- NSString *nickName = [TUIMessageCellData objectOrNilForKey:@"showName" fromDictionary:dict];
- if(nickName.length > 0){
- return nickName;
- }
- }
-
- return self.innerMessage.nameCard ? : (self.innerMessage.friendRemark ? : (self.innerMessage.nickName ? : self.innerMessage.sender));
- }
- return nil;
- }
- - (void)setAvatarUrl:(NSURL *)avatarUrl {
- _avatarUrl = avatarUrl;
- }
- - (NSDictionary *)dictionaryFromData:(NSData *)data {
- NSError *error = nil;
- NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
- if (error) {
- NSLog(@"Error converting NSData to NSDictionary: %@", error.localizedDescription);
- return nil;
- }
- return dictionary;
- }
- + (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
- {
- id object = [dict objectForKey:aKey];
- return [object isEqual:[NSNull null]] ? nil : object;
- }
- - (NSURL *)avatarUrl {
- if (_avatarUrl) {
- return _avatarUrl;
- }
- if (self.innerMessage) {
-
- if(self.innerMessage.localCustomData){
- NSDictionary *dict = [self dictionaryFromData:self.innerMessage.localCustomData];
- NSString *avatarStr = [TUIMessageCellData objectOrNilForKey:@"avatarURL" fromDictionary:dict];
- if(avatarStr.length > 0){
- return [NSURL URLWithString:avatarStr];
- }
- }
-
- return [NSURL URLWithString:self.innerMessage.faceURL];;
- }
- return nil;
- }
- - (NSInteger)headgearType{
- if (self.innerMessage){
- if(self.innerMessage.localCustomData){
- NSDictionary *dict = [self dictionaryFromData:self.innerMessage.localCustomData];
- NSInteger type = [[TUIMessageCellData objectOrNilForKey:@"headgearType" fromDictionary:dict] integerValue];
- return type;
- }
- }
- return 0;
- }
- - (NSString *)headdress{
- if (self.innerMessage){
- if(self.innerMessage.localCustomData){
- NSDictionary *dict = [self dictionaryFromData:self.innerMessage.localCustomData];
- NSString *headdressStr = [TUIMessageCellData objectOrNilForKey:@"headdress" fromDictionary:dict];
- return headdressStr;
- }
- }
- return @"";
- }
- - (BOOL)canForward {
- return YES;
- }
- - (BOOL)canLongPress {
- return YES;
- }
- - (BOOL)shouldHide {
- return NO;
- }
- - (BOOL)customReloadCellWithNewMsg:(V2TIMMessage *)newMessage {
- return NO;
- }
- - (CGSize)msgStatusSize {
- if (self.showReadReceipt && self.innerMessage.needReadReceipt &&
- (self.innerMessage.userID || self.innerMessage.groupID)) {
- if (self.direction == MsgDirectionOutgoing) {
- return CGSizeMake(54, 14);
- } else {
- return CGSizeMake(38, 14);
- }
- }
- else {
- //The community type does not require read receipt markers, only the time is needed.
- return CGSizeMake(26, 14);
- }
- }
- - (NSDictionary *)messageModifyUserInfos {
- return self.additionalUserInfoResult;
- }
- - (NSArray<NSString *> *)requestForAdditionalUserInfo {
- return @[];
- }
- @end
|