Clean message types & re-order files

This commit is contained in:
Niels Andriesse 2019-11-07 12:21:49 +11:00
parent f9d6f1dce3
commit db32a9f980
7 changed files with 19 additions and 26 deletions

View File

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

View File

@ -4,11 +4,13 @@
@implementation LKEphemeralMessage
#pragma mark Initialization
- (instancetype)initInThread:(nullable TSThread *)thread {
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];
}
#pragma mark Settings
- (BOOL)shouldSyncTranscript { return NO; }
- (BOOL)shouldBeSaved { return NO; }

View File

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

View File

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

View File

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

View File

@ -1,9 +1,9 @@
@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()
builder.setIdentityKey(preKeyBundle.identityKey)
builder.setDeviceID(UInt32(preKeyBundle.deviceId))
builder.setPrekeyID(UInt32(preKeyBundle.preKeyId))
@ -11,11 +11,11 @@
builder.setSignedKeyID(UInt32(preKeyBundle.signedPreKeyId))
builder.setSignedKey(preKeyBundle.signedPreKeyPublic)
builder.setSignature(preKeyBundle.signedPreKeySignature)
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)
return PreKeyBundle(registrationId: Int32(registrationId), deviceId: Int32(deviceID), preKeyId: Int32(prekeyID), preKeyPublic: prekey,
signedPreKeyPublic: signedKey, signedPreKeyId: Int32(signedKeyID), signedPreKeySignature: signature, identityKey: identityKey)

View File

@ -447,7 +447,7 @@ NS_ASSUME_NONNULL_BEGIN
// Loki: Handle pre key bundle message if needed
if (contentProto.prekeyBundleMessage != nil) {
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) {
OWSFailDebug(@"Failed to create a pre key bundle.");
}