Files
peko-ios/YuMi/Modules/YMMessage/View/Session/Content/SesssionModel/MessageMonentsAutoModel.m
2023-07-14 18:50:55 +08:00

47 lines
1.6 KiB
Objective-C

//
// MessageMonentsAutoModel.m
// YUMI
//
// Created by YUMI on 2023/1/30.
//
#import "MessageMonentsAutoModel.h"
#import "AttachmentModel.h"
#import "DJDKMIMOMColor.h"
#import "GuildMessageModel.h"
#import "NSObject+MJExtension.h"
@implementation MessageMonentsAutoModel
- (instancetype)initWithMessage:(NIMMessage *)message {
if (self = [super initWithMessage:message]) {
self.messageType = SessionMessageType_Custom;
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
AttachmentModel * attach = obj.attachment;
NSDictionary * dic = attach.data;
GuildMessageModel *model = [GuildMessageModel modelWithDictionary:dic];
GuildMessageLayoutModel * layout = model.layout;
if (layout) {
self.title = layout.title.content;
self.time = layout.time.content;
NSMutableAttributedString *msgString = [[NSMutableAttributedString alloc] init];
[layout.contents enumerateObjectsUsingBlock:^(GuildMessageLayoutInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:obj.content];
[string addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:obj.fontSize] range:NSMakeRange(0, string.length)];
[string addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0x333333) range:NSMakeRange(0, string.length)];
[msgString appendAttributedString:string];
}];
self.attributedText = msgString;
}
self.contentSize = CGSizeMake(250, 120);
self.height = (CONTENT_PADDING_V_TOTAL + 120);;
}
return self;
}
- (NSString *)cellContent:(MessageBaseModel *)model {
return @"MessageContentMonentsAutoView";
}
@end