Increase message TTL

pull/161/head
nielsandriesse 5 years ago
parent 8bf2215a24
commit d2dccc8b98

@ -43,7 +43,6 @@ public final class LokiAPI : NSObject {
internal static var powDifficulty: UInt = 2
public static let defaultMessageTTL: UInt64 = 24 * 60 * 60 * 1000
public static let deviceLinkUpdateInterval: TimeInterval = 20
// MARK: Nested Types

@ -34,7 +34,7 @@ public struct LokiMessage {
let wrappedMessage = try LokiMessageWrapper.wrap(message: signalMessage)
let data = wrappedMessage.base64EncodedString()
let destination = signalMessage.recipientID
var ttl = LokiAPI.defaultMessageTTL
var ttl = TTLUtilities.fallbackMessageTTL
if let messageTTL = signalMessage.ttl, messageTTL > 0 { ttl = UInt64(messageTTL) }
let isPing = signalMessage.isPing
return LokiMessage(destination: destination, data: data, ttl: ttl, isPing: isPing)

@ -44,6 +44,6 @@
}
#pragma mark Settings
- (uint)ttl { return 1 * kMinuteInMs; }
- (uint)ttl { return (uint)[LKTTLUtilities getTTLFor:LKMessageTypeAddress]; }
@end

@ -79,7 +79,7 @@
}
#pragma mark Settings
- (uint)ttl { return 4 * kMinuteInMs; }
- (uint)ttl { return (uint)[LKTTLUtilities getTTLFor:LKMessageTypeLinkDevice]; }
- (BOOL)shouldSyncTranscript { return NO; }
- (BOOL)shouldBeSaved { return NO; }

@ -13,6 +13,6 @@
#pragma mark Settings
- (BOOL)shouldSyncTranscript { return NO; }
- (BOOL)shouldBeSaved { return NO; }
- (uint)ttl { return 23 * kHourInMs; }
- (uint)ttl { return (uint)[LKTTLUtilities getTTLFor:LKMessageTypeEphemeral]; }
@end

@ -23,7 +23,7 @@
}
#pragma mark Settings
- (uint)ttl { return 4 * kDayInMs; }
- (uint)ttl { return (uint)[LKTTLUtilities getTTLFor:LKMessageTypeFriendRequest]; }
- (BOOL)shouldSyncTranscript { return NO; }
@end

@ -11,7 +11,7 @@
}
- (BOOL)shouldBeSaved { return NO; }
- (uint)ttl { return 23 * kHourInMs; }
- (uint)ttl { return (uint)[LKTTLUtilities getTTLFor:LKMessageTypeSessionRequest]; }
#pragma mark Building
- (nullable SSKProtoDataMessageBuilder *)dataMessageBuilder

@ -20,7 +20,7 @@
}
#pragma mark Settings
- (uint)ttl { return 4 * kDayInMs; }
- (uint)ttl { return (uint)[LKTTLUtilities getTTLFor:LKMessageTypeUnlinkDevice]; }
- (BOOL)shouldSyncTranscript { return NO; }
- (BOOL)shouldBeSaved { return NO; }

@ -0,0 +1,32 @@
@objc(LKTTLUtilities)
public final class TTLUtilities : NSObject {
/// If a message type specifies an invalid TTL, this will be used.
public static let fallbackMessageTTL: UInt64 = 4 * 24 * 60 * 60 * 1000
@objc(LKMessageType)
public enum MessageType : Int {
case address
case ephemeral
case friendRequest
case linkDevice
case regular
case sessionRequest
case typingIndicator
case unlinkDevice
}
@objc public static func getTTL(for messageType: MessageType) -> UInt64 {
switch messageType {
case .address: return 1 * kMinuteInMs
case .ephemeral: return 4 * kDayInMs - 1 * kHourInMs
case .friendRequest: return 4 * kDayInMs
case .linkDevice: return 4 * kMinuteInMs
case .sessionRequest: return 4 * kDayInMs - 1 * kHourInMs
case .regular: return 2 * kDayInMs
case .typingIndicator: return 1 * kMinuteInMs
case .unlinkDevice: return 4 * kDayInMs
}
}
}

@ -1155,9 +1155,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
return [result copy];
}
- (uint)ttl {
return 1 * kDayInMs; // TODO: Change this to return a value that the user chose
}
- (uint)ttl { return (uint)[LKTTLUtilities getTTLFor:LKMessageTypeRegular]; }
@end

@ -101,7 +101,7 @@ public class TypingIndicatorMessage: TSOutgoingMessage {
}
@objc
public override var ttl: UInt32 { return UInt32(2 * kMinuteInMs) }
public override var ttl: UInt32 { return UInt32(TTLUtilities.getTTL(for: .typingIndicator)) }
@objc
public override var debugDescription: String {

Loading…
Cancel
Save