Clean message types & re-order files

pull/63/head
Niels Andriesse 6 years ago
parent f9d6f1dce3
commit db32a9f980

@ -13,6 +13,7 @@
@implementation LKAddressMessage @implementation LKAddressMessage
#pragma mark Initialization
- (instancetype)initInThread:(nullable TSThread *)thread address:(NSString *)address port:(uint16_t)port isPing:(bool)isPing - (instancetype)initInThread:(nullable TSThread *)thread address:(NSString *)address port:(uint16_t)port isPing:(bool)isPing
{ {
self = [super initInThread:thread]; self = [super initInThread:thread];
@ -24,28 +25,25 @@
return self; return self;
} }
#pragma mark Building
- (SSKProtoContentBuilder *)prepareCustomContentBuilder:(SignalRecipient *)recipient { - (SSKProtoContentBuilder *)prepareCustomContentBuilder:(SignalRecipient *)recipient {
SSKProtoContentBuilder *contentBuilder = SSKProtoContent.builder; SSKProtoContentBuilder *contentBuilder = SSKProtoContent.builder;
SSKProtoLokiAddressMessageBuilder *addressMessageBuilder = SSKProtoLokiAddressMessage.builder;
SSKProtoLokiAddressMessageBuilder *addressBuilder = [SSKProtoLokiAddressMessage builder]; [addressMessageBuilder setPtpAddress:self.address];
[addressBuilder setPtpAddress:self.address];
uint32_t portAsUInt32 = self.port; uint32_t portAsUInt32 = self.port;
[addressBuilder setPtpPort:portAsUInt32]; [addressMessageBuilder setPtpPort:portAsUInt32];
NSError *error; NSError *error;
SSKProtoLokiAddressMessage *addressMessage = [addressBuilder buildAndReturnError:&error]; SSKProtoLokiAddressMessage *addressMessage = [addressMessageBuilder buildAndReturnError:&error];
if (error || !addressMessage) { if (error || !addressMessage) {
OWSFailDebug(@"Failed to build Loki address message for: %@ due to error: %@.", recipient.recipientId, error); OWSFailDebug(@"Failed to build Loki address message for: %@ due to error: %@.", recipient.recipientId, error);
return nil;
} else { } else {
[contentBuilder setLokiAddressMessage:addressMessage]; [contentBuilder setLokiAddressMessage:addressMessage];
} }
return contentBuilder; return contentBuilder;
} }
- (uint)ttl { #pragma mark Settings
// Address messages should only last 1 minute - (uint)ttl { return 1 * kMinuteInMs; }
return 1 * kMinuteInMs;
}
@end @end

@ -4,11 +4,13 @@
@implementation LKEphemeralMessage @implementation LKEphemeralMessage
#pragma mark Initialization
- (instancetype)initInThread:(nullable TSThread *)thread { - (instancetype)initInThread:(nullable TSThread *)thread {
return [self initOutgoingMessageWithTimestamp:NSDate.ows_millisecondTimeStamp inThread:thread messageBody:@"" attachmentIds:[NSMutableArray<NSString *> new] return [self initOutgoingMessageWithTimestamp:NSDate.ows_millisecondTimeStamp inThread:thread messageBody:@"" attachmentIds:[NSMutableArray<NSString *> new]
expiresInSeconds:0 expireStartedAt:0 isVoiceMessage:NO groupMetaMessage:TSGroupMetaMessageUnspecified quotedMessage:nil contactShare:nil linkPreview:nil]; expiresInSeconds:0 expireStartedAt:0 isVoiceMessage:NO groupMetaMessage:TSGroupMetaMessageUnspecified quotedMessage:nil contactShare:nil linkPreview:nil];
} }
#pragma mark Settings
- (BOOL)shouldSyncTranscript { return NO; } - (BOOL)shouldSyncTranscript { return NO; }
- (BOOL)shouldBeSaved { return NO; } - (BOOL)shouldBeSaved { return NO; }

@ -1,10 +1,6 @@
#import "TSOutgoingMessage.h" #import "TSOutgoingMessage.h"
NS_ASSUME_NONNULL_BEGIN
NS_SWIFT_NAME(FriendRequestMessage) NS_SWIFT_NAME(FriendRequestMessage)
@interface LKFriendRequestMessage : TSOutgoingMessage @interface LKFriendRequestMessage : TSOutgoingMessage
@end @end
NS_ASSUME_NONNULL_END

