зеркало из https://github.com/nextcloud/talk-ios.git
Move file-related parameters to NCMessageFileParameters
Don't return a new object each time "file" is accessed Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
This commit is contained in:
Родитель
b626b91f32
Коммит
95946ae6dc
|
@ -24,6 +24,7 @@
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
#import <Realm/Realm.h>
|
#import <Realm/Realm.h>
|
||||||
#import "NCMessageParameter.h"
|
#import "NCMessageParameter.h"
|
||||||
|
#import "NCMessageFileParameter.h"
|
||||||
|
|
||||||
extern NSInteger const kChatMessageGroupTimeDifference;
|
extern NSInteger const kChatMessageGroupTimeDifference;
|
||||||
|
|
||||||
|
@ -53,7 +54,7 @@ extern NSInteger const kChatMessageGroupTimeDifference;
|
||||||
|
|
||||||
- (BOOL)isSystemMessage;
|
- (BOOL)isSystemMessage;
|
||||||
- (BOOL)isEmojiMessage;
|
- (BOOL)isEmojiMessage;
|
||||||
- (NCMessageParameter *)file;
|
- (NCMessageFileParameter *)file;
|
||||||
- (NSDictionary *)messageParameters;
|
- (NSDictionary *)messageParameters;
|
||||||
- (NSMutableAttributedString *)parsedMessage;
|
- (NSMutableAttributedString *)parsedMessage;
|
||||||
- (NSMutableAttributedString *)systemMessageFormat;
|
- (NSMutableAttributedString *)systemMessageFormat;
|
||||||
|
|
|
@ -28,6 +28,13 @@
|
||||||
|
|
||||||
NSInteger const kChatMessageGroupTimeDifference = 30;
|
NSInteger const kChatMessageGroupTimeDifference = 30;
|
||||||
|
|
||||||
|
@interface NCChatMessage ()
|
||||||
|
{
|
||||||
|
NCMessageFileParameter *_fileParameter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation NCChatMessage
|
@implementation NCChatMessage
|
||||||
|
|
||||||
+ (instancetype)messageWithDictionary:(NSDictionary *)messageDict
|
+ (instancetype)messageWithDictionary:(NSDictionary *)messageDict
|
||||||
|
@ -124,20 +131,25 @@ NSInteger const kChatMessageGroupTimeDifference = 30;
|
||||||
|
|
||||||
- (NCMessageParameter *)file;
|
- (NCMessageParameter *)file;
|
||||||
{
|
{
|
||||||
NCMessageParameter *fileParam = nil;
|
if (!_fileParameter) {
|
||||||
for (NSDictionary *parameterDict in [[self messageParameters] allValues]) {
|
for (NSDictionary *parameterDict in [[self messageParameters] allValues]) {
|
||||||
NCMessageParameter *parameter = [NCMessageParameter parameterWithDictionary:parameterDict] ;
|
NCMessageFileParameter *parameter = [[NCMessageFileParameter alloc] initWithDictionary:parameterDict] ;
|
||||||
if ([parameter.type isEqualToString:@"file"]) {
|
if (![parameter.type isEqualToString:@"file"]) {
|
||||||
if (!fileParam) {
|
continue;
|
||||||
fileParam = parameter;
|
}
|
||||||
|
|
||||||
|
if (!_fileParameter) {
|
||||||
|
_fileParameter = parameter;
|
||||||
} else {
|
} else {
|
||||||
// If there is more than one file in the message,
|
// If there is more than one file in the message,
|
||||||
// we don't display any preview.
|
// we don't display any preview.
|
||||||
|
_fileParameter = nil;
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fileParam;
|
|
||||||
|
return _fileParameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDictionary *)messageParameters
|
- (NSDictionary *)messageParameters
|
||||||
|
@ -181,7 +193,7 @@ NSInteger const kChatMessageGroupTimeDifference = 30;
|
||||||
stringByReplacingOccurrencesOfString:@"}" withString:@""];
|
stringByReplacingOccurrencesOfString:@"}" withString:@""];
|
||||||
NSDictionary *parameterDict = [[self messageParameters] objectForKey:parameterKey];
|
NSDictionary *parameterDict = [[self messageParameters] objectForKey:parameterKey];
|
||||||
if (parameterDict) {
|
if (parameterDict) {
|
||||||
NCMessageParameter *messageParameter = [NCMessageParameter parameterWithDictionary:parameterDict] ;
|
NCMessageParameter *messageParameter = [[NCMessageParameter alloc] initWithDictionary:parameterDict] ;
|
||||||
// Default replacement string is the parameter name
|
// Default replacement string is the parameter name
|
||||||
NSString *replaceString = messageParameter.name;
|
NSString *replaceString = messageParameter.name;
|
||||||
// Format user and call mentions
|
// Format user and call mentions
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
/**
|
||||||
|
* @copyright Copyright (c) 2020 Marcel Müller <marcel-mueller@gmx.de>
|
||||||
|
*
|
||||||
|
* @author Marcel Müller <marcel-mueller@gmx.de>
|
||||||
|
*
|
||||||
|
* @license GNU GPL version 3 or any later version
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
|
#import "NCMessageParameter.h"
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@interface NCMessageFileParameter : NCMessageParameter
|
||||||
|
|
||||||
|
@property (nonatomic, strong) NSString *path;
|
||||||
|
@property (nonatomic, strong) NSString *mimetype;
|
||||||
|
@property (nonatomic, assign) BOOL previewAvailable;
|
||||||
|
@property (nonatomic, assign) BOOL isDownloading;
|
||||||
|
@property (nonatomic, assign) CGFloat downloadProgress;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
|
@ -0,0 +1,24 @@
|
||||||
|
//
|
||||||
|
// NCMessageFileParameter.m
|
||||||
|
// NextcloudTalk
|
||||||
|
//
|
||||||
|
// Created by Marcel Müller on 05.12.20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "NCMessageFileParameter.h"
|
||||||
|
|
||||||
|
@implementation NCMessageFileParameter
|
||||||
|
|
||||||
|
- (instancetype)initWithDictionary:(NSDictionary *)parameterDict
|
||||||
|
{
|
||||||
|
self = [super initWithDictionary:parameterDict];
|
||||||
|
if (self) {
|
||||||
|
self.path = [parameterDict objectForKey:@"path"];
|
||||||
|
self.mimetype = [parameterDict objectForKey:@"mimetype"];
|
||||||
|
self.previewAvailable = [[parameterDict objectForKey:@"preview-available"] boolValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
|
@ -26,14 +26,11 @@
|
||||||
|
|
||||||
@property (nonatomic, strong) NSString *parameterId;
|
@property (nonatomic, strong) NSString *parameterId;
|
||||||
@property (nonatomic, strong) NSString *name;
|
@property (nonatomic, strong) NSString *name;
|
||||||
@property (nonatomic, strong) NSString *path;
|
|
||||||
@property (nonatomic, strong) NSString *link;
|
@property (nonatomic, strong) NSString *link;
|
||||||
@property (nonatomic, strong) NSString *type;
|
@property (nonatomic, strong) NSString *type;
|
||||||
@property (nonatomic, strong) NSString *mimetype;
|
|
||||||
@property (nonatomic, assign) BOOL previewAvailable;
|
|
||||||
@property (nonatomic, assign) NSRange range;
|
@property (nonatomic, assign) NSRange range;
|
||||||
|
|
||||||
+ (instancetype)parameterWithDictionary:(NSDictionary *)parameterDict;
|
- (instancetype)initWithDictionary:(NSDictionary *)parameterDict;
|
||||||
- (BOOL)shouldBeHighlighted;
|
- (BOOL)shouldBeHighlighted;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -26,29 +26,28 @@
|
||||||
|
|
||||||
@implementation NCMessageParameter
|
@implementation NCMessageParameter
|
||||||
|
|
||||||
+ (instancetype)parameterWithDictionary:(NSDictionary *)parameterDict
|
- (instancetype)initWithDictionary:(NSDictionary *)parameterDict
|
||||||
{
|
{
|
||||||
if (!parameterDict || ![parameterDict isKindOfClass:[NSDictionary class]]) {
|
self = [super init];
|
||||||
return nil;
|
if (self) {
|
||||||
|
if (!parameterDict || ![parameterDict isKindOfClass:[NSDictionary class]]) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.parameterId = [parameterDict objectForKey:@"id"];
|
||||||
|
self.name = [parameterDict objectForKey:@"name"];
|
||||||
|
self.link = [parameterDict objectForKey:@"link"];
|
||||||
|
self.type = [parameterDict objectForKey:@"type"];
|
||||||
|
|
||||||
|
id parameterId = [parameterDict objectForKey:@"id"];
|
||||||
|
if ([parameterId isKindOfClass:[NSString class]]) {
|
||||||
|
self.parameterId = parameterId;
|
||||||
|
} else {
|
||||||
|
self.parameterId = [parameterId stringValue];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NCMessageParameter *messageParameter = [[NCMessageParameter alloc] init];
|
return self;
|
||||||
messageParameter.parameterId = [parameterDict objectForKey:@"id"];
|
|
||||||
messageParameter.name = [parameterDict objectForKey:@"name"];
|
|
||||||
messageParameter.type = [parameterDict objectForKey:@"type"];
|
|
||||||
messageParameter.path = [parameterDict objectForKey:@"path"];
|
|
||||||
messageParameter.link = [parameterDict objectForKey:@"link"];
|
|
||||||
messageParameter.mimetype = [parameterDict objectForKey:@"mimetype"];
|
|
||||||
messageParameter.previewAvailable = [[parameterDict objectForKey:@"preview-available"] boolValue];
|
|
||||||
|
|
||||||
id parameterId = [parameterDict objectForKey:@"id"];
|
|
||||||
if ([parameterId isKindOfClass:[NSString class]]) {
|
|
||||||
messageParameter.parameterId = parameterId;
|
|
||||||
} else {
|
|
||||||
messageParameter.parameterId = [parameterId stringValue];
|
|
||||||
}
|
|
||||||
|
|
||||||
return messageParameter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)shouldBeHighlighted
|
- (BOOL)shouldBeHighlighted
|
||||||
|
|
Загрузка…
Ссылка в новой задаче