mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.4 KiB
Objective-C
81 lines
2.4 KiB
Objective-C
//
|
|
// TSMessage.m
|
|
// TextSecureKit
|
|
//
|
|
// Created by Frederic Jacobs on 12/11/14.
|
|
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
|
|
//
|
|
|
|
#import "TSMessage.h"
|
|
#import "TSAttachment.h"
|
|
|
|
NSString * const TSAttachementsRelationshipEdgeName = @"TSAttachmentEdge";
|
|
|
|
@implementation TSMessage
|
|
|
|
- (void)addattachments:(NSArray*)attachments {
|
|
for (NSString *identifier in attachments) {
|
|
[self addattachment:identifier];
|
|
}
|
|
}
|
|
|
|
- (void)addattachment:(NSString*)attachment {
|
|
if (!_attachments) {
|
|
_attachments = [NSMutableArray array];
|
|
}
|
|
|
|
[self.attachments addObject:attachment];
|
|
}
|
|
|
|
- (NSArray *)yapDatabaseRelationshipEdges {
|
|
NSMutableArray *edges = [[super yapDatabaseRelationshipEdges] mutableCopy];
|
|
|
|
if ([self hasAttachments]) {
|
|
for (NSString *attachmentId in self.attachments) {
|
|
YapDatabaseRelationshipEdge *fileEdge = [[YapDatabaseRelationshipEdge alloc] initWithName:TSAttachementsRelationshipEdgeName
|
|
destinationKey:attachmentId
|
|
collection:[TSAttachment collection]
|
|
nodeDeleteRules:YDB_DeleteDestinationIfAllSourcesDeleted];
|
|
[edges addObject:fileEdge];
|
|
}
|
|
}
|
|
return edges;
|
|
}
|
|
|
|
- (instancetype)initWithTimestamp:(uint64_t)timestamp
|
|
inThread:(TSThread*)thread
|
|
messageBody:(NSString*)body
|
|
attachments:(NSArray*)attachments
|
|
{
|
|
self = [super initWithTimestamp:timestamp inThread:thread];
|
|
|
|
if (self) {
|
|
_body = body;
|
|
_attachments = [attachments mutableCopy];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (BOOL)hasAttachments{
|
|
return self.attachments?(self.attachments.count>0):false;
|
|
}
|
|
|
|
- (NSString *)description{
|
|
if(self.attachments > 0){
|
|
return @"Attachment";
|
|
} else {
|
|
return self.body;
|
|
}
|
|
}
|
|
|
|
- (void)removeWithTransaction:(YapDatabaseReadWriteTransaction *)transaction{
|
|
for (NSString *attachmentId in _attachments){
|
|
TSAttachment *attachment = [TSAttachment fetchObjectWithUniqueID:attachmentId transaction:transaction];
|
|
[attachment removeWithTransaction:transaction];
|
|
}
|
|
|
|
[super removeWithTransaction:transaction];
|
|
}
|
|
|
|
@end
|