Bypass ratchet and network to discuss with self.

Closes #314 #305 #274

Reviewed-by: @FredericJacobs
This commit is contained in:
Christine Corbett 2015-01-07 17:57:58 +00:00 committed by Frederic Jacobs
parent 07c539c844
commit 71320a690c
6 changed files with 47 additions and 18 deletions

View file

@ -57,7 +57,6 @@ dispatch_queue_t sendingQueue() {
dispatch_async(sendingQueue(), ^{
if ([thread isKindOfClass:[TSGroupThread class]]) {
TSGroupThread* groupThread = (TSGroupThread*)thread;
[self saveGroupMessage:message inThread:thread];
__block NSArray* recipients;
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
@ -65,7 +64,7 @@ dispatch_queue_t sendingQueue() {
}];
for(TSRecipient *rec in recipients){
// we don't need to send the message to ourselves, but otherwise we sends
// we don't need to send the message to ourselves, but otherwise we send
if( ![[rec uniqueId] isEqualToString:[SignalKeyingStorage.localNumber toE164]]){
[self sendMessage:message
toRecipient:rec
@ -76,19 +75,28 @@ dispatch_queue_t sendingQueue() {
}
else if([thread isKindOfClass:[TSContactThread class]]){
[self saveMessage:message withState:TSOutgoingMessageStateAttemptingOut];
TSContactThread *contactThread = (TSContactThread*)thread;
__block TSRecipient *recipient;
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
recipient = [contactThread recipientWithTransaction:transaction];
}];
[self saveMessage:message withState:TSOutgoingMessageStateAttemptingOut];
[self sendMessage:message
toRecipient:recipient
inThread:thread
withAttemps:3];
if(![contactThread.contactIdentifier isEqualToString:[SignalKeyingStorage.localNumber toE164]]) {
__block TSRecipient *recipient;
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
recipient = [contactThread recipientWithTransaction:transaction];
}];
[self sendMessage:message
toRecipient:recipient
inThread:thread
withAttemps:3];
}
else {
// Special situation: if we are sending to ourselves in a single thread, we treat this as an incoming message
[self handleMessageSent:message];
[[TSMessagesManager sharedManager] handleSendToMyself:message];
}
}
});
}

View file

@ -23,4 +23,6 @@
- (void)handleReceivedMessage:(IncomingPushMessageSignal*)message withContent:(PushMessageContent*)content attachments:(NSArray*)attachments;
-(void)handleSendToMyself:(TSOutgoingMessage*)outgoingMessage;
@end

View file

@ -32,6 +32,8 @@
#import "TSMessagesManager+attachments.h"
#import "TSAttachmentPointer.h"
#import "SignalKeyingStorage.h"
#import "NSData+messagePadding.h"
#import "Environment.h"
@ -227,6 +229,15 @@
[self handleReceivedMessage:message withContent:content attachments:content.attachments];
}
-(void)handleSendToMyself:(TSOutgoingMessage*)outgoingMessage {
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
TSContactThread *cThread = [TSContactThread getOrCreateThreadWithContactId:[SignalKeyingStorage.localNumber toE164] transaction:transaction];
[cThread saveWithTransaction:transaction];
TSIncomingMessage *incomingMessage = [[TSIncomingMessage alloc] initWithTimestamp:(outgoingMessage.timeStamp + 1) inThread:cThread messageBody:outgoingMessage.body attachments:outgoingMessage.attachments];
[incomingMessage saveWithTransaction:transaction];
}];
}
- (void)handleReceivedMessage:(IncomingPushMessageSignal*)message withContent:(PushMessageContent*)content attachments:(NSArray*)attachments {
uint64_t timeStamp = message.timestamp;
NSString *body = content.body;

View file

@ -10,6 +10,7 @@
#import "PhoneNumberDirectoryFilter.h"
#import "PhoneNumberUtil.h"
#import "RecentCallManager.h"
#import "SignalKeyingStorage.h"
#define INITIAL_BACKSPACE_TIMER_DURATION 0.5f
#define BACKSPACE_TIME_DECREASE_AMMOUNT 0.1f
@ -129,11 +130,17 @@
}
-(void) initiateCallToPhoneNumber:(PhoneNumber*) phoneNumber {
if (_contact) {
[Environment.phoneManager initiateOutgoingCallToContact:_contact
atRemoteNumber:phoneNumber];
} else {
[Environment.phoneManager initiateOutgoingCallToRemoteNumber:phoneNumber];
if(![[phoneNumber toE164] isEqualToString:[SignalKeyingStorage.localNumber toE164]]) {
if (_contact) {
[Environment.phoneManager initiateOutgoingCallToContact:_contact
atRemoteNumber:phoneNumber];
} else {
[Environment.phoneManager initiateOutgoingCallToRemoteNumber:phoneNumber];
}
}
else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"ERROR_CALL_ONESELF", @"") message:nil delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", @"") otherButtonTitles:nil, nil];
[alertView show];
}
}

View file

@ -195,7 +195,7 @@ typedef enum : NSUInteger {
if (!isGroupConversation) {
UIBarButtonItem * lockButton = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"lock"] style:UIBarButtonItemStylePlain target:self action:@selector(showFingerprint)];
if ([self isRedPhoneReachable]) {
if ([self isRedPhoneReachable] && ![((TSContactThread*)_thread).contactIdentifier isEqualToString:[SignalKeyingStorage.localNumber toE164]]) {
UIBarButtonItem * callButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"call_tab"] style:UIBarButtonItemStylePlain target:self action:@selector(callAction)];
[callButton setImageInsets:UIEdgeInsetsMake(0, -10, 0, -50)];
negativeSeparator.width = -8;

View file

@ -38,6 +38,7 @@
"DIALER_NUMBER_PLUS" = "+";
"DIALER_NUMBER_POUND" = "#";
"DISABLING_BACKUP_FAILED" = "We encountered an issue while disabling the backup of your call log. Call logs might leak in your iTunes/iCloud backups.";
"ERROR_CALL_ONESELF" = "You can't call yourself.";
"ERROR_WAS_DETECTED_TITLE" = "Bummer!";
"ERROR_WAS_DETECTED_SUBMIT" = "An bug was detected. Help us make Signal better by reporting this incident.";
"END_CALL_BAD_INTERACTION_WITH_SERVER" = "Server Failed!";