Create block offer when non-contacts send you a message.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-04-09 20:53:45 -04:00
parent adee71ba9b
commit 17b751d22a
6 changed files with 83 additions and 10 deletions

View file

@ -36,6 +36,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)updateSignalContactIntersectionWithABContacts:(NSArray<Contact *> *)abContacts
success:(void (^)())success
failure:(void (^)(NSError *error))failure;
@end
NS_ASSUME_NONNULL_END

View file

@ -1,5 +1,6 @@
// Created by Frederic Jacobs on 12/11/14.
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "OWSSignalServiceProtos.pb.h"
#import "TSMessage.h"
@ -15,6 +16,7 @@ typedef NS_ENUM(int32_t, TSErrorMessageType) {
TSErrorMessageDuplicateMessage,
TSErrorMessageInvalidVersion,
TSErrorMessageNonBlockingIdentityChange,
TSErrorMessageUnknownContactBlockOffer,
};
-(instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;

View file

@ -1,9 +1,5 @@
//
// TSErrorMessage.m
// TextSecureKit
//
// Created by Frederic Jacobs on 12/11/14.
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "TSErrorMessage.h"
@ -36,8 +32,14 @@
}
_errorType = errorMessageType;
// TODO Move this out of model class.
[[TextSecureKitEnv sharedEnv].notificationsManager notifyUserForErrorMessage:self inThread:thread];
// TODO: Move this out of model class.
//
// For now, dispatch async to ensure we're not inside a transaction
// and thereby avoid deadlock.
TSErrorMessage *errorMessage = self;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[[TextSecureKitEnv sharedEnv].notificationsManager notifyUserForErrorMessage:errorMessage inThread:thread];
});
return self;
}
@ -47,7 +49,7 @@
failedMessageType:(TSErrorMessageType)errorMessageType
{
TSContactThread *contactThread =
[TSContactThread getOrCreateThreadWithContactId:envelope.source transaction:transaction];
[TSContactThread getOrCreateThreadWithContactId:envelope.source transaction:transaction relay:nil];
return [self initWithTimestamp:envelope.timestamp inThread:contactThread failedMessageType:errorMessageType];
}
@ -68,6 +70,8 @@
return NSLocalizedString(@"ERROR_MESSAGE_WRONG_TRUSTED_IDENTITY_KEY", @"");
case TSErrorMessageNonBlockingIdentityChange:
return NSLocalizedString(@"ERROR_MESSAGE_NON_BLOCKING_IDENTITY_CHANGE", @"");
case TSErrorMessageUnknownContactBlockOffer:
return NSLocalizedString(@"UNKNOWN_CONTACT_BLOCK_OFFER", nil);
default:
return NSLocalizedString(@"ERROR_MESSAGE_UNKNOWN_ERROR", @"");
break;

View file

@ -1231,6 +1231,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
DDLogWarn(@"%@ Got exception: %@", self.tag, exception);
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
// TODO: This error message is never created?
TSErrorMessage *errorMessage;
if (message.groupMetaMessage == TSGroupMessageNone) {

View file

@ -0,0 +1,19 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "TSErrorMessage.h"
NS_ASSUME_NONNULL_BEGIN
@interface OWSUnknownContactBlockOfferMessage : TSErrorMessage
+ (instancetype)unknownContactBlockOfferMessage:(uint64_t)timestamp
thread:(TSThread *)thread
contactId:(NSString *)contactId;
@property (nonatomic, readonly) NSString *contactId;
@end
NS_ASSUME_NONNULL_END

View file

@ -0,0 +1,46 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "OWSUnknownContactBlockOfferMessage.h"
NS_ASSUME_NONNULL_BEGIN
@interface OWSUnknownContactBlockOfferMessage ()
@property (nonatomic) NSString *contactId;
@end
#pragma mark -
@implementation OWSUnknownContactBlockOfferMessage
+ (instancetype)unknownContactBlockOfferMessage:(uint64_t)timestamp
thread:(TSThread *)thread
contactId:(NSString *)contactId
{
return [[OWSUnknownContactBlockOfferMessage alloc] initWithTimestamp:timestamp thread:thread contactId:contactId];
}
- (instancetype)initWithTimestamp:(uint64_t)timestamp thread:(TSThread *)thread contactId:(NSString *)contactId
{
self = [super initWithTimestamp:timestamp inThread:thread failedMessageType:TSErrorMessageUnknownContactBlockOffer];
if (self) {
_contactId = contactId;
}
return self;
}
- (nullable NSDate *)receiptDateForSorting
{
// Always use date, since we're creating these interactions after the fact
// and back-dating them.
return self.date;
}
@end
NS_ASSUME_NONNULL_END