添加了进入非自己房间显示房间公告的

This commit is contained in:
fengshuo
2022-03-15 15:03:26 +08:00
parent ff8a6e2095
commit a36c68b14a
5 changed files with 86 additions and 3 deletions

View File

@@ -45,5 +45,8 @@
+ (NSString *)getNowTimeTimestampMillisecond;
///比较两个时间的差值
+ (NSDateComponents *)compareTwoDate:(NSDate *)firstDate secondDate:(NSDate *)secondDate;
@end

View File

@@ -229,6 +229,17 @@
}
+ (NSDateComponents *)compareTwoDate:(NSDate *)firstDate secondDate:(NSDate *)secondDate {
//
NSCalendar *calendar = [NSCalendar currentCalendar];
//
NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth
| NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
//
NSDateComponents *dateCom = [calendar components:unit fromDate:firstDate toDate:secondDate options:0];
return dateCom;
}
@end

View File

@@ -16,6 +16,7 @@
#import "XPMacro.h"
#import "XPGiftStorage.h"
#import "XPRoomFaceTool.h"
#import "TTPopup.h"
///Model
#import "XPMessageRemoteExtModel.h"
#import "AttachmentModel.h"
@@ -32,6 +33,7 @@
#import "NetImageView.h"
#import "XPUserCardViewController.h"
#import "XPRoomTopicAlertView.h"
@implementation XPRoomMessageParser
@@ -125,7 +127,24 @@
/// tips
/// @param message
- (NSAttributedString*)makeTipsAttribute:(NIMMessage *)message {
if ([message.localExt.allKeys containsObject:@"isRoomTopic"]) {
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
[attribute appendAttributedString: [self createTextAttribute:message.text color:[UIColor whiteColor] font:kRoomMessageDefalutFont]];
if ([[message.localExt objectForKey:@"isRoomTopic"] boolValue] == YES) {
[attribute yy_setTextHighlightRange:NSMakeRange(0, attribute.length) color:nil backgroundColor:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
RoomInfoModel * roomInfo = self.hostDelegate.getRoomInfo;
TTPopupService * config = [[TTPopupService alloc] init];
XPRoomTopicAlertView * alertView = [[XPRoomTopicAlertView alloc] init];
alertView.title = roomInfo.roomDesc;
alertView.message = roomInfo.introduction;
config.contentView = alertView;
[TTPopup popupWithConfig:config];
}];
}
return attribute;
} else {
return [self createTextAttribute:message.text color:UIColorFromRGB(0xFE5D7F) font:kRoomMessageDefalutFont];
}
}
///

View File

@@ -17,6 +17,7 @@
#import "XPRoomMessageParser.h"
#import "AccountInfoStorage.h"
#import "XPRoomMiniManager.h"
#import "PLTimeUtil.h"
///Model
#import "RoomInfoModel.h"
#import "AttachmentModel.h"
@@ -26,6 +27,7 @@
#import "XPRoomMessageHeaderView.h"
#import "View/XPRoomMessageHeaderView.h"
NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey";
@interface XPRoomMessageContainerView ()<UITableViewDelegate, UITableViewDataSource>
///
@@ -261,6 +263,51 @@
[self addRoomMessage:message];
}
///
- (void)createUserEnterRoomAddRoomtopicMessage {
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.roomDesc.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];
NSString * content = [NSString stringWithFormat:@"[房间公告] \n %@", roomInfo.introduction];
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];
NSString * content = [NSString stringWithFormat:@"[房间公告] \n %@", roomInfo.introduction];
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];
message.text = @"可点击查看本房间公告";
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];
}
#pragma mark - RoomGuestDelegate
- (void)handleNIMCustomMessage:(NIMMessage *)message {
self.isMiniEnter = NO;
@@ -301,6 +348,7 @@
[self addRoomMessage:message];
return;
} else {
[self createUserEnterRoomAddRoomtopicMessage];
[self addRoomMessage:message];
NIMChatroomNotificationMember *member = content.targets[0];
if (member.userId.integerValue == [AccountInfoStorage instance].getUid.integerValue) {
@@ -394,7 +442,9 @@
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSAttributedString* attr = [self.datasource objectAtIndex:indexPath.row];
CGSize maxSize = CGSizeMake(kRoomMessageMaxWidth, MAXFLOAT);
YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:maxSize text:attr];
YYTextContainer *container = [YYTextContainer containerWithSize:maxSize];
container.maximumNumberOfRows = 0;
YYTextLayout *layout = [YYTextLayout layoutWithContainer:container text:attr];
return layout.textBoundingSize.height + kRoomMessageTextSpaceHeight * 2 + 10;
}

View File

@@ -112,7 +112,7 @@
if (textView.text.length > 300) {
textView.text = [textView.text substringToIndex:300];
}
self.contentLabel.text = [NSString stringWithFormat:@"%ld/300", (300 - textView.text.length)];
self.contentLabel.text = [NSString stringWithFormat:@"%ld/300", textView.text.length];
}
- (void)textViewDidBeginEditing:(UITextView *)textView {
@@ -137,7 +137,7 @@
if (textField.text.length > 15) {
textField.text = [textField.text substringToIndex:15];
}
self.titleNumberLabel.text = [NSString stringWithFormat:@"%ld/15", (15 - textField.text.length)];
self.titleNumberLabel.text = [NSString stringWithFormat:@"%ld/15", textField.text.length];
}