用户可以自己发送公屏
This commit is contained in:
@@ -227,6 +227,7 @@
|
||||
E8E70D8C26F2F5A500F03460 /* XPMineMatchCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = E8E70D8B26F2F5A500F03460 /* XPMineMatchCollectionViewCell.m */; };
|
||||
E8E70D8F26F2F5DB00F03460 /* XPMineMenuTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = E8E70D8E26F2F5DB00F03460 /* XPMineMenuTableViewCell.m */; };
|
||||
E8E70D9226F2F60C00F03460 /* XPMineItemModel.m in Sources */ = {isa = PBXBuildFile; fileRef = E8E70D9126F2F60C00F03460 /* XPMineItemModel.m */; };
|
||||
E8EE827D272B9A2300A17217 /* XPRoomSendTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = E8EE827C272B9A2300A17217 /* XPRoomSendTextView.m */; };
|
||||
E8EEB8F226FC2050007C6EBA /* SDPhotoBrowser.m in Sources */ = {isa = PBXBuildFile; fileRef = E8EEB8EC26FC2050007C6EBA /* SDPhotoBrowser.m */; };
|
||||
E8EEB8F326FC2050007C6EBA /* SDWaitingView.m in Sources */ = {isa = PBXBuildFile; fileRef = E8EEB8ED26FC2050007C6EBA /* SDWaitingView.m */; };
|
||||
E8EEB8F426FC2050007C6EBA /* SDBrowserImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = E8EEB8EE26FC2050007C6EBA /* SDBrowserImageView.m */; };
|
||||
@@ -669,6 +670,8 @@
|
||||
E8E70D8E26F2F5DB00F03460 /* XPMineMenuTableViewCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPMineMenuTableViewCell.m; sourceTree = "<group>"; };
|
||||
E8E70D9026F2F60C00F03460 /* XPMineItemModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPMineItemModel.h; sourceTree = "<group>"; };
|
||||
E8E70D9126F2F60C00F03460 /* XPMineItemModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPMineItemModel.m; sourceTree = "<group>"; };
|
||||
E8EE827B272B9A2300A17217 /* XPRoomSendTextView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPRoomSendTextView.h; sourceTree = "<group>"; };
|
||||
E8EE827C272B9A2300A17217 /* XPRoomSendTextView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPRoomSendTextView.m; sourceTree = "<group>"; };
|
||||
E8EEB8EB26FC2050007C6EBA /* SDPhotoBrowserConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDPhotoBrowserConfig.h; sourceTree = "<group>"; };
|
||||
E8EEB8EC26FC2050007C6EBA /* SDPhotoBrowser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDPhotoBrowser.m; sourceTree = "<group>"; };
|
||||
E8EEB8ED26FC2050007C6EBA /* SDWaitingView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWaitingView.m; sourceTree = "<group>"; };
|
||||
@@ -1660,6 +1663,8 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E89D60B7271D6417001F8895 /* Model */,
|
||||
E8EE827B272B9A2300A17217 /* XPRoomSendTextView.h */,
|
||||
E8EE827C272B9A2300A17217 /* XPRoomSendTextView.m */,
|
||||
E8AEAEEE27141C430017FCE0 /* XPRoomMenuContainerView.h */,
|
||||
E8AEAEEF27141C430017FCE0 /* XPRoomMenuContainerView.m */,
|
||||
);
|
||||
@@ -2177,6 +2182,7 @@
|
||||
186A534726FC6ED900D67B2C /* TTAlertConfig.m in Sources */,
|
||||
18E7B31E26F0984C0064BC9B /* UserLevelVo.m in Sources */,
|
||||
E874B88B27215EAF003954B9 /* MicroQueueModel.m in Sources */,
|
||||
E8EE827D272B9A2300A17217 /* XPRoomSendTextView.m in Sources */,
|
||||
E8EEB90626FC5772007C6EBA /* XPMineUserInfoEditViewController.m in Sources */,
|
||||
E8B846D626FDE01B00A777FE /* XPMineRechargePresenter.m in Sources */,
|
||||
E8EEB91426FC7786007C6EBA /* XPMineUserInfoNickViewController.m in Sources */,
|
||||
|
@@ -33,7 +33,6 @@ typedef NS_ENUM(NSUInteger, GradientType) {
|
||||
|
||||
- (UIImage *)setCornerWithRadius:(CGFloat)radius andSize:(CGSize)size;
|
||||
|
||||
|
||||
//异步生成纯色圆角图片
|
||||
- (void)imageWithSize:(CGSize)size radius:(CGFloat)radius backColor:(UIColor *)backColor completion:(void(^)(UIImage *image))completion;
|
||||
/**
|
||||
|
@@ -25,6 +25,7 @@ typedef NS_ENUM(NSUInteger, KeyType) {
|
||||
KeyType_Agora,///声网 key
|
||||
KeyType_NetEase,///云信的key
|
||||
KeyType_APNSCer,///推送证书的名字
|
||||
keyType_YiDunBussinessId,///易盾的id
|
||||
};
|
||||
|
||||
/// 获取当前项目中所用到的 type 所对应的 value 的值 type 类型
|
||||
|
@@ -34,6 +34,7 @@ NSString * const KeyWithType(KeyType type) {
|
||||
@(KeyType_Agora) : @"7ae1a8dabe7a44a9a67c829faa409e70",
|
||||
@(KeyType_NetEase) : @"14ef7a0d0a84cb49bae1c22d78cf1ddf",
|
||||
@(KeyType_APNSCer) : @"yinyouApnsRelease",
|
||||
@(keyType_YiDunBussinessId) : @"2eda1894214da27d5ab7aec146fed2a2",
|
||||
},
|
||||
///测试环境
|
||||
@(NO):@{
|
||||
@@ -46,6 +47,7 @@ NSString * const KeyWithType(KeyType type) {
|
||||
@(KeyType_Agora) : @"7ae1a8dabe7a44a9a67c829faa409e70",
|
||||
@(KeyType_NetEase) : @"82a8d602aacbbb27a1c0fc809052286e",
|
||||
@(KeyType_APNSCer) : @"yinyouApnsDebug",
|
||||
@(keyType_YiDunBussinessId) : @"7ed4c5f72673dfc2d813a27bd5854874",
|
||||
}
|
||||
};
|
||||
NSDictionary * enviroDic = [dic objectForKey:@(isRelase)];
|
||||
|
@@ -6,18 +6,11 @@
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
///Model
|
||||
#import "XPRoomMenuItem.h"
|
||||
#import "RoomHostDelegate.h"
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
@class XPRoomMenuContainerView;
|
||||
@protocol XPRoomMenuContainerViewDelegate <NSObject>
|
||||
///点击了某个item
|
||||
- (void)xpRoomMenuContainerView:(XPRoomMenuContainerView *)view didClickItem:(XPRoomMenuItemType)itemType;
|
||||
|
||||
@end
|
||||
@interface XPRoomMenuContainerView : UIView
|
||||
///代理
|
||||
@property (nonatomic,weak) id<XPRoomMenuContainerViewDelegate> delegate;
|
||||
|
||||
- (instancetype)initWithDelegate:(id<RoomHostDelegate>)delegate;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@@ -10,6 +10,8 @@
|
||||
#import <Masonry/Masonry.h>
|
||||
///Model
|
||||
#import "XPRoomMenuItem.h"
|
||||
///View
|
||||
#import "XPRoomSendTextView.h"
|
||||
|
||||
@interface XPRoomMenuContainerView ()
|
||||
///
|
||||
@@ -30,15 +32,18 @@
|
||||
@property (nonatomic,strong) UIButton *giftButton;
|
||||
///占位的
|
||||
@property (nonatomic,strong) UIView * placeHolderView;
|
||||
///代理
|
||||
@property (nonatomic,weak) id<RoomHostDelegate> delegate;
|
||||
@end
|
||||
|
||||
|
||||
@implementation XPRoomMenuContainerView
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
|
||||
- (instancetype)initWithDelegate:(id<RoomHostDelegate>)delegate {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.delegate = delegate;
|
||||
[self initSubViews];
|
||||
[self initSubViewConstraints];
|
||||
}
|
||||
@@ -46,8 +51,14 @@
|
||||
}
|
||||
#pragma mark - Response
|
||||
- (void)menuButtonAction:(UIButton *)sender {
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(xpRoomMenuContainerView:didClickItem:)]) {
|
||||
[self.delegate xpRoomMenuContainerView:self didClickItem:sender.tag];
|
||||
XPRoomMenuItemType type = sender.tag;
|
||||
switch (type) {
|
||||
case XPRoomMenuItemType_Input:
|
||||
[XPRoomSendTextView showTextView:self.superview delegate:self.delegate];
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// XPRoomSendTextView.h
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by 冯硕 on 2021/10/29.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "RoomHostDelegate.h"
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface XPRoomSendTextView : UIView
|
||||
|
||||
- (instancetype)initWithDelegate:(id<RoomHostDelegate>)delegate;
|
||||
|
||||
///发小消息的弹框
|
||||
+ (void)showTextView:(UIView *)view delegate:(id<RoomHostDelegate>)delegate;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
251
xplan-ios/Main/Room/View/MenuContainerView/XPRoomSendTextView.m
Normal file
251
xplan-ios/Main/Room/View/MenuContainerView/XPRoomSendTextView.m
Normal file
@@ -0,0 +1,251 @@
|
||||
//
|
||||
// XPRoomSendTextView.m
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by 冯硕 on 2021/10/29.
|
||||
//
|
||||
|
||||
#import "XPRoomSendTextView.h"
|
||||
///Third
|
||||
#import <Masonry/Masonry.h>
|
||||
#import <NIMSDK/NIMSDK.h>
|
||||
#import "NSObject+MJExtension.h"
|
||||
///Tool
|
||||
#import "ThemeColor.h"
|
||||
#import "XPMacro.h"
|
||||
#import "UIImage+Utils.h"
|
||||
#import "XPConstant.h"
|
||||
#import "AccountInfoStorage.h"
|
||||
///Model
|
||||
#import "XPMessageRemoteExtModel.h"
|
||||
#import "UserInfoModel.h"
|
||||
#import "RoomInfoModel.h"
|
||||
//公屏限制最大字数
|
||||
#define MAX_STARWORDS_LENGTH 300
|
||||
|
||||
@interface XPRoomSendTextView ()
|
||||
///
|
||||
@property (nonatomic,strong) UIStackView *stackView;
|
||||
///输入框
|
||||
@property (nonatomic, strong) UITextField *editTextFiled;
|
||||
///发送按钮
|
||||
@property (nonatomic, strong) UIButton *sendButton;
|
||||
///文本输入的内容
|
||||
@property (nonatomic,copy) NSString *inputMessage;
|
||||
///代理
|
||||
@property (nonatomic,weak) id<RoomHostDelegate> delegate;
|
||||
@end
|
||||
|
||||
@implementation XPRoomSendTextView
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
- (instancetype)initWithDelegate:(id<RoomHostDelegate>)delegate {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.delegate = delegate;
|
||||
[self addNotification];
|
||||
[self initSubViews];
|
||||
[self initSubViewConstraints];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - Response
|
||||
|
||||
- (void)sendButtonDidClick:(UIButton *)sender {
|
||||
UserInfoModel * userInfo = [self.delegate getUserInfo];
|
||||
XPMessageRemoteExtModel *extModel = [[XPMessageRemoteExtModel alloc] init];
|
||||
if (userInfo.userLevelVo.charmUrl) {
|
||||
extModel.charmUrl = userInfo.userLevelVo.charmUrl;
|
||||
}
|
||||
if (userInfo.userLevelVo.experUrl) {
|
||||
extModel.experUrl = userInfo.userLevelVo.experUrl;
|
||||
}
|
||||
extModel.defUser = userInfo.userLevelVo.defUser;
|
||||
if (userInfo.erbanNo) {
|
||||
extModel.erbanNo = [NSString stringWithFormat:@"%ld", userInfo.erbanNo];
|
||||
}
|
||||
extModel.newUser = userInfo.newUser;
|
||||
|
||||
NIMMessage * message = [[NIMMessage alloc] init];
|
||||
message.text = self.inputMessage;
|
||||
NSMutableDictionary *remoteExt = [NSMutableDictionary dictionaryWithObject:extModel.model2dictionary forKey:[AccountInfoStorage instance].getUid];
|
||||
message.remoteExt = remoteExt;
|
||||
///网易易盾 拦截高风险
|
||||
NIMAntiSpamOption *option = [[NIMAntiSpamOption alloc]init];
|
||||
option.yidunEnabled = YES;
|
||||
option.businessId = KeyWithType(keyType_YiDunBussinessId);
|
||||
message.antiSpamOption = option;
|
||||
NSString * sessionId = [NSString stringWithFormat:@"%ld", [self.delegate getRoomInfo].roomId];
|
||||
//构造会话
|
||||
NIMSession *session = [NIMSession session:sessionId type:NIMSessionTypeChatroom];
|
||||
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:session completion:^(NSError * _Nullable error) {
|
||||
self.editTextFiled.text = @"";
|
||||
[self.editTextFiled resignFirstResponder];
|
||||
}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
- (void)keyboardWillShow:(NSNotification *)notification {
|
||||
[self.superview bringSubviewToFront:self];
|
||||
NSDictionary *info = [notification userInfo];
|
||||
CGFloat duration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
|
||||
CGRect endKeyboardRect = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
|
||||
CGFloat h = endKeyboardRect.size.height;
|
||||
[UIView animateWithDuration:duration animations:^{
|
||||
|
||||
[self mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.right.equalTo(self.superview);
|
||||
make.height.equalTo(@40);
|
||||
make.bottom.equalTo(self.superview).offset(-h);
|
||||
}];
|
||||
}];
|
||||
}
|
||||
|
||||
//键盘隐藏
|
||||
- (void)keyboardWillHidden:(NSNotification *)notification {
|
||||
NSDictionary *info = [notification userInfo];
|
||||
CGFloat duration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
|
||||
[UIView animateWithDuration:duration animations:^{
|
||||
[self mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.left.right.equalTo(self.superview);
|
||||
make.height.equalTo(@40);
|
||||
}];
|
||||
self.hidden = YES;
|
||||
}];
|
||||
}
|
||||
|
||||
-(void)textFieldEditChanged:(NSNotification *)notification{
|
||||
UITextField *textField = (UITextField *)notification.object;
|
||||
NSString *toBeString = textField.text;
|
||||
NSString *lang = [textField.textInputMode primaryLanguage];
|
||||
if ([lang isEqualToString:@"zh-Hans"]){// 简体中文输入
|
||||
//获取高亮部分
|
||||
UITextRange *selectedRange = [textField markedTextRange];
|
||||
UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0];
|
||||
// 没有高亮选择的字,则对已输入的文字进行字数统计和限制
|
||||
if (!position){
|
||||
if (toBeString.length > MAX_STARWORDS_LENGTH){
|
||||
NSRange rangeIndex = [toBeString rangeOfComposedCharacterSequenceAtIndex:MAX_STARWORDS_LENGTH];
|
||||
if (rangeIndex.length == 1){
|
||||
|
||||
textField.text = [toBeString substringToIndex:MAX_STARWORDS_LENGTH];
|
||||
}else{
|
||||
NSRange rangeRange = [toBeString rangeOfComposedCharacterSequencesForRange:NSMakeRange(0, MAX_STARWORDS_LENGTH)];
|
||||
textField.text = [toBeString substringWithRange:rangeRange];
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{ // 中文输入法以外的直接对其统计限制即可,不考虑其他语种情况
|
||||
if (toBeString.length > MAX_STARWORDS_LENGTH){
|
||||
NSRange rangeIndex = [toBeString rangeOfComposedCharacterSequenceAtIndex:MAX_STARWORDS_LENGTH];
|
||||
if (rangeIndex.length == 1){
|
||||
|
||||
textField.text = [toBeString substringToIndex:MAX_STARWORDS_LENGTH];
|
||||
}else{
|
||||
|
||||
NSRange rangeRange = [toBeString rangeOfComposedCharacterSequencesForRange:NSMakeRange(0, MAX_STARWORDS_LENGTH)];
|
||||
textField.text = [toBeString substringWithRange:rangeRange];
|
||||
}
|
||||
}
|
||||
}
|
||||
self.inputMessage = textField.text;
|
||||
if (self.inputMessage.length > 0) {
|
||||
self.sendButton.enabled = YES;
|
||||
} else {
|
||||
self.sendButton.enabled = NO;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#pragma mark - Public Method
|
||||
+ (void)showTextView:(UIView *)view delegate:(id<RoomHostDelegate>)delegate {
|
||||
__block XPRoomSendTextView * textView;
|
||||
[view.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
if ([obj isKindOfClass:[XPRoomSendTextView class]]) {
|
||||
textView = obj;
|
||||
*stop = YES;
|
||||
}
|
||||
}];
|
||||
if (textView == nil) {
|
||||
textView = [[XPRoomSendTextView alloc] initWithDelegate:delegate];
|
||||
}
|
||||
textView.hidden = NO;
|
||||
[view addSubview:textView];
|
||||
[textView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.right.bottom.mas_equalTo(view);
|
||||
make.height.mas_equalTo(40);
|
||||
}];
|
||||
[textView.editTextFiled becomeFirstResponder];
|
||||
}
|
||||
|
||||
#pragma mark - Private Method
|
||||
- (void)initSubViews {
|
||||
self.backgroundColor = [ThemeColor mainTextColor];
|
||||
[self addSubview:self.stackView];
|
||||
[self.stackView addArrangedSubview:self.editTextFiled];
|
||||
[self.stackView addArrangedSubview:self.sendButton];
|
||||
}
|
||||
|
||||
- (void)initSubViewConstraints {
|
||||
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self).offset(8);
|
||||
make.right.mas_equalTo(self).offset(-5);
|
||||
make.top.bottom.mas_equalTo(self);
|
||||
}];
|
||||
|
||||
[self.sendButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(50);
|
||||
make.top.bottom.mas_equalTo(self).inset(5);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)addNotification {
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHidden:) name:UIKeyboardWillHideNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldEditChanged:) name:UITextFieldTextDidChangeNotification object:self.editTextFiled];
|
||||
}
|
||||
|
||||
#pragma mark - Getters And Setters
|
||||
- (UITextField *)editTextFiled{
|
||||
if (!_editTextFiled) {
|
||||
_editTextFiled = [[UITextField alloc] init];
|
||||
_editTextFiled.placeholder = @"请输入消息...";
|
||||
_editTextFiled.borderStyle = UITextBorderStyleNone;
|
||||
[_editTextFiled setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
|
||||
|
||||
}
|
||||
return _editTextFiled;
|
||||
}
|
||||
- (UIButton *)sendButton{
|
||||
if (!_sendButton) {
|
||||
_sendButton = [[UIButton alloc] init];
|
||||
[_sendButton setTitle:@"发送" forState:UIControlStateNormal];
|
||||
_sendButton.titleLabel.textColor = [ThemeColor mainTextColor];
|
||||
_sendButton.titleLabel.font = [UIFont systemFontOfSize:15];
|
||||
[_sendButton setBackgroundImage:[UIImage imageWithColor:[ThemeColor disableButtonColor] ]forState:UIControlStateDisabled];
|
||||
[_sendButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[[ThemeColor confirmButtonGradientStartColor], [ThemeColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateNormal];
|
||||
_sendButton.enabled = NO;
|
||||
_sendButton.layer.cornerRadius = 5.0;
|
||||
_sendButton.layer.masksToBounds = YES;
|
||||
[_sendButton addTarget:self action:@selector(sendButtonDidClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _sendButton;
|
||||
}
|
||||
|
||||
- (UIStackView *)stackView {
|
||||
if (!_stackView) {
|
||||
_stackView = [[UIStackView alloc] init];
|
||||
_stackView.axis = UILayoutConstraintAxisHorizontal;
|
||||
_stackView.distribution = UIStackViewDistributionFill;
|
||||
_stackView.alignment = UIStackViewAlignmentCenter;
|
||||
_stackView.spacing = 10;
|
||||
}
|
||||
return _stackView;
|
||||
}
|
||||
@end
|
@@ -2,7 +2,7 @@
|
||||
// XPRoomMessageHelper.m
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by 冯硕 on 2021/10/26.
|
||||
// Created by 冯硕 on 1621/10/26.
|
||||
//
|
||||
|
||||
#import "XPRoomMessageAttributeHelper.h"
|
||||
@@ -39,9 +39,9 @@
|
||||
NSMutableAttributedString * experAttribute;
|
||||
if (image) {
|
||||
CGFloat kscale = image.size.width / image.size.height;
|
||||
experAttribute = [self createImageAttribute:image size:CGSizeMake(20 * kscale, 20)];
|
||||
experAttribute = [self createImageAttribute:image size:CGSizeMake(16 * kscale, 16)];
|
||||
} else {
|
||||
experAttribute = [self createUrlImageAttribute:remoteModel.experUrl size:CGSizeMake(25, 20) complection:^(UIImageView * _Nonnull imageView) {
|
||||
experAttribute = [self createUrlImageAttribute:remoteModel.experUrl size:CGSizeMake(25, 16) complection:^(UIImageView * _Nonnull imageView) {
|
||||
if (complection) {
|
||||
complection(imageView);
|
||||
}
|
||||
@@ -98,7 +98,9 @@
|
||||
}
|
||||
}];
|
||||
|
||||
genderImageView.bounds = CGRectMake(0, 0, 25, 20);
|
||||
genderImageView.bounds = CGRectMake(0, 0, 25, 16);
|
||||
genderImageView.layer.masksToBounds = YES;
|
||||
genderImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
NSMutableAttributedString * genderString = [NSMutableAttributedString yy_attachmentStringWithContent:genderImageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(genderImageView.frame.size.width, genderImageView.frame.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter];
|
||||
return genderString;
|
||||
}
|
||||
@@ -109,8 +111,8 @@
|
||||
+ (NSMutableAttributedString *)createLocalImageAttribute:(NSString *)imageName size:(CGSize)size {
|
||||
UIImageView *genderImageView = [[UIImageView alloc]init];
|
||||
genderImageView.image = [UIImage imageNamed:imageName];
|
||||
CGFloat kscale = genderImageView.image.size.width / genderImageView.image.size.height;
|
||||
genderImageView.bounds = CGRectMake(0, 0, 20 * kscale, 20);
|
||||
CGFloat kscale = (CGFloat)genderImageView.image.size.width / (CGFloat)genderImageView.image.size.height;
|
||||
genderImageView.bounds = CGRectMake(0, 0, 16 * kscale, 16);
|
||||
NSMutableAttributedString * genderString = [NSMutableAttributedString yy_attachmentStringWithContent:genderImageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(genderImageView.frame.size.width, genderImageView.frame.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter];
|
||||
return genderString;
|
||||
}
|
||||
@@ -121,8 +123,8 @@
|
||||
+ (NSMutableAttributedString *)createImageAttribute:(UIImage *)image size:(CGSize)size {
|
||||
UIImageView *genderImageView = [[UIImageView alloc]init];
|
||||
genderImageView.image = image;
|
||||
CGFloat kscale = genderImageView.image.size.width / genderImageView.image.size.height;
|
||||
genderImageView.bounds = CGRectMake(0, 0, 20 * kscale,20);
|
||||
CGFloat kscale = (CGFloat)genderImageView.image.size.width / (CGFloat)genderImageView.image.size.height;
|
||||
genderImageView.bounds = CGRectMake(0, 0, 16 * kscale,16);
|
||||
NSMutableAttributedString * genderString = [NSMutableAttributedString yy_attachmentStringWithContent:genderImageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(genderImageView.frame.size.width, genderImageView.frame.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter];
|
||||
return genderString;
|
||||
}
|
||||
@@ -162,6 +164,8 @@
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Private Method
|
||||
|
||||
+ (UIImage *)cacheImage:(NSString *)urlStr type:(ImageType)type {
|
||||
NSString * key = [self getCacheImageKey:urlStr type:type];
|
||||
// 缓存的图片(内存)
|
||||
|
@@ -150,23 +150,32 @@
|
||||
#pragma mark - NIMChatManagerDelegate
|
||||
- (void)onRecvMessages:(NSArray<NIMMessage *> *)messages {
|
||||
for (NIMMessage * message in messages) {
|
||||
///房间内的消息
|
||||
if (message.session.sessionType == NIMSessionTypeChatroom && [self isCurrentRoom:message.session.sessionId]) {
|
||||
if (message.messageType == NIMMessageTypeText || message.messageType == NIMMessageTypeTip) {
|
||||
[self addRoomMessage:message];
|
||||
} else if (message.messageType == NIMMessageTypeNotification) {
|
||||
NIMNotificationObject *notiMsg = (NIMNotificationObject *)message.messageObject;
|
||||
NIMChatroomNotificationContent *content = (NIMChatroomNotificationContent *)notiMsg.content;
|
||||
if (content.eventType == NIMChatroomEventTypeEnter) {
|
||||
[self addRoomMessage:message];
|
||||
}
|
||||
}else if (message.messageType == NIMMessageTypeCustom) {// 如果是自定义消息
|
||||
///TODO : 处理自定义消息
|
||||
[self handleMessage:message];
|
||||
}
|
||||
}
|
||||
|
||||
//发送消息成功回调
|
||||
- (void)sendMessage:(NIMMessage *)message didCompleteWithError:(NSError *)error {
|
||||
[self handleMessage:message];
|
||||
}
|
||||
|
||||
- (void)handleMessage:(NIMMessage *)message {
|
||||
///房间内的消息
|
||||
if (message.session.sessionType == NIMSessionTypeChatroom && [self isCurrentRoom:message.session.sessionId]) {
|
||||
if (message.messageType == NIMMessageTypeText || message.messageType == NIMMessageTypeTip) {
|
||||
[self addRoomMessage:message];
|
||||
} else if (message.messageType == NIMMessageTypeNotification) {
|
||||
NIMNotificationObject *notiMsg = (NIMNotificationObject *)message.messageObject;
|
||||
NIMChatroomNotificationContent *content = (NIMChatroomNotificationContent *)notiMsg.content;
|
||||
if (content.eventType == NIMChatroomEventTypeEnter) {
|
||||
[self addRoomMessage:message];
|
||||
}
|
||||
} else {
|
||||
}else if (message.messageType == NIMMessageTypeCustom) {// 如果是自定义消息
|
||||
///TODO : 处理自定义消息
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,10 +234,13 @@
|
||||
}
|
||||
|
||||
- (void)xpRoomMessageDisplayModel:(XPRoomMessageDisplayModel *)displayModel didClickUser:(NSString *)userId {
|
||||
NSLog(@"点击的用户%@", userId);
|
||||
///TODO : NSLog(@"点击的用户%@", userId);
|
||||
}
|
||||
|
||||
- (void)loadUrlImageSuccess:(UIImageView *)imageView cell:(XPRoomMessageTableViewCell *)cell {
|
||||
if (cell == nil) {
|
||||
return;
|
||||
}
|
||||
CGSize size = CGSizeMake(kRoomMessageMaxWidth, CGFLOAT_MAX);
|
||||
YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:size text:cell.contentLabel.attributedText];
|
||||
NSMutableAttributedString * attribute = [cell.contentLabel.attributedText mutableCopy];
|
||||
@@ -237,11 +249,10 @@
|
||||
YYTextAttachment * attachment = [layout.attachments objectAtIndex:i];
|
||||
if (imageView == attachment.content) {
|
||||
CGFloat kscale = (CGFloat)imageView.image.size.width / (CGFloat)imageView.image.size.height;
|
||||
imageView.frame = CGRectMake(0, 0, 40 * kscale, 40);
|
||||
attachment.content = imageView;
|
||||
imageView.frame = CGRectMake(0, 0, 16 * kscale, 16);
|
||||
NSValue * value = [layout.attachmentRanges objectAtIndex:i];
|
||||
NSRange range = value.rangeValue;
|
||||
NSMutableAttributedString * resultString = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:imageView.image.size alignToFont:[UIFont systemFontOfSize:14.0] alignment:YYTextVerticalAlignmentCenter];
|
||||
NSMutableAttributedString * resultString = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:imageView.frame.size alignToFont:[UIFont systemFontOfSize:14.0] alignment:YYTextVerticalAlignmentCenter];
|
||||
[attribute replaceCharactersInRange:range withAttributedString:resultString];
|
||||
break;
|
||||
}
|
||||
|
@@ -79,7 +79,9 @@
|
||||
[self.presenter getRoomInfoWithUid:self.roomUid];
|
||||
}
|
||||
|
||||
|
||||
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
||||
[self.view endEditing:YES];
|
||||
}
|
||||
#pragma mark - Private Method
|
||||
- (void)initSubViews {
|
||||
[self.view addSubview:self.backContainerView];
|
||||
@@ -213,7 +215,7 @@
|
||||
|
||||
- (XPRoomMenuContainerView *)menuContainerView {
|
||||
if (!_menuContainerView) {
|
||||
_menuContainerView = [[XPRoomMenuContainerView alloc] init];
|
||||
_menuContainerView = [[XPRoomMenuContainerView alloc] initWithDelegate:self];
|
||||
}
|
||||
return _menuContainerView;
|
||||
}
|
||||
|
Reference in New Issue
Block a user