123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- // _____ _
- // |_ _| |_ _ _ ___ ___ _ __ __ _
- // | | | ' \| '_/ -_) -_) ' \/ _` |_
- // |_| |_||_|_| \___\___|_|_|_\__,_(_)
- //
- // Threema iOS Client
- // Copyright (c) 2012-2020 Threema GmbH
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU Affero General Public License, version 3,
- // as published by the Free Software Foundation.
- //
- // 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 Affero General Public License for more details.
- //
- // You should have received a copy of the GNU Affero General Public License
- // along with this program. If not, see <https://www.gnu.org/licenses/>.
- #import "ImageMessage.h"
- #import "NSString+Hex.h"
- #import "UTIConverter.h"
- #import "ThreemaFramework/ThreemaFramework-swift.h"
- @implementation ImageMessage
- @dynamic image;
- @dynamic thumbnail;
- @dynamic imageBlobId;
- @dynamic imageNonce;
- @dynamic imageSize;
- @dynamic progress;
- @dynamic encryptionKey;
- - (NSString*)logText {
- if ([self.image getCaption] != nil) {
- return [NSString stringWithFormat:@"%@ (%@) %@ %@", NSLocalizedString(@"image", nil), [self blobGetFilename], NSLocalizedString(@"caption", nil), [self.image getCaption]];
- }
- return [NSString stringWithFormat:@"%@ (%@)", NSLocalizedString(@"image", nil), [self blobGetFilename]];
- }
- - (NSString*)previewText {
- return NSLocalizedString(@"image", nil);
- }
- - (NSData *)blobGetData {
- if (self.image) {
- return self.image.data;
- }
-
- return nil;
- }
- - (NSData *)blobGetId {
- return self.imageBlobId;
- }
- - (NSData *)blobGetEncryptionKey {
- return self.encryptionKey;
- }
- - (NSNumber *)blobGetSize {
- return self.imageSize;
- }
- - (void)blobSetData:(NSData *)data {
- ImageData *dbData = [NSEntityDescription
- insertNewObjectForEntityForName:@"ImageData"
- inManagedObjectContext:self.managedObjectContext];
-
- dbData.data = data;
- self.image = dbData;
- }
- - (NSData *)blobGetThumbnail {
- if (self.thumbnail) {
- return self.thumbnail.data;
- }
-
- return nil;
- }
- - (NSString *)blobGetUTI {
- return UTTYPE_IMAGE;
- }
- - (NSString *)blobGetFilename {
- return [NSString stringWithFormat: @"%@.%@", [NSString stringWithHexData:self.id], MEDIA_EXTENSION_IMAGE];
- }
- - (NSString *)blobGetWebFilename {
- return [NSString stringWithFormat: @"threema-%@-image.%@", [DateFormatter getDateForWeb:self.date], MEDIA_EXTENSION_IMAGE];
- }
- - (void)blobUpdateProgress:(NSNumber *)progress {
- self.progress = progress;
- }
- - (NSNumber *)blobGetProgress {
- return self.progress;
- }
- #pragma mark ExternalStorageInfo
- - (NSString *)getFilename {
- return self.image != nil ? [self getFilename:self.image.data] : nil;
- }
- - (NSString *)getThumbnailname {
- return self.thumbnail != nil ? [self getFilename:self.thumbnail.data] : nil;
- }
- - (NSString *)getFilename:(NSData *)ofData {
- if (ofData != nil && [ofData respondsToSelector:NSSelectorFromString(@"filename")]) {
- return [ofData performSelector:NSSelectorFromString(@"filename")];
- }
- return nil;
- }
- - (NSString *)quotePreviewText {
- NSString *caption = nil;
- if (self.image != nil) {
- caption = [self.image getCaption];
- if (caption != nil) {
- NSString *quotePreviewString = [[caption componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsJoinedByString:@" "];
- caption = [quotePreviewString substringWithRange:NSMakeRange(0, MIN(caption.length, 200))];
- }
- }
- if (caption == nil || caption.length == 0) {
- caption = self.previewText;
- }
- return caption;
- }
- #ifdef DEBUG
- #else
- - (NSString *)debugDescription
- {
- return [NSString stringWithFormat:@"<%@: %p> %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@", [self class], self, @"image =", self.image.description, @"thumbnail =", self.thumbnail.description, @"imageBlobId =", @"***", @"imageNonce =", @"***", @"imageSize =", self.imageSize.description, @"progress =", self.progress.description, @"encryptionKey =", self.encryptionKey.description];
- }
- #endif
- @end
|