54 lines
2.1 KiB
Objective-C
54 lines
2.1 KiB
Objective-C
//
|
|
// MessageTweetModel.m
|
|
// YUMI
|
|
//
|
|
// Created by YUMI on 2023/1/30.
|
|
//
|
|
|
|
#import "MessageTweetModel.h"
|
|
#import "AttachmentModel.h"
|
|
#import "ContentTweetModel.h"
|
|
#import "NSObject+MJExtension.h"
|
|
@implementation MessageTweetModel
|
|
|
|
- (instancetype)initWithMessage:(NIMMessage *)message {
|
|
if (self = [super initWithMessage:message]) {
|
|
self.messageType = SessionMessageType_Custom;
|
|
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
|
|
AttachmentModel * attach = (AttachmentModel *)obj.attachment;
|
|
ContentTweetModel * model = [ContentTweetModel modelWithJSON:attach.data];
|
|
self.tweetInfo = model;
|
|
|
|
CGFloat oneHeight = [YMLocalizedString(@"MessageTweetModel0") boundingRectWithSize:CGSizeMake(240, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin
|
|
attributes:[self messageTextAttibutes:[UIFont systemFontOfSize:16]] context:nil].size.height + 2.5;
|
|
|
|
CGFloat titleHeight = [model.title boundingRectWithSize:CGSizeMake(240, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin
|
|
attributes:[self messageTextAttibutes:[UIFont systemFontOfSize:16]] context:nil].size.height;
|
|
if (titleHeight <= oneHeight * 2) {
|
|
titleHeight = titleHeight + 5;
|
|
} else {
|
|
titleHeight = oneHeight * 2;
|
|
}
|
|
CGFloat desHeight = [model.desc boundingRectWithSize:CGSizeMake(240, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin
|
|
attributes:[self messageTextAttibutes:[UIFont systemFontOfSize:13]] context:nil].size.height;
|
|
self.height = titleHeight + desHeight + 85 + 20 + 1 + 35 + MESSAGE_PADDING * 2 + CONTENT_PADDING_V_TOTAL;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (NSDictionary<NSAttributedStringKey, id> *)messageTextAttibutes:(UIFont *)font {
|
|
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
|
|
[paragraphStyle setLineSpacing:2.5];
|
|
return @{
|
|
NSFontAttributeName:font,
|
|
NSParagraphStyleAttributeName: paragraphStyle
|
|
};
|
|
}
|
|
|
|
|
|
- (NSString *)cellContent:(MessageBaseModel *)model {
|
|
return @"MessageContentTweetView";
|
|
}
|
|
|
|
@end
|