2016-10-03 13:26:58 +00:00
|
|
|
/*
|
|
|
|
Copyright 2016 OpenMarket Ltd
|
2017-03-08 17:54:20 +00:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2018-03-30 10:04:50 +00:00
|
|
|
Copyright 2018 New Vector Ltd
|
2016-10-03 13:26:58 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import "FilesSearchCellData.h"
|
|
|
|
|
|
|
|
@implementation FilesSearchCellData
|
|
|
|
@synthesize roomId, senderDisplayName;
|
|
|
|
@synthesize searchResult, title, message, date, shouldShowRoomDisplayName, roomDisplayName, attachment, isAttachmentWithThumbnail, attachmentIcon;
|
|
|
|
|
|
|
|
- (instancetype)initWithSearchResult:(MXSearchResult *)searchResult2 andSearchDataSource:(MXKSearchDataSource *)searchDataSource2
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self)
|
|
|
|
{
|
|
|
|
searchResult = searchResult2;
|
|
|
|
searchDataSource = searchDataSource2;
|
|
|
|
|
|
|
|
MXEvent *event = searchResult.result;
|
|
|
|
|
|
|
|
roomId = event.roomId;
|
|
|
|
|
|
|
|
// Title is here the file name stored in event body
|
|
|
|
title = [event.content[@"body"] isKindOfClass:[NSString class]] ? event.content[@"body"] : nil;
|
|
|
|
|
2017-04-27 14:55:38 +00:00
|
|
|
// Check attachment if any
|
|
|
|
if ([searchDataSource.eventFormatter isSupportedAttachment:event])
|
|
|
|
{
|
2018-03-30 10:04:50 +00:00
|
|
|
// Note: event.eventType may be equal here to MXEventTypeRoomMessage or MXEventTypeSticker
|
2017-04-27 14:55:38 +00:00
|
|
|
attachment = [[MXKAttachment alloc] initWithEvent:event andMatrixSession:searchDataSource.mxSession];
|
|
|
|
}
|
|
|
|
|
2016-10-03 13:26:58 +00:00
|
|
|
// Append the file size if any
|
|
|
|
if (attachment.contentInfo[@"size"])
|
|
|
|
{
|
|
|
|
NSInteger size = [attachment.contentInfo[@"size"] integerValue];
|
|
|
|
if (size)
|
|
|
|
{
|
2016-12-01 15:26:46 +00:00
|
|
|
title = [NSString stringWithFormat:@"%@ (%@)", title, [MXTools fileSizeToString:size round:YES]];
|
2016-10-03 13:26:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
date = [searchDataSource.eventFormatter dateStringFromEvent:event withTime:NO];
|
|
|
|
|
|
|
|
// Retrieve the sender display name from the current room state
|
|
|
|
MXRoom *room = [searchDataSource.mxSession roomWithRoomId:roomId];
|
|
|
|
if (room)
|
|
|
|
{
|
2018-07-11 21:52:46 +00:00
|
|
|
senderDisplayName = [room.state.members memberName:event.sender];
|
2016-10-03 13:26:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
senderDisplayName = event.sender;
|
|
|
|
}
|
|
|
|
|
|
|
|
message = senderDisplayName;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setShouldShowRoomDisplayName:(BOOL)shouldShowRoomDisplayName2
|
|
|
|
{
|
|
|
|
shouldShowRoomDisplayName = shouldShowRoomDisplayName2;
|
|
|
|
|
|
|
|
if (shouldShowRoomDisplayName)
|
|
|
|
{
|
|
|
|
MXRoom *room = [searchDataSource.mxSession roomWithRoomId:roomId];
|
|
|
|
if (room)
|
|
|
|
{
|
2017-09-14 14:00:50 +00:00
|
|
|
roomDisplayName = room.summary.displayname;
|
2016-10-03 13:26:58 +00:00
|
|
|
if (!roomDisplayName.length)
|
|
|
|
{
|
|
|
|
roomDisplayName = NSLocalizedStringFromTable(@"room_displayname_no_title", @"Vector", nil);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
roomDisplayName = roomId;
|
|
|
|
}
|
|
|
|
|
|
|
|
message = [NSString stringWithFormat:@"%@ - %@", roomDisplayName, senderDisplayName];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
message = senderDisplayName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isAttachmentWithThumbnail
|
|
|
|
{
|
2018-03-30 10:04:50 +00:00
|
|
|
return (attachment && (attachment.type == MXKAttachmentTypeImage || attachment.type == MXKAttachmentTypeVideo || attachment.type == MXKAttachmentTypeSticker));
|
2016-10-03 13:26:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (UIImage*)attachmentIcon
|
|
|
|
{
|
|
|
|
MXEvent *event = searchResult.result;
|
|
|
|
NSString *msgtype;
|
|
|
|
MXJSONModelSetString(msgtype, event.content[@"msgtype"]);
|
|
|
|
|
|
|
|
if ([msgtype isEqualToString:kMXMessageTypeImage])
|
|
|
|
{
|
|
|
|
return [UIImage imageNamed:@"file_photo_icon"];
|
|
|
|
}
|
|
|
|
else if ([msgtype isEqualToString:kMXMessageTypeAudio])
|
|
|
|
{
|
2017-07-06 09:06:12 +00:00
|
|
|
return [UIImage imageNamed:@"file_music_icon"];
|
2016-10-03 13:26:58 +00:00
|
|
|
}
|
|
|
|
else if ([msgtype isEqualToString:kMXMessageTypeVideo])
|
|
|
|
{
|
|
|
|
return [UIImage imageNamed:@"file_video_icon"];
|
|
|
|
}
|
|
|
|
else if ([msgtype isEqualToString:kMXMessageTypeLocation])
|
|
|
|
{
|
|
|
|
// Not supported yet
|
|
|
|
}
|
|
|
|
else if ([msgtype isEqualToString:kMXMessageTypeFile])
|
|
|
|
{
|
|
|
|
return [UIImage imageNamed:@"file_doc_icon"];
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|