Files
peko-ios/YuMi/Modules/YMRoom/View/MessageContainerView/XPRoomMessageContainerView.m

1857 lines
74 KiB
Mathematica
Raw Normal View History

2023-07-14 18:50:55 +08:00
//
// YMRoomMessageView.m
// YUMI
//
// Created by YUMI on 2021/10/11.
//
#import "XPRoomMessageContainerView.h"
///Third
#import <Masonry/Masonry.h>
#import <NIMSDK/NIMSDK.h>
2023-10-28 04:46:10 +08:00
2023-07-14 18:50:55 +08:00
///Tool
#import "DJDKMIMOMColor.h"
#import "YUMIMacroUitls.h"
#import "XPRoomMessageConstant.h"
#import "XPRoomMessageParser.h"
#import "AccountInfoStorage.h"
#import "XPRoomMiniManager.h"
#import "PLTimeUtil.h"
#import "ClientConfig.h"
#import <POP.h>
#import "ThemeColor+Room.h"
#import "NSArray+Safe.h"
2023-10-17 18:30:14 +08:00
#import "Api+Room.h"
2023-07-14 18:50:55 +08:00
///Model
#import "RoomInfoModel.h"
#import "AttachmentModel.h"
#import "RoomFaceSendInfoModel.h"
#import "XPMessageRemoteExtModel.h"
#import "RoomPKChooseUserModel.h"
#import "CandyTreeResultModel.h"
#import "RoomSailingPrizeModel.h"
#import "UserInfoModel.h"
#import "XPMessageInfoModel.h"
2024-03-25 14:39:36 +08:00
#import "GiftReceiveInfoModel.h"
#import "XPGiftStorage.h"
2024-08-22 11:40:50 +08:00
2023-07-14 18:50:55 +08:00
///View
#import "XPRoomMessageTableViewCell.h"
#import "XPRoomMessageHeaderView.h"
2023-10-13 17:20:50 +08:00
#import "PIRoomMessagePhotoAlbumCell.h"
#import "PIRoomMessageUnlockPhotoAlbumView.h"
2023-10-17 18:30:14 +08:00
#import "PIRoomPhotoAlbumItemModel.h"
#import "SDPhotoBrowser.h"
#import "XPSkillCardPlayerManager.h"
2023-07-14 18:50:55 +08:00
2024-10-12 19:30:41 +08:00
// Boom
#import "BoomInfoModel.h"
2025-02-28 19:04:09 +08:00
//
#import "LuckyPackageMessageTableViewCell.h"
// CP
#import "CPEnterRoomTableViewCell.h"
#import "RoomEnterModel.h"
2023-07-14 18:50:55 +08:00
NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey";
2023-10-17 18:30:14 +08:00
@interface XPRoomMessageContainerView ()<UITableViewDelegate, UITableViewDataSource, XPRoomMessageTableViewCellDelegate, UIGestureRecognizerDelegate,PIRoomMessagePhotoAlbumCellDelegate,SDPhotoBrowserDelegate,PIRoomMessageUnlockPhotoAlbumViewDelegate>
2023-07-14 18:50:55 +08:00
///
@property (nonatomic,weak) id<RoomHostDelegate> hostDelegate;
///
@property (nonatomic,strong) UITableView *messageTableView;
///
@property (nonatomic,strong) XPRoomMessageHeaderView *headerView;
///
@property (nonatomic,strong) UIButton *messageTipsBtn;
///at
@property (nonatomic, strong) UIButton *atTipBtn;
///
@property (nonatomic,assign) BOOL isPending;
///
@property (nonatomic,assign) BOOL isMiniEnter;
///
@property (nonatomic,strong) NSMutableArray<XPMessageInfoModel *> *datasource;
@property (nonatomic,strong) NSMutableArray<XPMessageInfoModel *> *datasource_chat;
@property (nonatomic,strong) NSMutableArray<XPMessageInfoModel *> *datasource_gift;
2023-07-14 18:50:55 +08:00
///
2024-10-12 19:30:41 +08:00
@property (nonatomic,strong) NSMutableArray *incomingMessages;
2023-07-14 18:50:55 +08:00
///at
@property (nonatomic, assign) NSInteger atCount;
///@
@property (nonatomic, strong) NSMutableArray *locationArray;
///messageView
2023-07-14 18:50:55 +08:00
@property (nonatomic,strong) XPRoomMessageParser *messageParser;
2024-06-04 14:54:51 +08:00
2023-10-17 18:30:14 +08:00
@property(nonatomic,strong) PIRoomPhotoAlbumItemModel *lookUpModel;
2023-10-26 16:37:53 +08:00
@property(nonatomic,assign) BOOL isLoadHistoryMessage;
@property (nonatomic, assign) NSInteger displayType;
/// reload
@property (nonatomic, assign) BOOL forceReloadNextAppend;
2025-02-28 19:04:09 +08:00
/// UI
@property (atomic, assign) BOOL viewReady;
///
@property (atomic, assign) BOOL isFlushing;
/// UI viewReady
@property (nonatomic, strong) NSMutableArray<dispatch_block_t> *pendingOps;
2023-07-14 18:50:55 +08:00
@end
@implementation XPRoomMessageContainerView
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (instancetype)initWithDelegate:(id<RoomHostDelegate>)delegate {
self = [super init];
if (self) {
self.displayType = 1;
2023-10-31 18:02:12 +08:00
self.isLoadHistoryMessage = YES;
self.forceReloadNextAppend = NO;
2023-07-14 18:50:55 +08:00
self.hostDelegate = delegate;
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
/// UI 退 reload
- (void)safeApplyInsertsFromStartIndex:(NSInteger)startIndex
newItemsCount:(NSInteger)newItemsCount
needReload:(BOOL)needReload {
if (needReload || newItemsCount <= 0) {
[self.messageTableView reloadData];
return;
}
if (self.isFlushing) {
//
dispatch_async(dispatch_get_main_queue(), ^{
[self safeApplyInsertsFromStartIndex:startIndex newItemsCount:newItemsCount needReload:NO];
});
return;
}
self.isFlushing = YES;
//
NSInteger beforeRows = [self.messageTableView numberOfRowsInSection:0];
NSInteger expectedRows = [self getCurrentDataSourceCount];
BOOL indexValid = (startIndex >= 0 && startIndex <= beforeRows);
BOOL countValid = (beforeRows + newItemsCount == expectedRows);
if (!indexValid || !countValid) {
[self.messageTableView reloadData];
self.isFlushing = NO;
return;
}
// indexPaths
NSMutableArray<NSIndexPath *> *indexPaths = [NSMutableArray array];
for (NSInteger i = 0; i < newItemsCount; i++) {
[indexPaths addObject:[NSIndexPath indexPathForRow:startIndex + i inSection:0]];
}
//
[self.messageTableView beginUpdates];
@try {
[self.messageTableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
} @catch (__unused NSException *e) {
[self.messageTableView reloadData];
} @finally {
[self.messageTableView endUpdates];
self.isFlushing = NO;
}
}
- (void)changeType:(NSInteger)type {
2024-12-04 21:22:38 +08:00
if (self.displayType == type) {
return;
}
self.displayType = type;
[self.messageTableView reloadData];
if (self.displayType == 1) {
self.messageTableView.tableHeaderView = self.headerView;
} else {
self.messageTableView.tableHeaderView = nil;
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self scrollToBottom:YES];
});
}
/// tag datasource
- (void)updateAllDataSource:(NSArray *)datas {
if (!datas || datas.count == 0) {
//
[self.datasource_chat removeAllObjects];
[self.datasource_gift removeAllObjects];
//
datas = self.datasource;
}
for (XPMessageInfoModel *model in datas) {
switch (model.first) {
case NIMMessageTypeText:
case CustomMessageType_Face:
[self.datasource_chat addObject:model];
break;
case CustomMessageType_Gift:
2024-10-12 19:30:41 +08:00
case CustomMessageType_RoomBoom:
case CustomMessageType_Candy_Tree:
case CustomMessageType_Super_Gift:
case CustomMessageType_AllMicroSend:
[self.datasource_gift addObject:model];
break;
default:
break;
}
}
}
2024-05-11 10:21:48 +08:00
- (UIView *)listView {
return self;
}
2023-10-26 15:20:20 +08:00
- (void)showUserCard:(NSInteger)uid{
[self.messageParser showUserCard:uid];
}
2023-07-14 18:50:55 +08:00
#pragma mark - Response
- (void)messageTipsBtnAction:(UIButton *)sender {
self.isPending = NO;
self.messageTipsBtn.hidden = YES;
[self appendAndScrollToBottom];
}
- (void)atTipsBtnAction:(UIButton *)sender {
self.isPending = YES;
[self appendAndScrollToAtUser];
}
///
- (void)appendAndScrollToAtUser {
//
if (![NSThread isMainThread]) {
dispatch_async(dispatch_get_main_queue(), ^{
[self appendAndScrollToAtUser];
});
return;
}
if (!self.viewReady) {
if (!self.pendingOps) self.pendingOps = [NSMutableArray array];
__weak typeof(self) weakSelf = self;
[self.pendingOps addObject:^{ __strong typeof(weakSelf) self = weakSelf; [self appendAndScrollToAtUser]; }];
return;
}
2024-12-04 21:22:38 +08:00
// 1. incomingMessages
if (self.incomingMessages.count < 1) {
// 2. locationArray
2023-07-14 18:50:55 +08:00
if (self.locationArray.count == 0) {
2024-12-04 21:22:38 +08:00
[self scrollToBottomWithTipsHidden:YES];
return;
2023-07-14 18:50:55 +08:00
}
2024-12-04 21:22:38 +08:00
// 3. @
NSInteger index = [self safeGetIndexFromLocationArrayAt:0];
2024-12-04 21:22:38 +08:00
if (index == NSNotFound) {
[self scrollToBottomWithTipsHidden:YES];
return;
2023-07-14 18:50:55 +08:00
}
2024-12-04 21:22:38 +08:00
// datasource
NSInteger convertedIndex = [self convertDataSourceIndexToCurrentDisplayIndex:index];
if (convertedIndex == NSNotFound) {
2024-12-04 21:22:38 +08:00
[self scrollToBottomWithTipsHidden:YES];
} else {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:convertedIndex inSection:0];
NSInteger currentRows = [self getCurrentDataSourceCount];
if (currentRows > indexPath.row) {
[self.messageTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
if (currentRows == indexPath.row + 1) {
self.messageTipsBtn.hidden = YES;
self.isPending = NO;
}
} else {
[self scrollToBottomWithTipsHidden:YES];
}
2023-07-14 18:50:55 +08:00
}
2024-12-04 21:22:38 +08:00
[self safelyRemoveLocationAtIndex:0];
[self updateAtTipButton];
return;
2023-07-14 18:50:55 +08:00
}
2024-12-04 21:22:38 +08:00
// 4.
BOOL needReloadData = NO;
2024-12-04 21:22:38 +08:00
if (self.datasource.count > kRoomMessageMaxLength) {
NSInteger removedCount = kRoomMessageMaxLength / 2;
[self safelyRemoveMessages:removedCount];
needReloadData = YES; //
2024-12-04 21:22:38 +08:00
}
// 5.
NSInteger currentRows = [self getCurrentDataSourceCount];
// 6.
NSMutableArray *tempNewDatas = @[].mutableCopy;
for (id item in self.incomingMessages) {
2024-12-04 21:22:38 +08:00
XPMessageInfoModel *model = [self parseMessage:item];
if (!model) continue;
[tempNewDatas addObject:model];
[self.datasource addObject:model];
2024-12-04 21:22:38 +08:00
[self processAtMentionsForMessage:item];
2023-07-14 18:50:55 +08:00
}
[self updateAllDataSource:tempNewDatas];
2023-07-14 18:50:55 +08:00
[self.incomingMessages removeAllObjects];
// 7. UITableView
[self safeApplyInsertsFromStartIndex:currentRows newItemsCount:tempNewDatas.count needReload:(needReloadData || self.forceReloadNextAppend)];
self.forceReloadNextAppend = NO;
2023-07-14 18:50:55 +08:00
2024-12-04 21:22:38 +08:00
// 6.
[self scrollToFirstLocationOrBottom];
}
- (void)scrollToBottomWithTipsHidden:(BOOL)hidden {
NSInteger rows = [self getCurrentDataSourceCount];
if (rows > 0) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:(rows - 1) inSection:0];
[self.messageTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}
2024-12-04 21:22:38 +08:00
self.messageTipsBtn.hidden = hidden;
self.isPending = NO;
self.atCount = 0;
self.atTipBtn.hidden = hidden;
}
- (void)updateLocationArrayForMessageRemoval:(NSInteger)removedCount {
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
for (int i = 0; i < self.locationArray.count; i++) {
NSNumber *number = self.locationArray[i];
if (number.integerValue < removedCount) {
self.atCount--;
[indexSet addIndex:i];
2023-07-14 18:50:55 +08:00
}
2024-12-04 21:22:38 +08:00
}
[self.locationArray removeObjectsAtIndexes:indexSet];
for (int i = 0; i < self.locationArray.count; i++) {
NSNumber *number = self.locationArray[i];
self.locationArray[i] = @(number.integerValue - removedCount);
}
}
- (void)updateAtTipButton {
if (self.locationArray.count == 0) {
self.atTipBtn.hidden = YES;
} else {
[self.atTipBtn setTitle:[NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageContainerView0"), (unsigned long)self.locationArray.count] forState:UIControlStateNormal];
self.atTipBtn.hidden = NO;
}
}
- (NSInteger)safeGetIndexFromLocationArrayAt:(NSUInteger)index {
2024-12-04 21:22:38 +08:00
if (index < self.locationArray.count) {
NSNumber *number = self.locationArray[index];
return [number intValue];
}
return NSNotFound; //
}
- (void)safelyRemoveLocationAtIndex:(NSUInteger)index {
if (index < self.locationArray.count) {
[self.locationArray xpSafeRemoveObjectAtIndex:index];
2024-12-04 21:22:38 +08:00
self.atCount = MAX(0, self.atCount - 1);
}
}
- (void)safelyRemoveMessages:(NSInteger)count {
if (self.datasource.count >= count) {
//
2024-12-04 21:22:38 +08:00
NSIndexSet *set = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, count)];
NSArray *removedMessages = [self.datasource objectsAtIndexes:set];
//
2024-12-04 21:22:38 +08:00
[self.datasource removeObjectsAtIndexes:set];
//
for (XPMessageInfoModel *removedModel in removedMessages) {
switch (removedModel.first) {
case NIMMessageTypeText:
case CustomMessageType_Face:
[self.datasource_chat removeObject:removedModel];
break;
case CustomMessageType_Gift:
case CustomMessageType_RoomBoom:
case CustomMessageType_Candy_Tree:
case CustomMessageType_Super_Gift:
case CustomMessageType_AllMicroSend:
[self.datasource_gift removeObject:removedModel];
break;
default:
break;
}
}
2024-12-04 21:22:38 +08:00
// locationArray
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
for (NSUInteger i = 0; i < self.locationArray.count; i++) {
NSNumber *number = self.locationArray[i];
if (number.integerValue < count) {
[indexSet addIndex:i];
} else {
self.locationArray[i] = @(number.integerValue - count);
2023-07-14 18:50:55 +08:00
}
}
2024-12-04 21:22:38 +08:00
[self.locationArray removeObjectsAtIndexes:indexSet];
}
}
- (XPMessageInfoModel *)parseMessage:(id)item {
if ([item isKindOfClass:[NIMMessage class]]) {
return [self.messageParser parseMessageAttribute:item];
} else if ([item isKindOfClass:[NIMBroadcastMessage class]]) {
return [self.messageParser parseBroadcastMessageAttribute:item];
}
return nil;
}
- (void)processAtMentionsForMessage:(id)item {
if ([item isKindOfClass:[NIMMessage class]]) {
NSArray *nickNameInfos = [(NIMMessage *)item remoteExt][@"atUids"];
if ([nickNameInfos isKindOfClass:[NSArray class]]) {
for (NSString *nick in nickNameInfos) {
if ([nick isEqualToString:[AccountInfoStorage instance].getUid]) {
[self.locationArray addObject:@(self.datasource.count - 1)];
}
2023-07-14 18:50:55 +08:00
}
}
}
}
///
- (BOOL)isGiftMessage:(id)messageData {
if ([messageData isKindOfClass:[NIMMessage class]]) {
NIMMessage *message = (NIMMessage *)messageData;
if ([message.messageObject isKindOfClass:[NIMCustomObject class]]) {
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
if (obj.attachment && [obj.attachment isKindOfClass:[AttachmentModel class]]) {
AttachmentModel *attachment = (AttachmentModel *)obj.attachment;
return (attachment.first == CustomMessageType_Gift ||
attachment.first == CustomMessageType_AllMicroSend ||
attachment.first == CustomMessageType_Super_Gift);
}
}
}
return NO;
}
- (NSInteger)getCurrentDataSourceCount {
NSInteger count = 0;
switch (self.displayType) {
case 1:
count = self.datasource.count;
break;
case 2:
count = self.datasource_chat.count;
break;
case 3:
count = self.datasource_gift.count;
break;
default:
count = self.datasource.count;
break;
}
//
return MAX(0, count);
}
- (NSInteger)convertDataSourceIndexToCurrentDisplayIndex:(NSInteger)dataSourceIndex {
if (self.displayType == 1) {
return dataSourceIndex;
}
if (dataSourceIndex >= self.datasource.count) {
return NSNotFound;
}
XPMessageInfoModel *targetModel = [self.datasource objectAtIndex:dataSourceIndex];
if (!targetModel) {
return NSNotFound;
}
NSArray *currentDataSource = nil;
switch (self.displayType) {
case 2:
currentDataSource = self.datasource_chat;
break;
case 3:
currentDataSource = self.datasource_gift;
break;
default:
return dataSourceIndex;
}
//
for (NSInteger i = 0; i < currentDataSource.count; i++) {
XPMessageInfoModel *model = [currentDataSource objectAtIndex:i];
if ([model isEqual:targetModel]) {
return i;
}
}
return NSNotFound;
}
2024-12-04 21:22:38 +08:00
- (void)scrollToFirstLocationOrBottom {
if (self.locationArray.count == 0) {
[self scrollToBottomWithTipsHidden:YES];
return;
}
NSInteger index = [self safeGetIndexFromLocationArrayAt:0];
if (index == NSNotFound) {
[self scrollToBottomWithTipsHidden:YES];
return;
}
// datasource
NSInteger convertedIndex = [self convertDataSourceIndexToCurrentDisplayIndex:index];
if (convertedIndex == NSNotFound) {
2024-12-04 21:22:38 +08:00
[self scrollToBottomWithTipsHidden:YES];
} else {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:convertedIndex inSection:0];
2024-12-04 21:22:38 +08:00
[self.messageTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
[self safelyRemoveLocationAtIndex:0];
}
[self updateAtTipButton];
}
2023-07-14 18:50:55 +08:00
#pragma mark - @
///@
- (void)findAtMeNumber {
if (self.incomingMessages.count) {
NIMMessage *message = self.incomingMessages.lastObject;
if (![message isKindOfClass:[NIMMessage class]] || ![message respondsToSelector:@selector(remoteExt)]) {
return;
}
2023-07-14 18:50:55 +08:00
id nickNameNifo = message.remoteExt[@"atUids"];
if ([nickNameNifo isKindOfClass:[NSArray class]]) {
for (NSString *nick in nickNameNifo) {
if ([nick isEqualToString:[AccountInfoStorage instance].getUid]) {
self.atCount += 1;
}
}
}
if (self.atCount > 0) {
self.atTipBtn.hidden = NO;
[self.atTipBtn setTitle:[NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageContainerView2"), self.atCount] forState:UIControlStateNormal];
} else {
self.atTipBtn.hidden = YES;
}
}
}
#pragma mark - Private Method
- (void)initSubViews {
self.clipsToBounds = YES;
2023-07-14 18:50:55 +08:00
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addCustomMessage:) name:@"message" object:nil];
[self addSubview:self.messageTableView];
[self addSubview:self.messageTipsBtn];
[self addSubview:self.atTipBtn];
self.messageTableView.tableHeaderView = self.headerView;
// flush
self.viewReady = NO;
self.isFlushing = NO;
2023-07-14 18:50:55 +08:00
}
- (void)initSubViewConstraints {
2024-06-04 11:30:58 +08:00
RoomInfoModel *infoModel = self.hostDelegate.getRoomInfo;
CGFloat top = infoModel.type == RoomType_MiniGame ? 0 : 10;
2023-07-14 18:50:55 +08:00
[self.messageTableView mas_makeConstraints:^(MASConstraintMaker *make) {
2024-04-11 17:05:27 +08:00
make.leading.mas_equalTo(self).offset(15);
make.bottom.trailing.mas_equalTo(self);
2024-08-22 11:40:50 +08:00
make.top.equalTo(self).mas_offset(top);
2023-07-14 18:50:55 +08:00
}];
[self.messageTipsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(100);
make.height.mas_equalTo(30);
make.bottom.mas_equalTo(self.mas_bottom).offset(-5);
2024-04-11 17:05:27 +08:00
make.leading.mas_equalTo(self);
2023-07-14 18:50:55 +08:00
}];
[self.atTipBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(100);
make.height.mas_equalTo(30);
make.bottom.mas_equalTo(self.mas_bottom).offset(-5);
2024-04-11 17:05:27 +08:00
make.leading.mas_equalTo(self);
2023-07-14 18:50:55 +08:00
}];
// flush
dispatch_async(dispatch_get_main_queue(), ^{
if (!self.viewReady) {
self.viewReady = YES;
if (self.pendingOps.count > 0) {
NSArray<dispatch_block_t> *ops = [self.pendingOps copy];
[self.pendingOps removeAllObjects];
for (void (^op)(void) in ops) { op(); }
}
}
});
2023-07-14 18:50:55 +08:00
}
2024-08-22 11:40:50 +08:00
2023-07-14 18:50:55 +08:00
///
- (BOOL)isCurrentRoom:(NSString *)sessionId {
if ([sessionId isEqualToString:[NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.roomId]]) {
return YES;
}
return NO;
}
///
- (BOOL)handleHideEnter:(NIMMessage *)message {
NIMMessageChatroomExtension * messageExt = (NIMMessageChatroomExtension *)message.messageExt;
NSDictionary * dic = [(NSDictionary *)messageExt.roomExt.toJSONObject objectForKey:message.from];
XPMessageRemoteExtModel * extModel = [XPMessageRemoteExtModel modelWithJSON:dic];
return (extModel.enterHide || extModel.platformRole == 1);
}
#pragma mark -
///
2024-10-12 19:30:41 +08:00
- (void)addRoomMessage:(id)messageData {
2023-10-26 16:37:53 +08:00
if(self.isLoadHistoryMessage == YES)return;
2024-10-12 19:30:41 +08:00
[self.incomingMessages addObject:messageData];
2025-02-28 19:04:09 +08:00
2024-10-12 19:30:41 +08:00
if ([messageData isKindOfClass:[NIMBroadcastMessage class]]) {
NIMBroadcastMessage *broadcastMessage = (NIMBroadcastMessage *)messageData;
[[XPRoomMiniManager shareManager] saveRoomMessage:broadcastMessage];
} else if ([messageData isKindOfClass:[NIMMessage class]]) {
NIMMessage *message = (NIMMessage *)messageData;
if (!self.isMiniEnter) {///
if (self.hostDelegate.getRoomInfo.isCloseScreen) {
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) {
AttachmentModel *attachment = (AttachmentModel *)obj.attachment;
if (attachment.first == CustomMessageType_Update_RoomInfo &&
attachment.second == Custom_Message_Sub_Update_RoomInfo_MessageState){
[[XPRoomMiniManager shareManager] saveRoomMessage:message];
}
}
} else {
[[XPRoomMiniManager shareManager] saveRoomMessage:message];
}
}
}
2023-07-14 18:50:55 +08:00
if (self.isPending) {
self.messageTipsBtn.hidden = NO;
[self findAtMeNumber];
} else {
// 使
if ([self isGiftMessage:messageData]) {
//
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self appendAndScrollToBottom];
});
} else {
[self appendAndScrollToBottom];
}
2023-07-14 18:50:55 +08:00
}
}
///
- (void)appendAndScrollToBottom {
//
if (![NSThread isMainThread]) {
dispatch_async(dispatch_get_main_queue(), ^{
[self appendAndScrollToBottom];
});
return;
}
if (!self.viewReady) {
if (!self.pendingOps) self.pendingOps = [NSMutableArray array];
__weak typeof(self) weakSelf = self;
[self.pendingOps addObject:^{ __strong typeof(weakSelf) self = weakSelf; [self appendAndScrollToBottom]; }];
return;
}
2023-07-14 18:50:55 +08:00
if (self.incomingMessages.count < 1) {
///atincomeatatat
[self scrollToBottom:YES];
return;
}
BOOL needReloadData = NO;
2023-07-14 18:50:55 +08:00
if (self.datasource.count > kRoomMessageMaxLength) {
NSInteger removedCount = kRoomMessageMaxLength / 2;
[self safelyRemoveMessages:removedCount];
needReloadData = YES; //
2023-07-14 18:50:55 +08:00
}
//
NSInteger currentRows = [self getCurrentDataSourceCount];
NSMutableArray *tempArray = @[].mutableCopy;
@kWeakify(self);
2024-10-12 19:30:41 +08:00
[self.incomingMessages enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
@kStrongify(self);
id model = nil;
2024-10-12 19:30:41 +08:00
if ([obj isKindOfClass:[NIMMessage class]]) {
model = [self.messageParser parseMessageAttribute:(NIMMessage *)obj];
2024-10-12 19:30:41 +08:00
} else if ([obj isKindOfClass:[NIMBroadcastMessage class]]) {
model = [self.messageParser parseBroadcastMessageAttribute:(NIMBroadcastMessage *)obj];
}
if (model) {
[tempArray addObject:model];
[self.datasource addObject:model];
2024-10-12 19:30:41 +08:00
}
}];
2023-07-14 18:50:55 +08:00
[self.incomingMessages removeAllObjects];
[self updateAllDataSource:tempArray];
// 使 reloadData使
[self safeApplyInsertsFromStartIndex:currentRows newItemsCount:tempArray.count needReload:(needReloadData || self.forceReloadNextAppend)];
self.forceReloadNextAppend = NO;
2023-07-14 18:50:55 +08:00
//
//
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self scrollToBottom:NO];
});
2023-07-14 18:50:55 +08:00
}
///
- (void)scrollToBottom:(BOOL)animated {
NSArray *source = @[];
switch (self.displayType) {
case 1:
source = self.datasource;
break;
case 2:
source = self.datasource_chat;
break;
case 3:
source = self.datasource_gift;
break;
default:
source = self.datasource;
break;
}
if(source.count > 0){
NSIndexPath *ip = [NSIndexPath indexPathForRow:source.count-1 inSection:0]; //
//
if (animated) {
// 使 dispatch_async
dispatch_async(dispatch_get_main_queue(), ^{
[self.messageTableView scrollToRowAtIndexPath:ip atScrollPosition:UITableViewScrollPositionBottom animated:YES];
});
} else {
// 使
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
[self.messageTableView scrollToRowAtIndexPath:ip atScrollPosition:UITableViewScrollPositionBottom animated:NO];
} completion:nil];
}
2023-10-17 18:30:14 +08:00
self.atCount = 0;
self.atTipBtn.hidden = YES;
[self.locationArray removeAllObjects];
}
2023-07-14 18:50:55 +08:00
}
///
- (BOOL)isCanDisplayMessage:(NIMMessage *)message {
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) {
AttachmentModel *attachment = (AttachmentModel *)obj.attachment;
if (attachment.first == CustomMessageType_Face && attachment.second == Custom_Message_Sub_Face_Send) {
return NO;
}
2025-02-28 19:04:09 +08:00
if (attachment.first == CustomMessageType_User_Enter_Room && attachment.second == Custom_Message_Sub_User_Enter_Room) {
return NO;
}
if (attachment.first == CustomMessageType_RedPacket) {
return NO;
}
// if (attachment.first == CustomMessageType_Face && attachment.second == Custom_Message_Sub_Face_Send) {
// if ([attachment.data[@"data"] isKindOfClass:[NSArray class]]) {
// NSArray * array = [RoomFaceSendInfoModel modelsWithArray:attachment.data[@"data"]];
// for (int i = 0; i< array.count; i++) {
// RoomFaceSendInfoModel * sendInfo = [array xpSafeObjectAtIndex:i];
// if (sendInfo.resultIndexes.count <=0) {
// return NO;
// }
// }
// }
// }
if (attachment.first == CustomMessageType_Room_PK && attachment.second == Custom_Message_Sub_Room_PK_Manager_Up_Mic) {
2023-07-14 18:50:55 +08:00
if (attachment.data && [attachment.data allKeys].count > 0) {
for (NSDictionary * dic in [attachment.data allValues]) {
RoomPKChooseUserModel * userModel = [RoomPKChooseUserModel modelWithDictionary:dic];
if (userModel.groupType == GroupType_Red || userModel.groupType == GroupType_Blue) {
return YES;
}
}
}
return NO;
} else if(attachment.first == CustomMessageType_Room_Sailing && (attachment.second == Custom_Message_Sub_Sailing_AllRoom_Notify || attachment.second == Custom_Message_Sub_Sailing_InRoom_NeedAllMicSend)) {
RoomSailingPrizeModel * prizeModel = [RoomSailingPrizeModel modelWithDictionary:attachment.data];
if (self.hostDelegate.getUserInfo.userLevelVo.experLevelSeq > prizeModel.userLevelLimit) {
return YES;
}
2023-10-17 18:30:14 +08:00
} else if(attachment.first == CustomMessageType_Room_Album){
return YES;
}else if(attachment.first == CustomMessageType_Gift) {
if(attachment.data[@"isRoomAlbum"] != nil){
2023-10-31 18:02:12 +08:00
BOOL isRoomAlbum = [attachment.data[@"isRoomAlbum"] boolValue];
if(isRoomAlbum == YES){
return NO;
}
2023-10-17 18:30:14 +08:00
}
2024-03-25 14:39:36 +08:00
GiftReceiveInfoModel *info = [GiftReceiveInfoModel modelWithJSON:attachment.data];
GiftInfoModel *giftInfo = info.gift == nil ? info.giftInfo : info.gift;
if (giftInfo == nil) {
2025-03-06 15:26:44 +08:00
giftInfo = [[XPGiftStorage shareStorage] findGiftInfo:info.giftId inRoom:@(info.roomUid).stringValue];
2024-03-25 14:39:36 +08:00
}
if (giftInfo.giftType == GiftType_super){
return NO;
}
}else if(attachment.first == CustomMessageType_AllMicroSend){
GiftReceiveInfoModel *info = [GiftReceiveInfoModel modelWithJSON:attachment.data];
GiftInfoModel *giftInfo = info.gift == nil ? info.giftInfo : info.gift;
if (giftInfo == nil) {
2025-03-06 15:26:44 +08:00
giftInfo = [[XPGiftStorage shareStorage] findGiftInfo:info.giftId inRoom:@(info.roomUid).stringValue];
2024-03-25 14:39:36 +08:00
}
if (giftInfo.giftType == GiftType_super){
return NO;
}
2023-10-17 18:30:14 +08:00
}
2023-07-14 18:50:55 +08:00
return [[[self supportMessageDic] objectForKey:@(attachment.first)] containsObject:@(attachment.second)];
}
return NO;
}
- (NSDictionary *)supportMessageDic {
return @{
@(CustomMessageType_AllMicroSend):
[NSSet setWithObjects:
@(Custom_Message_Sub_AllMicroSend),
@(Custom_Message_Sub_AllMicroLuckySend),
@(Custom_Message_Sub_AllBatchSend),
@(Custom_Message_Sub_AllBatchMicroLuckySend),
nil],
@(CustomMessageType_Gift):
[NSSet setWithObjects:
@(Custom_Message_Sub_Gift_Send),
@(Custom_Message_Sub_Gift_LuckySend),
nil],
@(CustomMessageType_Room_Tip):
[NSSet setWithObjects:
@(Custom_Message_Sub_Room_Tip_ShareRoom),
@(Custom_Message_Sub_Room_Tip_Attention_Owner),
nil],
@(CustomMessageType_Kick_User):
[NSSet setWithObjects:
@(Custom_Message_Sub_Kick_BeKicked),
@(Custom_Message_Sub_Kick_BlackList),
nil],
@(CustomMessageType_Queue):
[NSSet setWithObjects:
@(Custom_Message_Sub_Queue_Kick),
nil],
@(CustomMessageType_Look_Love):
[NSSet setWithObjects:
@(Custom_Message_Sub_Look_Love_Me),
@(Custom_Message_Sub_Look_Love_InRoom),
@(Custom_Message_Sub_Look_Love_AllRoom),
@(Custom_Message_Sub_Look_Love_AllRoom_Notify),
@(Custom_Message_Sub_Look_Love_InRoom_NeedAllMicSend),
nil],
@(CustomMessageType_Arrange_Mic):
[NSSet setWithObjects:
@(Custom_Message_Sub_Arrange_Mic_Mode_Open),
@(Custom_Message_Sub_Arrange_Mic_Mode_Close),
@(Custom_Message_Sub_Arrange_Mic_Free_Mic_Open),
@(Custom_Message_Sub_Arrange_Mic_Free_Mic_Close),
nil],
@(CustomMessageType_Update_RoomInfo):
[NSSet setWithObjects:
@(Custom_Message_Sub_Update_RoomInfo_MessageState),
@(Custom_Message_Sub_Update_RoomInfo_AnimateEffect),
nil],
@(CustomMessageType_Collection_Room):
[NSSet setWithObjects:
@(Custom_Message_Sub_Collect_Room_Tips),
nil],
@(CustomMessageType_RoomPlay_Dating):
[NSSet setWithObjects:
@(Custom_Message_Sub_Room_Play_Dating_Pick_Heart),
@(Custom_Message_Sub_Room_Play_Dating_Result_Mutual),
@(Custom_Message_Sub_Room_Play_Dating_Result_Not_Mutual),
nil],
@(CustomMessageType_Noble_VIP):
[NSSet setWithObjects:
@(Custom_Message_Sub_Room_Open_Noble_VIP),
@(Custom_Message_Sub_Room_Noble_LevelUp),
@(Custom_Message_Sub_AllRoom_Noble_LevelUp_Suspend),
nil],
@(CustomMessageType_Face):
[NSSet setWithObjects:
@(Custom_Message_Sub_Face_Send),
nil],
@(CustomMessageType_Anchor_FansTeam):
[NSSet setWithObjects:
@(Custom_Message_Sub_FansTeam_Open_Success),
@(Custom_Message_Sub_FansTeam_Open_Fail),
@(Custom_Message_Sub_FansTeam_Join_Success),
@(Custom_Message_Sub_FansTeam_Out_Success),
nil],
@(CustomMessageType_Hall_Super_Admin):
[NSSet setWithObjects:
@(Custom_Message_Sub_Hall_Super_Admin_Kick_Manager_Out_Room),
nil],
@(CustomMessageType_Room_PK):
[NSSet setWithObjects:
@(Custom_Message_Sub_Room_PK_Manager_Up_Mic),
@(Custom_Message_Sub_Room_PK_Mode_Close),
@(Custom_Message_Sub_Room_PK_Result),
@(Custom_Message_Sub_Room_PK_Mode_Open),
@(Custom_Message_Sub_Room_PK_Start),
@(Custom_Message_Sub_Room_PK_Re_Start),
nil],
@(CustomMessageType_LuckyBag):
[NSSet setWithObjects:
@(Custom_Message_Sub_Room_Gift_LuckBag_Server),
2024-05-07 19:40:21 +08:00
@(Custom_Message_Sub_Room_Gift_LuckBag_FullScree),
2023-07-14 18:50:55 +08:00
nil],
@(CustomMessageType_Gift_Compound):
[NSSet setWithObjects:@(Custom_Message_Sub_Gift_Compound),
nil],
@(CustomMessageType_Tarot):
[NSSet setWithObjects:
2023-09-14 11:16:47 +08:00
@(Custom_Message_Sub_Tarot_Novice),
@(Custom_Message_Sub_Tarot_Advanced),
@(Custom_Message_Sub_Tarot_Intermediate),
nil],
2023-07-14 18:50:55 +08:00
@(CustomMessageType_Room_Sailing):
[NSSet setWithObjects:
@(Custom_Message_Sub_Sailing_Me),
@(Custom_Message_Sub_Sailing_InRoom),
@(Custom_Message_Sub_Sailing_AllRoom),
@(Custom_Message_Sub_Sailing_AllRoom_Notify),
@(Custom_Message_Sub_Sailing_InRoom_NeedAllMicSend),
nil],
@(CustomMessageType_RedPacket):
[NSSet setWithObjects:
@(Custom_Message_Sub_OpenRedPacketSuccess),
2025-02-28 19:04:09 +08:00
@(Custom_Message_Sub_LuckyPackage),
2023-07-14 18:50:55 +08:00
nil],
2024-02-23 14:40:10 +08:00
@(CustomMessageType_General_Public_Screen):
[NSSet setWithObjects:
@(Custom_Message_Sub_General_Public_Screen_One_Room),
@(Custom_Message_Sub_General_Public_Screen_All_Room),
nil],
2024-03-25 14:39:36 +08:00
@(CustomMessageType_Super_Gift):
[NSSet setWithObjects:
@(Custom_Message_Sub_Super_Gift),
@(Custom_Message_Sub_Super_Gift_Room_Message),
2024-03-25 14:39:36 +08:00
nil],
2023-07-14 18:50:55 +08:00
};
}
- (void)addCustomMessage:(NSNotification *)notification {
self.isMiniEnter = NO;
if (self.hostDelegate.getRoomInfo.isCloseScreen) {return;}
NIMMessage * message = notification.object;
[self addRoomMessage:message];
}
///
- (void)createUserEnterRoomAddRoomTopicMessage {
if ([ClientConfig shareConfig].configInfo.hideNoticeVersion == YES) {
2023-07-14 18:50:55 +08:00
return;
}
RoomInfoModel * roomInfo = self.hostDelegate.getRoomInfo;
if (roomInfo.uid == [AccountInfoStorage instance].getUid.integerValue) {return;}
NSString * key = [NSString stringWithFormat:@"%@_%@_%ld", kRoomShowTopicKey, [AccountInfoStorage instance].getUid, roomInfo.uid];
NSDate * oldDate = [[NSUserDefaults standardUserDefaults] valueForKey:key];
NSDate * date = [NSDate date];
if (roomInfo.introduction.length > 0) {
if (oldDate) {
NSDateComponents *compons = [PLTimeUtil compareTwoDate:date secondDate:[NSDate date]];
if (ABS(compons.year) > 0 || ABS(compons.month) > 0 || ABS(compons.day) > 0) {
NIMMessage * message = [[NIMMessage alloc] init];
NIMTipObject *tipObject = [[NIMTipObject alloc] init];
message.messageObject = tipObject;
2023-08-09 11:55:27 +08:00
NSString * content = [NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageContainerView3"), roomInfo.introduction];
2023-07-14 18:50:55 +08:00
message.text = content;
message.localExt = @{@"isRoomTopic": @(NO)};
[message setValue:@(NIMMessageTypeTip) forKey:@"messageType"];
[message setValue:[NIMSession session:[NSString stringWithFormat:@"%ld", roomInfo.roomId] type:NIMSessionTypeChatroom] forKey:@"session"];
[self addRoomMessage:message];
[[NSUserDefaults standardUserDefaults] setValue:@(YES) forKey:key];
[[NSUserDefaults standardUserDefaults] synchronize];
}
} else {
NIMMessage * message = [[NIMMessage alloc] init];
2023-08-09 11:55:27 +08:00
NSString * content = [NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageContainerView3"), roomInfo.introduction];
2023-07-14 18:50:55 +08:00
message.text = content;
message.localExt = @{@"isRoomTopic": @(NO)};
[message setValue:@(NIMMessageTypeTip) forKey:@"messageType"];
[message setValue:[NIMSession session:[NSString stringWithFormat:@"%ld", roomInfo.roomId] type:NIMSessionTypeChatroom] forKey:@"session"];
[self addRoomMessage:message];
[[NSUserDefaults standardUserDefaults] setValue:@(YES) forKey:key];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
NIMMessage * message = [[NIMMessage alloc] init];
NIMTipObject *tipObject = [[NIMTipObject alloc] init];
message.messageObject = tipObject;
2023-07-14 18:50:55 +08:00
message.text = YMLocalizedString(@"XPRoomMessageContainerView5");
message.localExt = @{@"isRoomTopic": @(YES)};
[message setValue:@(NIMMessageTypeTip) forKey:@"messageType"];
[message setValue:[NIMSession session:[NSString stringWithFormat:@"%ld", roomInfo.roomId] type:NIMSessionTypeChatroom] forKey:@"session"];
[self addRoomMessage:message];
}
2024-10-12 19:30:41 +08:00
- (void)handleBroadcastMessageAttachment:(AttachmentModel *)attachment; {
// if (attachment.first == CustomMessageType_RoomBoom) {
// Boom632Model *m = [Boom632Model modelWithJSON:attachment.data];
// NIMMessage * message = [[NIMMessage alloc] init];
// message.text = YMLocalizedString(@"XPRoomMessageContainerView5");
// message.localExt = @{@"isRoomTopic": @(YES)};
// [message setValue:@(NIMMessageTypeTip) forKey:@"messageType"];
// [message setValue:[NIMSession session:[NSString stringWithFormat:@"%ld", roomInfo.roomId] type:NIMSessionTypeChatroom] forKey:@"session"];
// [self addRoomMessage:message];
// }
}
- (void)handleBroadcastMessage:(NIMBroadcastMessage *)message {
[self addRoomMessage:message];
}
2023-07-14 18:50:55 +08:00
#pragma mark - RoomGuestDelegate
2023-08-25 16:32:51 +08:00
- (void)handleNIMCustomAttachment:(AttachmentModel *)attachment{
}
2023-07-14 18:50:55 +08:00
- (void)handleNIMCustomMessage:(NIMMessage *)message {
self.isMiniEnter = NO;
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
2025-02-28 19:04:09 +08:00
//
2023-07-14 18:50:55 +08:00
if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) {
AttachmentModel *attachment = (AttachmentModel *)obj.attachment;
2025-02-28 19:04:09 +08:00
switch (attachment.first) {
case CustomMessageType_Update_RoomInfo: {
if (attachment.second == Custom_Message_Sub_Update_RoomInfo_MessageState) {
[self.datasource removeAllObjects];
[self updateAllDataSource:nil];
[self.incomingMessages removeAllObjects];
[self.locationArray removeAllObjects];
self.forceReloadNextAppend = YES;
2025-02-28 19:04:09 +08:00
self.atCount = 0;
self.atTipBtn.hidden = YES;
self.messageTipsBtn.hidden = YES;
self.isPending = NO;
[[XPRoomMiniManager shareManager] resetLocalMessage];
[self addRoomMessage:message];
} else if (attachment.second == Custom_Message_Sub_Update_RoomInfo_CleanScreen) {
[self.datasource removeAllObjects];
[self updateAllDataSource:nil];
[self.incomingMessages removeAllObjects];
[self.locationArray removeAllObjects];
self.forceReloadNextAppend = YES;
2025-02-28 19:04:09 +08:00
self.atCount = 0;
self.atTipBtn.hidden = YES;
self.messageTipsBtn.hidden = YES;
self.isPending = NO;
[[XPRoomMiniManager shareManager] resetLocalMessage];
[self addRoomMessage:message];
}
}
break;
case CustomMessageType_Candy_Tree: {
if(attachment.second == Custom_Message_Sub_Candy_Tree_Me) {
CandyTreeGiftInfoModel * model = [CandyTreeGiftInfoModel modelWithDictionary:attachment.data];
if (model.uid.integerValue != [AccountInfoStorage instance].getUid.integerValue) {
return;
}
}
}
break;
case CustomMessageType_Kick_User: {
NSString * uid = [AccountInfoStorage instance].getUid;
NSString * roomId = [NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.roomId];
NIMChatroomMembersByIdsRequest *request = [[NIMChatroomMembersByIdsRequest alloc]init];
request.roomId = roomId;
request.userIds = @[uid];
[[NIMSDK sharedSDK].chatroomManager fetchChatroomMembersByIds:request completion:^(NSError * _Nullable error, NSArray<NIMChatroomMember *> * _Nullable members) {
if (error == nil) {
NIMChatroomMember * member = members.firstObject;
BOOL isCreator = member.type == NIMChatroomMemberTypeCreator;
BOOL isManager = member.type == NIMChatroomMemberTypeManager;
if (isCreator || isManager) {
[self addRoomMessage:message];
}
}
}];
}
break;
case CustomMessageType_Hall_Super_Admin: {
[self addRoomMessage:message];
}
break;
case CustomMessageType_RedPacket: {
NSDictionary *data = attachment.data;
if (data) {
NSInteger currentRoomUID = self.hostDelegate.getRoomInfo.uid;
NSNumber *messageRoomUI = [data objectForKey:@"roomUid"];
if (messageRoomUI) {
if (currentRoomUID == messageRoomUI.integerValue) {
[self addRoomMessage:message];
}
}
}
}
break;
case CustomMessageType_User_Enter_Room: {
if (attachment.second == Custom_Message_Sub_Pic_Message) {
[self addRoomMessage:message];
} else if (attachment.second == Custom_Message_Sub_User_Enter_Room) {
RoomEnterModel *model = [RoomEnterModel modelWithJSON:attachment.data];
if (model.screenType == 1 || model.enterHide == 1) {
return;
}
for (int index = 0; index<model.cpList.count; index++) {
2025-02-28 19:04:09 +08:00
attachment.seq = index;
index += 1;
[(NIMCustomObject *)message.messageObject setAttachment:attachment];
2023-07-14 18:50:55 +08:00
[self addRoomMessage:message];
}
}
2025-02-28 19:04:09 +08:00
}
break;
case CustomMessageType_Face: {
// MARK:
NSInteger delay = -1;
if ([message.messageObject isKindOfClass:[NIMCustomObject class]]) {
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
AttachmentModel *attachment =(AttachmentModel *)obj.attachment;
if (attachment.second == Custom_Message_Sub_Face_Send) {
NSArray *datas = [attachment.data objectForKey:@"data"];
NSDictionary *obj = [datas xpSafeObjectAtIndex:0];
if (obj) {
NSArray *results = [obj objectForKey:@"resultIndexes"];
if ([results isKindOfClass:[NSArray class]] && results.count > 0) {
delay = 2.5;
}
}
}
}
if (delay > 0 ) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self addRoomMessage:message];
});
}
}
break;
2025-02-28 19:04:09 +08:00
default:
break;
2023-07-14 18:50:55 +08:00
}
}
2023-07-14 18:50:55 +08:00
if (self.hostDelegate.getRoomInfo.isCloseScreen) {
return;
}
// isCanDisplayMessage
2023-07-14 18:50:55 +08:00
if ([self isCanDisplayMessage:message]) {
[self addRoomMessage:message];
}
}
- (void)handleNIMNotificationMessage:(NIMMessage *)message {
self.isMiniEnter = NO;
NIMNotificationObject *notiMsg = (NIMNotificationObject *)message.messageObject;
2025-01-07 20:07:54 +08:00
if (![notiMsg.content isKindOfClass:[NIMChatroomNotificationContent class]]) {
return;
}
2023-07-14 18:50:55 +08:00
NIMChatroomNotificationContent *content = (NIMChatroomNotificationContent *)notiMsg.content;
2024-12-16 19:41:23 +08:00
RoomInfoModel *roomInfo = self.hostDelegate.getRoomInfo;
2023-07-14 18:50:55 +08:00
if (content.eventType == NIMChatroomEventTypeEnter) {
2023-10-31 18:02:12 +08:00
2023-07-14 18:50:55 +08:00
if (roomInfo.isCloseScreen) {
2023-10-31 18:02:12 +08:00
self.isLoadHistoryMessage = NO;
AttachmentModel *attachment = [[AttachmentModel alloc]init];
attachment.first = CustomMessageType_Update_RoomInfo;
attachment.second = Custom_Message_Sub_Update_RoomInfo_MessageState;
attachment.data = @{@"roomInfo":self.hostDelegate.getRoomInfo.model2dictionary};
2023-07-14 18:50:55 +08:00
NIMMessage *message = [[NIMMessage alloc]init];
NIMCustomObject *object = [[NIMCustomObject alloc] init];
object.attachment = attachment;
2023-07-14 18:50:55 +08:00
message.messageObject = object;
[self addRoomMessage:message];
return;
} else {
NIMChatroomNotificationMember *member = content.targets[0];
if (member.userId.integerValue == [AccountInfoStorage instance].getUid.integerValue) {
///
2023-11-01 10:36:21 +08:00
if(self.datasource.count > 0)
{
self.isLoadHistoryMessage = NO;
return;
}
2023-07-14 18:50:55 +08:00
[self handleFetchHistoryMessage:message];
} else {
2023-10-31 18:02:12 +08:00
self.isLoadHistoryMessage = NO;
2023-07-14 18:50:55 +08:00
BOOL hideEnter = [self handleHideEnter:message];
if (!hideEnter) {
///
[self addRoomMessage:message];
}
}
}
} else if(content.eventType == NIMChatroomEventTypeInfoUpdated) {
if (roomInfo.isCloseScreen) {return;}
if (roomInfo.datingState == RoomDatingStateChangeType_Open) {
NSString * uid = [AccountInfoStorage instance].getUid;
NSString * roomId = [NSString stringWithFormat:@"%ld", roomInfo.roomId];
NIMChatroomMembersByIdsRequest *request = [[NIMChatroomMembersByIdsRequest alloc]init];
request.roomId = roomId;
request.userIds = @[uid];
[[NIMSDK sharedSDK].chatroomManager fetchChatroomMembersByIds:request completion:^(NSError * _Nullable error, NSArray<NIMChatroomMember *> * _Nullable members) {
if (error == nil) {
NIMChatroomMember * member = members.firstObject;
BOOL isCreator = member.type == NIMChatroomMemberTypeCreator;
BOOL isManager = member.type == NIMChatroomMemberTypeManager;
if (isCreator || isManager) {
[self addRoomMessage:message];
}
}
}];
2025-01-22 21:22:58 +08:00
}// else if (roomInfo)
2023-07-14 18:50:55 +08:00
}
}
- (void)handleFetchNewestMessage:(NIMMessage *)message {
RoomInfoModel * roomInfo = self.hostDelegate.getRoomInfo;
NSString *roomId = [NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.roomId];
NIMHistoryMessageSearchOption *option = [[NIMHistoryMessageSearchOption alloc] init];
option.limit = [ClientConfig shareConfig].configInfo.roomMessageCount;
option.order = NIMMessageSearchOrderDesc;
option.messageTypes = @[@(NIMMessageTypeText),@(NIMMessageTypeCustom)];
@kWeakify(self);
[[NIMSDK sharedSDK].chatroomManager fetchMessageHistory:roomId
option:option
result:^(NSError * _Nullable error, NSArray<NIMMessage *> * _Nullable messages) {
@kStrongify(self);
if(error != nil){
self.isLoadHistoryMessage = NO;
}
if (self.datasource.count > kRoomMessageMaxLength) {
NSIndexSet *set = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, kRoomMessageMaxLength/2)];
NSArray *needRemoveMsgArray = [self.datasource objectsAtIndexes:set];
[self.datasource removeObjectsInArray:needRemoveMsgArray];
}
//
for (NIMMessage *item in messages.reverseObjectEnumerator) {
[self dealWithHistoryDataWithMessage:item];
}
self.isLoadHistoryMessage = NO;
BOOL hideEnter = [self handleHideEnter:message];
if (!hideEnter) {
///
[self addRoomMessage:message];
}
if (!roomInfo.hasAnimationEffect) {
[self roomInfoNoGiftAnimationMessage:message];
}
[self createUserEnterRoomAddRoomTopicMessage];
[self updateAllDataSource:nil];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.messageTableView reloadData];
[self scrollToBottom:YES];
});
}];
}
2023-07-14 18:50:55 +08:00
- (void)handleFetchHistoryMessage:(NIMMessage *)message {
RoomInfoModel * roomInfo = self.hostDelegate.getRoomInfo;
NSString *roomId = [NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.roomId];
NIMHistoryMessageSearchOption *option = [[NIMHistoryMessageSearchOption alloc] init];
option.limit = [ClientConfig shareConfig].configInfo.roomMessageCount;
option.startTime = self.hostDelegate.getRoomInfo.clearScreenTime / 1000.0;
option.order = NIMMessageSearchOrderAsc;
2023-10-25 11:28:28 +08:00
option.messageTypes = @[@(NIMMessageTypeText),@(NIMMessageTypeCustom)];
[[NIMSDK sharedSDK].chatroomManager fetchMessageHistory:roomId
option:option
result:^(NSError * _Nullable error, NSArray<NIMMessage *> * _Nullable messages) {
2023-10-31 18:02:12 +08:00
if(error != nil){
self.isLoadHistoryMessage = NO;
2023-10-31 18:02:12 +08:00
}
2023-07-14 18:50:55 +08:00
if (messages.count) {
//50
if (messages.count == [ClientConfig shareConfig].configInfo.roomMessageCount) {
[self handleFetchNewestMessage:message];
} else {
if (self.datasource.count > kRoomMessageMaxLength) {
NSIndexSet *set = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, kRoomMessageMaxLength/2)];
NSArray *needRemoveMsgArray = [self.datasource objectsAtIndexes:set];
[self.datasource removeObjectsInArray:needRemoveMsgArray];
}
//
for (NIMMessage *item in messages) {
[self dealWithHistoryDataWithMessage:item];
}
self.isLoadHistoryMessage = NO;
BOOL hideEnter = [self handleHideEnter:message];
if (!hideEnter) {
///
[self addRoomMessage:message];
}
if (!roomInfo.hasAnimationEffect) {
[self roomInfoNoGiftAnimationMessage:message];
}
[self createUserEnterRoomAddRoomTopicMessage];
[self updateAllDataSource:nil];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.messageTableView reloadData];
[self scrollToBottom:YES];
});
}
2023-10-26 16:37:53 +08:00
}else{
dispatch_async(dispatch_get_main_queue(), ^{///线
self.isLoadHistoryMessage = NO;
BOOL hideEnter = [self handleHideEnter:message];
if (!hideEnter) {
///
[self addRoomMessage:message];
}
if (!roomInfo.hasAnimationEffect) {
[self roomInfoNoGiftAnimationMessage:message];
}
[self createUserEnterRoomAddRoomTopicMessage];
2023-10-26 16:37:53 +08:00
});
2023-07-14 18:50:55 +08:00
}
2023-10-26 16:37:53 +08:00
2023-07-14 18:50:55 +08:00
}];
}
2023-10-25 11:28:28 +08:00
-(void)dealWithHistoryDataWithMessage:(NIMMessage *)item{
BOOL isHaveSave = NO;
if(item.messageType == NIMMessageTypeText){
isHaveSave = YES;
}else if(item.messageType == NIMMessageTypeCustom){
NIMCustomObject *obj = (NIMCustomObject *)item.messageObject;
if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) {
AttachmentModel *attachment = (AttachmentModel *)obj.attachment;
if (attachment.first == CustomMessageType_Room_Album && attachment.second == Custom_Message_Sub_Room_Album) {
isHaveSave = YES;
2025-02-28 19:04:09 +08:00
} else if (attachment.first == CustomMessageType_User_Enter_Room && attachment.second == Custom_Message_Sub_Pic_Message) {
isHaveSave = YES;
2023-10-25 11:28:28 +08:00
}
}
}
if(isHaveSave == NO)return;
[self.datasource addObject:[self.messageParser parseMessageAttribute:item]];
if (!self.isMiniEnter) {///
if (self.hostDelegate.getRoomInfo.isCloseScreen) {
NIMCustomObject *obj = (NIMCustomObject *)item.messageObject;
if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) {
AttachmentModel *attachment = (AttachmentModel *)obj.attachment;
if (attachment.first == CustomMessageType_Update_RoomInfo && attachment.second == Custom_Message_Sub_Update_RoomInfo_MessageState){
[[XPRoomMiniManager shareManager] saveRoomMessage:item];
}
}
} else {
[[XPRoomMiniManager shareManager] saveRoomMessage:item];
}
}
}
2023-07-14 18:50:55 +08:00
- (void)handleNIMTextMessage:(NIMMessage *)message {
self.isMiniEnter = NO;
if (self.hostDelegate.getRoomInfo.isCloseScreen) {return;}
[self addRoomMessage:message];
}
- (void)roomInfoNoGiftAnimationMessage:(NIMMessage *)message {
self.isMiniEnter = NO;
AttachmentModel *attachement = [[AttachmentModel alloc]init];
attachement.first = CustomMessageType_Update_RoomInfo;
attachement.second = Custom_Message_Sub_Update_RoomInfo_AnimateEffect;
NIMMessage *tempMessage = [[NIMMessage alloc]init];
NIMCustomObject *customObject = [[NIMCustomObject alloc]init];
customObject.attachment = attachement;
tempMessage.messageObject = customObject;
[self addRoomMessage:tempMessage];
}
- (void)onRoomMiniEntered {
self.isMiniEnter = YES;
2023-10-31 19:35:39 +08:00
self.isLoadHistoryMessage = NO;
2023-07-14 18:50:55 +08:00
///
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSMutableArray *tempArray = @[].mutableCopy;
2023-07-14 18:50:55 +08:00
NSArray * temArray = [XPRoomMiniManager shareManager].getLocalCurrentRoomMessage;
2024-10-12 19:30:41 +08:00
[temArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
id model = nil;
2024-10-12 19:30:41 +08:00
if ([obj isKindOfClass:[NIMMessage class]]) {
model = [self.messageParser parseMessageAttribute:(NIMMessage *)obj];
2024-10-12 19:30:41 +08:00
} else if ([obj isKindOfClass:[NIMBroadcastMessage class]]) {
model = [self.messageParser parseBroadcastMessageAttribute:(NIMBroadcastMessage *)obj];
}
if (model) {
[tempArray addObject:model];
[self.datasource addObject:model];
2024-10-12 19:30:41 +08:00
}
}];
[self updateAllDataSource:tempArray];
2023-07-14 18:50:55 +08:00
[self.messageTableView reloadData];
//
[self scrollToBottom:YES];
});
}
- (void)onRoomEntered {
[[XPRoomMiniManager shareManager] resetLocalMessage];
2024-05-22 12:06:48 +08:00
self.headerView.bubbleColor = self.hostDelegate.getRoomInfo.type == RoomType_MiniGame ? [UIColor colorWithWhite:1 alpha:0.2] : [UIColor colorWithWhite:1 alpha:0.3];
2023-07-14 18:50:55 +08:00
}
- (void)onRoomUpdate {
///
if (self.hostDelegate.getRoomInfo.hadChangeRoomType) {
2024-05-22 12:06:48 +08:00
self.headerView.bubbleColor = self.hostDelegate.getRoomInfo.type == RoomType_MiniGame ? [UIColor colorWithWhite:1 alpha:0.2] : [UIColor colorWithWhite:1 alpha:0.3];
2023-07-14 18:50:55 +08:00
[self.messageTableView reloadData];
}
2024-06-04 10:43:58 +08:00
RoomInfoModel *infoModel = self.hostDelegate.getRoomInfo;
2024-06-04 11:30:58 +08:00
CGFloat top = infoModel.type == RoomType_MiniGame ? 0 : 10;
[self.messageTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(self).offset(15);
make.bottom.trailing.mas_equalTo(self);
2024-08-22 11:40:50 +08:00
make.top.equalTo(self).mas_offset(top);
2024-06-04 11:30:58 +08:00
}];
2023-07-14 18:50:55 +08:00
}
#pragma mark - ScrollViewDelegate
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
//
self.isPending = YES;
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
// decelerate01,DidEndDecelerating
if (!decelerate) {
[self finishDraggingWith:scrollView];
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
//
[self finishDraggingWith:scrollView];
}
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
if (!self.isPending && self.incomingMessages.count <= 0) {
[self scrollToBottom:YES];
}
}
/**
()
*/
- (void)finishDraggingWith:(UIScrollView *)scrollView {
CGFloat contentSizeH = scrollView.contentSize.height;
CGFloat contentOffsetY = scrollView.contentOffset.y;
CGFloat sizeH = scrollView.frame.size.height;
self.isPending = contentSizeH - contentOffsetY - sizeH > 20.0;
if (!self.isPending) {
self.messageTipsBtn.hidden = YES;
self.atTipBtn.hidden = YES;
self.atCount = 0;
[self.locationArray removeAllObjects];
if (self.incomingMessages.count > 0) {
[self appendAndScrollToBottom];
}
}
[[NSNotificationCenter defaultCenter] postNotificationName:@"roomMessageTabelViewStopScroll" object:nil];
}
#pragma mark - UITableViewDelegate And UITableViewDataSource
2024-11-29 21:50:24 +08:00
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSArray *source = @[];
switch (self.displayType) {
case 1:
source = self.datasource;
break;
case 2:
source = self.datasource_chat;
break;
case 3:
source = self.datasource_gift;
break;
default:
source = self.datasource;
break;
}
XPMessageInfoModel *model = [source xpSafeObjectAtIndex:indexPath.row];
// 使 UITableViewAutomaticDimension
if (model.rowHeight <= 0) {
[self calculateRowHeightForModel:model];
2024-11-29 21:50:24 +08:00
}
if (model.first == CustomMessageType_RedPacket && model.second == Custom_Message_Sub_LuckyPackage) {
return model.rowHeight;
}
2024-11-29 21:50:24 +08:00
return model.rowHeight + 20;
}
//
- (void)calculateRowHeightForModel:(XPMessageInfoModel *)model {
if (!model || !model.content) {
model.rowHeight = 44; //
return;
}
// 使 YYTextLayout
YYTextContainer *container = [YYTextContainer new];
container.size = CGSizeMake(kRoomMessageMaxWidth - 24, MAXFLOAT);
container.maximumNumberOfRows = 0;
YYTextLayout *layout = [YYTextLayout layoutWithContainer:container text:model.content];
model.rowHeight = layout.textBoundingSize.height;
//
if (model.rowHeight < 44) {
model.rowHeight = 44;
}
2024-11-29 21:50:24 +08:00
}
2024-10-12 19:30:41 +08:00
2023-07-14 18:50:55 +08:00
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSInteger count = 0;
switch (self.displayType) {
case 1:
count = self.datasource.count;
break;
case 2:
count = self.datasource_chat.count;
break;
case 3:
count = self.datasource_gift.count;
break;
default:
count = self.datasource.count;
break;
}
//
return MAX(0, count);
}
2023-07-14 18:50:55 +08:00
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSArray *source = @[];
switch (self.displayType) {
case 1:
source = self.datasource;
break;
case 2:
source = self.datasource_chat;
break;
case 3:
source = self.datasource_gift;
break;
default:
source = self.datasource;
break;
}
XPMessageInfoModel *model = [source xpSafeObjectAtIndex:indexPath.row];
NSString *cellKey = [NSString isEmpty:model.cellKey] ? NSStringFromClass([XPRoomMessageTableViewCell class]) : model.cellKey;
2025-02-28 19:04:09 +08:00
if(model.first == CustomMessageType_Room_Album ||
(model.first == CustomMessageType_User_Enter_Room && model.second == Custom_Message_Sub_Pic_Message)){
PIRoomMessagePhotoAlbumCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([PIRoomMessagePhotoAlbumCell class])];
cell.delegate = self;
cell.messageInfo = model;
cell.roomType = self.hostDelegate.getRoomInfo.type;
return cell;
2025-02-28 19:04:09 +08:00
} else if (model.first == CustomMessageType_RedPacket && model.second == Custom_Message_Sub_LuckyPackage) {
LuckyPackageMessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LuckyPackageMessageTableViewCell" forIndexPath:indexPath];
cell.dataSource = model.customInfo;
return cell;
} else if (model.first == CustomMessageType_User_Enter_Room && model.second == Custom_Message_Sub_User_Enter_Room) {
CPEnterRoomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CPEnterRoomTableViewCell" forIndexPath:indexPath];
cell.cpIndex = [[model.customInfo objectForKey:@"cpIndex"] integerValue];
cell.dataSource = model.customInfo;
return cell;
2024-10-12 19:30:41 +08:00
}
else if (model.isBoom) {
cellKey = @"XPRoomMessageTableViewCell_Boom";
}
XPRoomMessageTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellKey];
cell.delegate = self;
cell.isLeftBigImage = model.isBoom;
2024-10-12 19:30:41 +08:00
cell.messageInfo = model;
cell.roomType = self.hostDelegate.getRoomInfo.type;
return cell;
}
//- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
// NSArray *source = @[];
// switch (self.displayType) {
// case 1:
// source = self.datasource;
// break;
// case 2:
// source = self.datasource_chat;
// break;
// case 3:
// source = self.datasource_gift;
// break;
//
// default:
// source = self.datasource;
// break;
// }
// XPMessageInfoModel *model = [source xpSafeObjectAtIndex:indexPath.row];
// if (model.rowHeight == 0) {
// model.rowHeight = CGRectGetHeight(cell.frame);
// }
//}
2024-06-04 14:54:51 +08:00
2023-07-14 18:50:55 +08:00
#pragma mark - XPRoomMessageTableViewCellDelegate
- (void)xPRoomMessageTableViewCellDidTapEmpty:(XPRoomMessageTableViewCell *)view {
2024-06-04 14:54:51 +08:00
if (self.delegate && [self.delegate respondsToSelector:@selector(xPRoomMessageContainerViewlDidTapEmpty:)]) {
[self.delegate xPRoomMessageContainerViewlDidTapEmpty:self];
}
}
-(void)clickDidTapEmptyAction{
if (self.delegate && [self.delegate respondsToSelector:@selector(xPRoomMessageContainerViewlDidTapEmpty:)]) {
[self.delegate xPRoomMessageContainerViewlDidTapEmpty:self];
}
2023-07-14 18:50:55 +08:00
}
2023-10-13 17:20:50 +08:00
#pragma mark - PIRoomMessagePhotoAlbumCell
- (void)pIRoomMessagePhotoAlbumCellDelegateDidTapEmpty:(PIRoomMessagePhotoAlbumCell *)view{
2024-06-04 14:54:51 +08:00
if (self.delegate && [self.delegate respondsToSelector:@selector(xPRoomMessageContainerViewlDidTapEmpty:)]) {
[self.delegate xPRoomMessageContainerViewlDidTapEmpty:self];
2023-10-17 18:30:14 +08:00
}
}
-(void)unlockAlbumHandleWithInfo:(PIRoomPhotoAlbumItemModel *_Nonnull)info{
2023-10-13 17:20:50 +08:00
PIRoomMessageUnlockPhotoAlbumView *albumView = [[PIRoomMessageUnlockPhotoAlbumView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
2023-10-17 18:30:14 +08:00
albumView.albumModel = info;
albumView.delegate = self;
2023-10-13 17:20:50 +08:00
[TTPopup popupView:albumView style:TTPopupStyleAlert];
}
2023-10-17 18:30:14 +08:00
-(void)pIRoomMessagePhotoAlbumCell:(PIRoomMessagePhotoAlbumCell *_Nonnull)cell lookUpAlbumPhotoWithAlbumModel:(PIRoomPhotoAlbumItemModel *_Nonnull)albumModel;{
SDPhotoBrowser *browser = [[SDPhotoBrowser alloc]init];
browser.sourceImagesContainerView = cell;
browser.delegate = self;
browser.imageCount = 1;
browser.currentImageIndex = 0;
browser.isMe = NO;
self.lookUpModel = albumModel;
[browser show];
}
2023-10-18 15:11:56 +08:00
- (void)pIRoomMessagePhotoAlbumCell:(PIRoomMessagePhotoAlbumCell *)cell lookUpUserCardModel:(PIRoomPhotoAlbumItemModel *)albumModel{
[self.messageParser showUserCard:albumModel.uid.integerValue];
}
2023-10-17 18:30:14 +08:00
#pragma mark - PIRoomMessageUnlockPhotoAlbumViewDelegate
- (void)unlockRoomAlbumImageWithAlbumModel:(PIRoomPhotoAlbumItemModel *)albumModel{
[XNDJTDDLoadingTool showLoading];
[Api unlockRoomAlbumPhoto:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
[XNDJTDDLoadingTool hideHUD];
if(code == 200){
NSMutableDictionary *getData = [NSMutableDictionary dictionary];
[getData addEntriesFromDictionary:data.data];
AttachmentModel *attachment = [[AttachmentModel alloc] init];
attachment.first = CustomMessageType_Gift;
attachment.second = Custom_Message_Sub_Gift_Send;
NSDictionary *targetUsers = ((NSArray *)[getData objectForKey:@"targetUsers"]).firstObject;
[getData setObject:[targetUsers valueForKeyPath:@"uid"] forKey:@"targetUid"];
[getData setObject:[targetUsers valueForKeyPath:@"nick"] forKey:@"targetNick"];
[getData setObject:[targetUsers valueForKeyPath:@"avatar"] forKey:@"targetAvatar"];
[getData setObject:@(YES) forKey:@"isRoomAlbum"];
attachment.data = getData;
[self sendCustomMessage:attachment];
if(albumModel.ID != nil){
if(![[XPSkillCardPlayerManager shareInstance].photoIdList containsObject:albumModel.ID]){
if([XPSkillCardPlayerManager shareInstance].photoIdList == nil){
[XPSkillCardPlayerManager shareInstance].photoIdList = [NSMutableArray arrayWithArray:@[albumModel.ID]];
}else{
[[XPSkillCardPlayerManager shareInstance].photoIdList addObject:albumModel.ID];
}
}
[[NSNotificationCenter defaultCenter]postNotificationName:@"kGetgetUnlockRoomAlbumPhotoListNot" object:nil];
}
return;
}
[XNDJTDDLoadingTool showErrorWithMessage:msg];
} id:albumModel.ID roomUid:@(self.hostDelegate.getRoomInfo.uid).stringValue];
}
- (void)sendCustomMessage:(AttachmentModel *)attachment {
NSString *sessionID = [NSString stringWithFormat:@"%ld", [self.hostDelegate getRoomInfo].roomId];
NIMMessage *message = [[NIMMessage alloc]init];
NIMCustomObject *object = [[NIMCustomObject alloc] init];
object.attachment = attachment;
message.messageObject = object;
UserInfoModel *userInfo = [self.hostDelegate getUserInfo];
XPMessageRemoteExtModel *extModel = [[XPMessageRemoteExtModel alloc] init];
extModel.androidBubbleUrl = userInfo.androidBubbleUrl;
extModel.iosBubbleUrl = userInfo.iosBubbleUrl;
extModel.fromSayHelloChannel = userInfo.fromSayHelloChannel;
2025-01-22 21:22:58 +08:00
extModel.platformRole = userInfo.platformRole;
2023-10-17 18:30:14 +08:00
NSMutableDictionary *remoteExt = [NSMutableDictionary dictionaryWithObject:extModel.model2dictionary forKey:[NSString stringWithFormat:@"%ld", userInfo.uid]];
message.remoteExt = remoteExt;
NIMSessionType sessionType = NIMSessionTypeChatroom;
//
NIMSession *session = [NIMSession session:sessionID type:sessionType];
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:session error:nil];
}
#pragma mark - SDPhotoBrowserDelegate
- (NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index{
if(self.lookUpModel != nil){
return [[NSURL alloc]initWithString:self.lookUpModel.photoUrl];
}
return nil;
}
- (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index {
2024-06-21 01:37:38 +08:00
return [UIImageConstant defaultBannerPlaceholder];
2023-10-17 18:30:14 +08:00
}
2023-07-14 18:50:55 +08:00
#pragma mark - Getters And Setters
- (UITableView *)messageTableView {
if (!_messageTableView) {
_messageTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
_messageTableView.delegate = self;
_messageTableView.dataSource = self;
// UITableViewAutomaticDimension使
_messageTableView.rowHeight = 64; //
2023-07-14 18:50:55 +08:00
_messageTableView.tableFooterView = [UIView new];
_messageTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_messageTableView.backgroundColor = [UIColor clearColor];
_messageTableView.showsVerticalScrollIndicator = NO;
_messageTableView.clipsToBounds = NO;
2023-07-14 18:50:55 +08:00
_messageTableView.tag = 666;
if (@available(iOS 11.0, *)) {
_messageTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
2024-10-12 19:30:41 +08:00
[_messageTableView registerClass:[XPRoomMessageTableViewCell class] forCellReuseIdentifier:@"XPRoomMessageTableViewCell_Boom"];
2023-07-14 18:50:55 +08:00
[_messageTableView registerClass:[XPRoomMessageTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPRoomMessageTableViewCell class])];
[_messageTableView registerClass:[XPRoomMessageTableViewCell class] forCellReuseIdentifier:@"ChatMessage"];
2023-10-13 17:20:50 +08:00
[_messageTableView registerClass:[PIRoomMessagePhotoAlbumCell class] forCellReuseIdentifier:NSStringFromClass([PIRoomMessagePhotoAlbumCell class])];
2025-02-28 19:04:09 +08:00
[_messageTableView registerClass:[LuckyPackageMessageTableViewCell class] forCellReuseIdentifier:@"LuckyPackageMessageTableViewCell"];
[_messageTableView registerClass:[CPEnterRoomTableViewCell class] forCellReuseIdentifier:@"CPEnterRoomTableViewCell"];
2023-07-14 18:50:55 +08:00
}
return _messageTableView;
}
- (XPRoomMessageHeaderView *)headerView {
if (!_headerView) {
_headerView = [[XPRoomMessageHeaderView alloc] init];
}
return _headerView;
}
- (UIButton *)messageTipsBtn {
if (!_messageTipsBtn) {
_messageTipsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_messageTipsBtn setTitle:YMLocalizedString(@"XPRoomMessageContainerView6") forState:UIControlStateNormal];
[_messageTipsBtn setTitleColor:[DJDKMIMOMColor appMainColor] forState:UIControlStateNormal];
_messageTipsBtn.layer.cornerRadius = 15.0;
_messageTipsBtn.layer.masksToBounds = YES;
_messageTipsBtn.titleLabel.font = [UIFont systemFontOfSize:12.0];
_messageTipsBtn.backgroundColor = [UIColor whiteColor];
[_messageTipsBtn addTarget:self action:@selector(messageTipsBtnAction:) forControlEvents:UIControlEventTouchUpInside];
_messageTipsBtn.hidden = YES;
}
return _messageTipsBtn;
}
- (UIButton *)atTipBtn {
if (!_atTipBtn) {
_atTipBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_atTipBtn setTitle:YMLocalizedString(@"XPRoomMessageContainerView7") forState:UIControlStateNormal];
[_atTipBtn setTitleColor:[DJDKMIMOMColor appMainColor] forState:UIControlStateNormal];
_atTipBtn.layer.cornerRadius = 15.0;
_atTipBtn.layer.masksToBounds = YES;
_atTipBtn.titleLabel.font = [UIFont systemFontOfSize:12.0];
_atTipBtn.backgroundColor = [UIColor whiteColor];
[_atTipBtn addTarget:self action:@selector(atTipsBtnAction:) forControlEvents:UIControlEventTouchUpInside];
_atTipBtn.hidden = YES;
}
return _atTipBtn;
}
- (NSMutableArray<XPMessageInfoModel *> *)datasource {
if (!_datasource) {
_datasource = [NSMutableArray array];
}
return _datasource;
}
- (NSMutableArray<XPMessageInfoModel *> *)datasource_chat {
if (!_datasource_chat) {
_datasource_chat = [NSMutableArray array];
}
return _datasource_chat;
}
- (NSMutableArray<XPMessageInfoModel *> *)datasource_gift {
if (!_datasource_gift) {
_datasource_gift = [NSMutableArray array];
}
return _datasource_gift;
}
2024-10-12 19:30:41 +08:00
- (NSMutableArray *)incomingMessages {
2023-07-14 18:50:55 +08:00
if (!_incomingMessages) {
_incomingMessages = [NSMutableArray array];
}
return _incomingMessages;
}
- (NSMutableArray *)locationArray {
if (!_locationArray) {
_locationArray = [NSMutableArray array];
}
return _locationArray;
}
- (XPRoomMessageParser *)messageParser {
if (!_messageParser) {
_messageParser = [[XPRoomMessageParser alloc] init];
_messageParser.hostDelegate = self.hostDelegate;
}
return _messageParser;
}
@end