зеркало из https://github.com/nextcloud/talk-ios.git
Format system messages.
Signed-off-by: Ivan Sein <ivan@nextcloud.com>
This commit is contained in:
Родитель
afa6682711
Коммит
6f3e15bd59
|
@ -45,6 +45,7 @@
|
|||
2C4D7D731F309DA500FF4A0D /* RTCSessionDescription+JSON.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C4D7D701F309DA500FF4A0D /* RTCSessionDescription+JSON.m */; };
|
||||
2C4D7D761F30F7B600FF4A0D /* ARDUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C4D7D751F30F7B600FF4A0D /* ARDUtilities.m */; };
|
||||
2C5435ED1FB1E5E8003D4222 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 2C5435EC1FB1E5E8003D4222 /* GoogleService-Info.plist */; };
|
||||
2C604BD9211988A700D34DCD /* SystemMessageTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C604BD8211988A700D34DCD /* SystemMessageTableViewCell.m */; };
|
||||
2C7381562106136000CDB8DB /* NCChatTitleView.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C7381552106136000CDB8DB /* NCChatTitleView.m */; };
|
||||
2C738158210613A200CDB8DB /* NCChatTitleView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2C738157210613A200CDB8DB /* NCChatTitleView.xib */; };
|
||||
2C78EF951F7E70EB008AFA74 /* NCPeerConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C78EF941F7E70EB008AFA74 /* NCPeerConnection.m */; };
|
||||
|
@ -200,6 +201,8 @@
|
|||
2C4D7D741F30F7B600FF4A0D /* ARDUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ARDUtilities.h; sourceTree = "<group>"; };
|
||||
2C4D7D751F30F7B600FF4A0D /* ARDUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ARDUtilities.m; sourceTree = "<group>"; };
|
||||
2C5435EC1FB1E5E8003D4222 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
|
||||
2C604BD7211988A700D34DCD /* SystemMessageTableViewCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SystemMessageTableViewCell.h; sourceTree = "<group>"; };
|
||||
2C604BD8211988A700D34DCD /* SystemMessageTableViewCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SystemMessageTableViewCell.m; sourceTree = "<group>"; };
|
||||
2C6085C11FB1063700B36A6E /* VideoCalls.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = VideoCalls.entitlements; sourceTree = "<group>"; };
|
||||
2C7381542106136000CDB8DB /* NCChatTitleView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NCChatTitleView.h; sourceTree = "<group>"; };
|
||||
2C7381552106136000CDB8DB /* NCChatTitleView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NCChatTitleView.m; sourceTree = "<group>"; };
|
||||
|
@ -810,6 +813,8 @@
|
|||
2CA15547208EA1EA00CE8EF0 /* ChatMessageTableViewCell.m */,
|
||||
2CA155542099E07700CE8EF0 /* GroupedChatMessageTableViewCell.h */,
|
||||
2CA155552099E07700CE8EF0 /* GroupedChatMessageTableViewCell.m */,
|
||||
2C604BD7211988A700D34DCD /* SystemMessageTableViewCell.h */,
|
||||
2C604BD8211988A700D34DCD /* SystemMessageTableViewCell.m */,
|
||||
2C06BF6520AC647A0031EB46 /* DateHeaderView.h */,
|
||||
2C06BF6620AC647A0031EB46 /* DateHeaderView.m */,
|
||||
2C06BF6320AC64370031EB46 /* DateHeaderView.xib */,
|
||||
|
@ -1126,6 +1131,7 @@
|
|||
2CC007B820D8139D0096D91F /* RoomCreationTableViewController.m in Sources */,
|
||||
2CA1CCA41F025F64002FE6A2 /* RoomsTableViewController.m in Sources */,
|
||||
2C90E5D31EE80C870093D85A /* AuthenticationViewController.m in Sources */,
|
||||
2C604BD9211988A700D34DCD /* SystemMessageTableViewCell.m in Sources */,
|
||||
2CA1CCD01F1E1779002FE6A2 /* SearchTableViewController.m in Sources */,
|
||||
2C7381562106136000CDB8DB /* NCChatTitleView.m in Sources */,
|
||||
2C0574A41EDDA2E300D9E7F2 /* LoginViewController.m in Sources */,
|
||||
|
|
|
@ -22,12 +22,15 @@ extern NSInteger const kChatMessageGroupTimeDifference;
|
|||
@property (nonatomic, strong) NSDictionary *messageParameters;
|
||||
@property (nonatomic, assign) NSInteger timestamp;
|
||||
@property (nonatomic, strong) NSString *token;
|
||||
@property (nonatomic, strong) NSString *systemMessage;
|
||||
// Group messages
|
||||
@property (nonatomic, assign) BOOL groupMessage;
|
||||
@property (nonatomic, assign) NSInteger groupMessageNumber;
|
||||
|
||||
+ (instancetype)messageWithDictionary:(NSDictionary *)messageDict;
|
||||
- (BOOL)isSystemMessage;
|
||||
- (NSMutableAttributedString *)parsedMessage;
|
||||
- (NSMutableAttributedString *)lastRoomMessageFormat;
|
||||
- (NSMutableAttributedString *)systemMessageFormat;
|
||||
|
||||
@end
|
||||
|
|
|
@ -30,6 +30,7 @@ NSInteger const kChatMessageGroupTimeDifference = 15;
|
|||
message.messageParameters = [messageDict objectForKey:@"messageParameters"];
|
||||
message.timestamp = [[messageDict objectForKey:@"timestamp"] integerValue];
|
||||
message.token = [messageDict objectForKey:@"token"];
|
||||
message.systemMessage = [messageDict objectForKey:@"systemMessage"];
|
||||
|
||||
id actorDisplayName = [messageDict objectForKey:@"actorDisplayName"];
|
||||
if (!actorDisplayName) {
|
||||
|
@ -49,6 +50,14 @@ NSInteger const kChatMessageGroupTimeDifference = 15;
|
|||
return message;
|
||||
}
|
||||
|
||||
- (BOOL)isSystemMessage
|
||||
{
|
||||
if (![_systemMessage isEqualToString:@""]) {
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSMutableAttributedString *)parsedMessage
|
||||
{
|
||||
NSString *originalMessage = _message;
|
||||
|
@ -114,4 +123,12 @@ NSInteger const kChatMessageGroupTimeDifference = 15;
|
|||
return lastMessage;
|
||||
}
|
||||
|
||||
- (NSMutableAttributedString *)systemMessageFormat
|
||||
{
|
||||
NSMutableAttributedString *message = [self parsedMessage];
|
||||
[message addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithWhite:0 alpha:0.3] range:NSMakeRange(0,message.length)];
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#import "ChatMessageTableViewCell.h"
|
||||
#import "GroupedChatMessageTableViewCell.h"
|
||||
#import "SystemMessageTableViewCell.h"
|
||||
#import "DateHeaderView.h"
|
||||
#import "ChatPlaceholderView.h"
|
||||
#import "NCAPIController.h"
|
||||
|
@ -109,6 +110,7 @@
|
|||
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
||||
[self.tableView registerClass:[ChatMessageTableViewCell class] forCellReuseIdentifier:ChatMessageCellIdentifier];
|
||||
[self.tableView registerClass:[GroupedChatMessageTableViewCell class] forCellReuseIdentifier:GroupedChatMessageCellIdentifier];
|
||||
[self.tableView registerClass:[SystemMessageTableViewCell class] forCellReuseIdentifier:SystemMessageCellIdentifier];
|
||||
[self.autoCompletionView registerClass:[ChatMessageTableViewCell class] forCellReuseIdentifier:AutoCompletionCellIdentifier];
|
||||
[self registerPrefixesForAutoCompletion:@[@"@"]];
|
||||
|
||||
|
@ -525,10 +527,11 @@
|
|||
- (BOOL)shouldGroupMessage:(NCChatMessage *)newMessage withMessage:(NCChatMessage *)lastMessage
|
||||
{
|
||||
BOOL sameActor = [newMessage.actorId isEqualToString:lastMessage.actorId];
|
||||
BOOL sameType = ([newMessage isSystemMessage] == [lastMessage isSystemMessage]);
|
||||
BOOL timeDiff = (newMessage.timestamp - lastMessage.timestamp) < kChatMessageGroupTimeDifference;
|
||||
BOOL notMaxGroup = lastMessage.groupMessageNumber < kChatMessageMaxGroupNumber;
|
||||
|
||||
return sameActor & timeDiff & notMaxGroup;
|
||||
return sameActor & sameType & timeDiff & notMaxGroup;
|
||||
}
|
||||
|
||||
- (BOOL)shouldRetireveHistory
|
||||
|
@ -693,6 +696,16 @@
|
|||
NSDate *sectionDate = [_dateSections objectAtIndex:indexPath.section];
|
||||
NCChatMessage *message = [[_messages objectForKey:sectionDate] objectAtIndex:indexPath.row];
|
||||
UITableViewCell *cell = [UITableViewCell new];
|
||||
if (message.isSystemMessage) {
|
||||
SystemMessageTableViewCell *systemCell = (SystemMessageTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:SystemMessageCellIdentifier];
|
||||
systemCell.bodyLabel.attributedText = message.systemMessageFormat;
|
||||
systemCell.messageId = message.messageId;
|
||||
if (!message.groupMessage) {
|
||||
NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:message.timestamp];
|
||||
systemCell.dateLabel.text = [self getTimeFromDate:date];
|
||||
}
|
||||
return systemCell;
|
||||
}
|
||||
if (message.groupMessage) {
|
||||
GroupedChatMessageTableViewCell *groupedCell = (GroupedChatMessageTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:GroupedChatMessageCellIdentifier];
|
||||
groupedCell.bodyTextView.attributedText = message.parsedMessage;
|
||||
|
@ -736,7 +749,7 @@
|
|||
NSParagraphStyleAttributeName: paragraphStyle};
|
||||
|
||||
CGFloat width = CGRectGetWidth(tableView.frame) - kChatMessageCellAvatarHeight;
|
||||
width -= 30.0;
|
||||
width -= (message.isSystemMessage)? 70.0 : 30.0;
|
||||
|
||||
CGRect titleBounds = [message.actorDisplayName boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:NULL];
|
||||
CGRect bodyBounds = [message.parsedMessage boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) context:NULL];
|
||||
|
@ -753,7 +766,7 @@
|
|||
height = kChatMessageCellMinimumHeight;
|
||||
}
|
||||
|
||||
if (message.groupMessage) {
|
||||
if (message.groupMessage || message.isSystemMessage) {
|
||||
height = CGRectGetHeight(bodyBounds) + 20;
|
||||
|
||||
if (height < kGroupedChatMessageCellMinimumHeight) {
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
//
|
||||
// SystemMessageTableViewCell.h
|
||||
// VideoCalls
|
||||
//
|
||||
// Created by Ivan Sein on 07.08.18.
|
||||
// Copyright © 2018 struktur AG. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import "ChatTableViewCell.h"
|
||||
|
||||
static CGFloat kSystemMessageCellMinimumHeight = 30.0;
|
||||
|
||||
static NSString *SystemMessageCellIdentifier = @"SystemMessageCellIdentifier";
|
||||
|
||||
@interface SystemMessageTableViewCell : ChatTableViewCell
|
||||
|
||||
@property (nonatomic, strong) UILabel *dateLabel;
|
||||
@property (nonatomic, strong) UILabel *bodyLabel;
|
||||
|
||||
+ (CGFloat)defaultFontSize;
|
||||
|
||||
@end
|
|
@ -0,0 +1,95 @@
|
|||
//
|
||||
// SystemMessageTableViewCell.m
|
||||
// VideoCalls
|
||||
//
|
||||
// Created by Ivan Sein on 07.08.18.
|
||||
// Copyright © 2018 struktur AG. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SystemMessageTableViewCell.h"
|
||||
|
||||
@implementation SystemMessageTableViewCell
|
||||
|
||||
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
|
||||
{
|
||||
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
|
||||
if (self) {
|
||||
self.selectionStyle = UITableViewCellSelectionStyleNone;
|
||||
self.backgroundColor = [UIColor whiteColor];
|
||||
|
||||
[self configureSubviews];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)configureSubviews
|
||||
{
|
||||
[self.contentView addSubview:self.dateLabel];
|
||||
[self.contentView addSubview:self.bodyLabel];
|
||||
|
||||
NSDictionary *views = @{@"dateLabel": self.dateLabel,
|
||||
@"bodyLabel": self.bodyLabel,
|
||||
};
|
||||
|
||||
NSDictionary *metrics = @{@"avatar": @50,
|
||||
@"right": @10,
|
||||
@"left": @5
|
||||
};
|
||||
|
||||
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-avatar-[bodyLabel]-[dateLabel(40)]-right-|" options:0 metrics:metrics views:views]];
|
||||
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-left-[bodyLabel(>=0@999)]-left-|" options:0 metrics:metrics views:views]];
|
||||
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-left-[dateLabel(30)]-left-|" options:0 metrics:metrics views:views]];
|
||||
}
|
||||
|
||||
- (void)prepareForReuse
|
||||
{
|
||||
[super prepareForReuse];
|
||||
|
||||
self.selectionStyle = UITableViewCellSelectionStyleNone;
|
||||
CGFloat pointSize = [SystemMessageTableViewCell defaultFontSize];
|
||||
self.bodyLabel.font = [UIFont systemFontOfSize:pointSize];
|
||||
self.bodyLabel.text = @"";
|
||||
self.dateLabel.text = @"";
|
||||
}
|
||||
|
||||
#pragma mark - Getters
|
||||
|
||||
- (UILabel *)bodyLabel
|
||||
{
|
||||
if (!_bodyLabel) {
|
||||
_bodyLabel = [UILabel new];
|
||||
_bodyLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
_bodyLabel.backgroundColor = [UIColor clearColor];
|
||||
_bodyLabel.userInteractionEnabled = NO;
|
||||
_bodyLabel.numberOfLines = 0;
|
||||
_bodyLabel.font = [UIFont systemFontOfSize:[SystemMessageTableViewCell defaultFontSize]];
|
||||
}
|
||||
return _bodyLabel;
|
||||
}
|
||||
|
||||
- (UILabel *)dateLabel
|
||||
{
|
||||
if (!_dateLabel) {
|
||||
_dateLabel = [UILabel new];
|
||||
_dateLabel.textAlignment = NSTextAlignmentRight;
|
||||
_dateLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
_dateLabel.backgroundColor = [UIColor clearColor];
|
||||
_dateLabel.userInteractionEnabled = NO;
|
||||
_dateLabel.numberOfLines = 1;
|
||||
_dateLabel.textColor = [UIColor lightGrayColor];
|
||||
_dateLabel.font = [UIFont systemFontOfSize:12.0];
|
||||
}
|
||||
return _dateLabel;
|
||||
}
|
||||
|
||||
+ (CGFloat)defaultFontSize
|
||||
{
|
||||
CGFloat pointSize = 16.0;
|
||||
|
||||
// NSString *contentSizeCategory = [[UIApplication sharedApplication] preferredContentSizeCategory];
|
||||
// pointSize += SLKPointSizeDifferenceForCategory(contentSizeCategory);
|
||||
|
||||
return pointSize;
|
||||
}
|
||||
|
||||
@end
|
Загрузка…
Ссылка в новой задаче