Files
peko-ios/YuMi/Modules/YMMessage/View/Session/Content/SesssionModel/MessageGuildModel.m

73 lines
2.6 KiB
Mathematica
Raw Normal View History

2023-07-06 16:54:13 +08:00
//
2023-07-14 18:50:55 +08:00
// MessageGuildModel.m
2023-07-06 16:54:13 +08:00
// YUMI
//
// Created by YUMI on 2023/1/30.
//
2023-07-14 18:50:55 +08:00
#import "MessageGuildModel.h"
2023-10-28 04:46:10 +08:00
2023-07-14 18:50:55 +08:00
#import "AttachmentModel.h"
#import "GuildMessageModel.h"
2023-07-06 16:54:13 +08:00
#import "DJDKMIMOMColor.h"
#import "NSObject+MJExtension.h"
2023-07-14 18:50:55 +08:00
@implementation MessageGuildModel
2023-07-06 16:54:13 +08:00
- (instancetype)initWithMessage:(NIMMessage *)message {
if (self = [super initWithMessage:message]) {
2023-07-14 18:50:55 +08:00
self.messageType = SessionMessageType_Custom;
2023-07-06 16:54:13 +08:00
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
2024-05-22 12:06:48 +08:00
AttachmentModel * attach = (AttachmentModel *)obj.attachment;
2023-07-14 18:50:55 +08:00
GuildMessageModel * info = [GuildMessageModel modelWithDictionary:attach.data];
2023-07-06 16:54:13 +08:00
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]init];
2023-07-14 18:50:55 +08:00
GuildMessageLayoutModel *layout = info.layout;
for (GuildMessageLayoutInfoModel *params in layout.contents) {
2023-07-06 16:54:13 +08:00
if (params.content.length > 0) {
if ([params.content containsString:@"/r/n"]) {
params.content = @"\r\n";
}
NSMutableAttributedString *subAttr = [[NSMutableAttributedString alloc]initWithString:params.content];
if (params.fontSize > 0) {
[subAttr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:params.fontSize weight:params.fontBold?UIFontWeightBold:UIFontWeightRegular] range:NSMakeRange(0, subAttr.length)];
}
if (params.fontColor.length > 0) {
2023-07-14 18:50:55 +08:00
[subAttr addAttribute:NSForegroundColorAttributeName value:[DJDKMIMOMColor colorWithHexString:params.fontColor] range:NSMakeRange(0, subAttr.length)];
2023-07-06 16:54:13 +08:00
}
[attr appendAttributedString:subAttr];
}
}
attr.yy_lineSpacing = 5;
CGSize maxSize = CGSizeMake(230 - MESSAGE_PADDING * 2, CGFLOAT_MAX);
YYTextLayout * contentLayout = [YYTextLayout layoutWithContainerSize:maxSize text:attr];
2023-07-14 18:50:55 +08:00
/// 20 title15 titlecontent
2023-07-06 16:54:13 +08:00
CGFloat contentHeight = contentLayout.textBoundingSize.height + 5 + 20 + 15 + 15 + MESSAGE_PADDING;
2023-07-14 18:50:55 +08:00
///44
2023-07-06 16:54:13 +08:00
BOOL isCommonNotice = (attach.second == Custom_Message_Sub_Hall_Notice || attach.second == Custom_Message_Sub_Hall_Become_Hall);
if (!isCommonNotice) {
contentHeight += (10+44);
}
self.height = contentHeight + CONTENT_PADDING_V_TOTAL;
self.contentSize = CGSizeMake(CONTENT_WIDTH_MAX, contentHeight + 20 + 15 + 15);
}
return self;
}
2023-07-14 18:50:55 +08:00
- (NSDictionary<NSAttributedStringKey, id> *)messageTextAttibutes {
2023-07-06 16:54:13 +08:00
UIFont *font = [UIFont systemFontOfSize:13.f];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:2.5];
return @{
NSFontAttributeName:font,
NSParagraphStyleAttributeName: paragraphStyle
};
}
2023-07-14 18:50:55 +08:00
- (NSString *)cellContent:(MessageBaseModel *)model {
return @"MessageContentGuildView";
2023-07-06 16:54:13 +08:00
}
@end