66 lines
2.6 KiB
Objective-C
66 lines
2.6 KiB
Objective-C
//
|
|
// MessageRiskAlertModel.m
|
|
// YUMI
|
|
//
|
|
// Created by YUMI on 2023/1/30.
|
|
//
|
|
|
|
#import "MessageRiskAlertModel.h"
|
|
#import <YYText/YYText.h>
|
|
#import "AttachmentModel.h"
|
|
#import "ContentRistAlertModel.h"
|
|
#import "NSObject+MJExtension.h"
|
|
#import "DJDKMIMOMColor.h"
|
|
#import "XPWebViewController.h"
|
|
#import "XCCurrentVCStackManager.h"
|
|
#import "YUMIHtmlUrl.h"
|
|
@implementation MessageRiskAlertModel
|
|
- (instancetype)initWithMessage:(NIMMessage *)message {
|
|
if (self = [super initWithMessage:message]) {
|
|
self.messageType = SessionMessageType_Custom;
|
|
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
|
|
AttachmentModel * attach = obj.attachment;
|
|
ContentRistAlertModel * model = [ContentRistAlertModel modelWithDictionary:attach.data];
|
|
NSString * text = model.content;
|
|
if (text.length <= 0) {
|
|
text = @"";
|
|
}
|
|
|
|
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] initWithString:text attributes:[self messageTextAttibutes]];
|
|
NSRange range = [text rangeOfString:YMLocalizedString(@"MessageRiskAlertModel0")];
|
|
if ((range.location + range.length) <= text.length) {
|
|
[attribute addAttribute:NSForegroundColorAttributeName value:[DJDKMIMOMColor appEmphasizeColor] range:range];
|
|
[attribute yy_setTextHighlightRange:range color:nil backgroundColor:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
|
|
XPWebViewController * webVC = [[XPWebViewController alloc] init];
|
|
webVC.url = URLWithType(kNetworkRenovateURL);
|
|
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:webVC animated:YES];
|
|
}];
|
|
}
|
|
self.isHiddenAvatar = YES;
|
|
self.attributedText = attribute;
|
|
CGSize dstRect = CGSizeMake(CONTENT_WIDTH_MAX - MESSAGE_PADDING * 2, MAXFLOAT);
|
|
CGSize msgSize = [text boundingRectWithSize:dstRect options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine attributes:[self messageTextAttibutes] context:nil].size;
|
|
self.contentSize = CGSizeMake(msgSize.width + MESSAGE_PADDING * 2, msgSize.height + MESSAGE_PADDING * 2);
|
|
self.height = msgSize.height + MESSAGE_PADDING * 2 + CONTENT_PADDING_V_TOTAL;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
|
|
- (NSDictionary<NSAttributedStringKey, id> *)messageTextAttibutes {
|
|
UIFont *font = [UIFont systemFontOfSize:13.f];
|
|
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
|
|
[paragraphStyle setLineSpacing:2.5];
|
|
return @{
|
|
NSFontAttributeName:font,
|
|
NSParagraphStyleAttributeName: paragraphStyle
|
|
};
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)cellContent:(MessageBaseModel *)model {
|
|
return @"MessageContentRiskAlertView";
|
|
}
|
|
@end
|