Add better logging & fix message routing issues

pull/70/head
Niels Andriesse 6 years ago
parent a2c09370bb
commit 2e35628ce9

@ -0,0 +1,12 @@
// For some reason NSLog doesn't seem to work. This is a workaround to still allow debugging from Obj-C.
@objc(LKLogger)
public final class Objc_Logger : NSObject {
private override init() { }
@objc public static func print(_ message: String) {
Swift.print(message)
}
}

@ -673,7 +673,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
}
// Loki: Handle note to self case
if ([thread isKindOfClass:[TSContactThread class]]) {
if ([thread isKindOfClass:[TSContactThread class]] && ![message isKindOfClass:OWSOutgoingSyncMessage.class] && ![message isKindOfClass:LKDeviceLinkMessage.class]) {
__block BOOL isNoteToSelf;
[OWSPrimaryStorage.sharedManager.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
isNoteToSelf = [LKDatabaseUtilities isUserLinkedDevice:((TSContactThread *)thread).contactIdentifier in:transaction];
@ -1241,10 +1241,23 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
failedMessageSend(error);
}) retainUntilComplete];
} else {
NSString *targetHexEncodedPublicKey = recipient.recipientId;
NSString *userHexEncodedPublicKey = OWSIdentityManager.sharedManager.identityKeyPair.hexEncodedPublicKey;
__block BOOL isUserLinkedDevice;
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
isUserLinkedDevice = [LKDatabaseUtilities isUserLinkedDevice:targetHexEncodedPublicKey in:transaction];
}];
if ([targetHexEncodedPublicKey isEqual:userHexEncodedPublicKey]) {
[LKLogger print:[NSString stringWithFormat:@"[Loki] Sending %@ to self.", message.class]];
} else if (isUserLinkedDevice) {
[LKLogger print:[NSString stringWithFormat:@"[Loki] Sending %@ to %@ (one of the current user's linked devices).", message.class, recipient.recipientId]];
} else {
[LKLogger print:[NSString stringWithFormat:@"[Loki] Sending %@ to %@.", message.class, recipient.recipientId]];
}
NSDictionary *signalMessageInfo = deviceMessages.firstObject;
SSKProtoEnvelopeType type = ((NSNumber *)signalMessageInfo[@"type"]).integerValue;
uint64_t timestamp = message.timestamp;
NSString *senderID = OWSIdentityManager.sharedManager.identityKeyPair.hexEncodedPublicKey;
NSString *senderID = userHexEncodedPublicKey;
uint32_t senderDeviceID = OWSDevicePrimaryDeviceId;
NSString *content = signalMessageInfo[@"content"];
NSString *recipientID = signalMessageInfo[@"destination"];
@ -1578,7 +1591,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
BOOL isPublicChatMessage = message.thread.isGroupThread;
BOOL shouldSendTranscript = (AreRecipientUpdatesEnabled() || !message.hasSyncedTranscript) && !isNoteToSelf && !isPublicChatMessage;
BOOL shouldSendTranscript = (AreRecipientUpdatesEnabled() || !message.hasSyncedTranscript) && !isNoteToSelf && !isPublicChatMessage && !([message isKindOfClass:LKDeviceLinkMessage.class]);
if (!shouldSendTranscript) {
return success();
}

Loading…
Cancel
Save