@ -6,24 +6,23 @@
@implementation LKFriendRequestMessage @implementation LKFriendRequestMessage
#pragma mark Initialization
- (SSKProtoContentBuilder *)prepareCustomContentBuilder:(SignalRecipient *)recipient { - (SSKProtoContentBuilder *)prepareCustomContentBuilder:(SignalRecipient *)recipient {
SSKProtoContentBuilder *contentBuilder = SSKProtoContent.builder; SSKProtoContentBuilder *contentBuilder = SSKProtoContent.builder;
PreKeyBundle *bundle = [OWSPrimaryStorage.sharedManager generatePreKeyBundleForContact:recipient.recipientId]; PreKeyBundle *bundle = [OWSPrimaryStorage.sharedManager generatePreKeyBundleForContact:recipient.recipientId];
SSKProtoPrekeyBundleMessageBuilder *preKeyBuilder = [SSKProtoPrekeyBundleMessage builderFromPreKeyBundle:bundle]; SSKProtoPrekeyBundleMessageBuilder *preKeyBuilder = [SSKProtoPrekeyBundleMessage builderFromPreKeyBundle:bundle];
// Build the pre key bundle message
NSError *error; NSError *error;
SSKProtoPrekeyBundleMessage *_Nullable message = [preKeyBuilder buildAndReturnError:&error]; SSKProtoPrekeyBundleMessage *_Nullable message = [preKeyBuilder buildAndReturnError:&error];
if (error || !message) { if (error || !message) {
OWSFailDebug(@"Failed to build pre key bundle for: %@ due to error: %@.", recipient.recipientId, error); OWSFailDebug(@"Failed to build pre key bundle for: %@ due to error: %@.", recipient.recipientId, error);
return nil;
} else { } else {
[contentBuilder setPrekeyBundleMessage:message]; [contentBuilder setPrekeyBundleMessage:message];
} }
return contentBuilder; return contentBuilder;
} }
#pragma mark Settings
- (uint)ttl { return 4 * kDayInMs; } - (uint)ttl { return 4 * kDayInMs; }
@end @end

@ -7,8 +7,6 @@ public extension Notification.Name {
public static let threadDeleted = Notification.Name("threadDeleted") public static let threadDeleted = Notification.Name("threadDeleted")
} }
// MARK: - Obj-C
@objc public extension NSNotification { @objc public extension NSNotification {
@objc public static let contactOnlineStatusChanged = Notification.Name.contactOnlineStatusChanged.rawValue as NSString @objc public static let contactOnlineStatusChanged = Notification.Name.contactOnlineStatusChanged.rawValue as NSString
@objc public static let newMessagesReceived = Notification.Name.newMessagesReceived.rawValue as NSString @objc public static let newMessagesReceived = Notification.Name.newMessagesReceived.rawValue as NSString

@ -1,9 +1,9 @@
@objc public extension SSKProtoPrekeyBundleMessage { @objc public extension SSKProtoPrekeyBundleMessage {
@objc public static func builder(fromPreKeyBundle preKeyBundle: PreKeyBundle) -> SSKProtoPrekeyBundleMessageBuilder { @objc(builderFromPreKeyBundle:)
public static func builder(from preKeyBundle: PreKeyBundle) -> SSKProtoPrekeyBundleMessageBuilder {
let builder = self.builder() let builder = self.builder()
builder.setIdentityKey(preKeyBundle.identityKey) builder.setIdentityKey(preKeyBundle.identityKey)
builder.setDeviceID(UInt32(preKeyBundle.deviceId)) builder.setDeviceID(UInt32(preKeyBundle.deviceId))
builder.setPrekeyID(UInt32(preKeyBundle.preKeyId)) builder.setPrekeyID(UInt32(preKeyBundle.preKeyId))
@ -11,11 +11,11 @@
builder.setSignedKeyID(UInt32(preKeyBundle.signedPreKeyId)) builder.setSignedKeyID(UInt32(preKeyBundle.signedPreKeyId))
builder.setSignedKey(preKeyBundle.signedPreKeyPublic) builder.setSignedKey(preKeyBundle.signedPreKeyPublic)
builder.setSignature(preKeyBundle.signedPreKeySignature) builder.setSignature(preKeyBundle.signedPreKeySignature)
return builder return builder
} }
@objc public func createPreKeyBundle(withTransaction transaction: YapDatabaseReadWriteTransaction) -> PreKeyBundle? { @objc(getPreKeyBundleWithTransaction:)
public func getPreKeyBundle(with transaction: YapDatabaseReadWriteTransaction) -> PreKeyBundle? {
let registrationId = TSAccountManager.sharedInstance().getOrGenerateRegistrationId(transaction) let registrationId = TSAccountManager.sharedInstance().getOrGenerateRegistrationId(transaction)
return PreKeyBundle(registrationId: Int32(registrationId), deviceId: Int32(deviceID), preKeyId: Int32(prekeyID), preKeyPublic: prekey, return PreKeyBundle(registrationId: Int32(registrationId), deviceId: Int32(deviceID), preKeyId: Int32(prekeyID), preKeyPublic: prekey,
signedPreKeyPublic: signedKey, signedPreKeyId: Int32(signedKeyID), signedPreKeySignature: signature, identityKey: identityKey) signedPreKeyPublic: signedKey, signedPreKeyId: Int32(signedKeyID), signedPreKeySignature: signature, identityKey: identityKey)

@ -447,7 +447,7 @@ NS_ASSUME_NONNULL_BEGIN
// Loki: Handle pre key bundle message if needed // Loki: Handle pre key bundle message if needed
if (contentProto.prekeyBundleMessage != nil) { if (contentProto.prekeyBundleMessage != nil) {
OWSLogInfo(@"[Loki] Received a pre key bundle message from: %@.", envelope.source); OWSLogInfo(@"[Loki] Received a pre key bundle message from: %@.", envelope.source);
PreKeyBundle *_Nullable bundle = [contentProto.prekeyBundleMessage createPreKeyBundleWithTransaction:transaction]; PreKeyBundle *_Nullable bundle = [contentProto.prekeyBundleMessage getPreKeyBundleWithTransaction:transaction];
if (bundle == nil) { if (bundle == nil) {
OWSFailDebug(@"Failed to create a pre key bundle."); OWSFailDebug(@"Failed to create a pre key bundle.");
} }

Loading…
Cancel
Save