Added ttl property on TSOutgoingMessage.

Use this ttl value when sending a message.
pull/18/head
Mikunj 5 years ago
parent 5a1272c23b
commit b5cc66262d

@ -35,7 +35,12 @@ public extension LokiAPI {
let wrappedMessage = try LokiMessageWrapper.wrap(message: signalMessage, timestamp: timestamp)
let data = wrappedMessage.base64EncodedString()
let destination = signalMessage["destination"] as! String
let ttl = LokiAPI.defaultMessageTTL
var ttl = LokiAPI.defaultMessageTTL
if let messageTTL = signalMessage["ttl"] as? UInt, messageTTL > 0 {
ttl = UInt64(messageTTL)
}
if isPoWRequired {
// The storage server takes a time interval in milliseconds
let now = NSDate.ows_millisecondTimeStamp()

@ -1,2 +1,3 @@
// This is basically OWSMessageServiceParams
public typealias SignalMessage = [String:Any]

@ -1,11 +1,17 @@
#import "LKFriendRequestMessage.h"
#import "OWSPrimaryStorage+Loki.h"
#import "NSDate+OWS.h"
#import "SignalRecipient.h"
#import <SignalServiceKit/SignalServiceKit-Swift.h>
@implementation LKFriendRequestMessage
-(BOOL)isFriendRequest { return YES; }
- (BOOL)isFriendRequest { return YES; }
- (uint)ttl {
// Friend requests should stay for the longest on the storage server
return 4 * kDayInterval;
}
- (SSKProtoContentBuilder *)contentBuilder:(SignalRecipient *)recipient {
SSKProtoContentBuilder *contentBuilder = [super contentBuilder:recipient];

@ -144,6 +144,9 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
// Loki: Bool to indicate if proof of work is being calculated for this message
@property (atomic, readonly) BOOL isCalculatingPoW;
// Loki: Time to live for the message
@property (nonatomic, readonly) uint ttl;
/**
* The data representation of this message, to be encrypted, before being sent.
*/

@ -1154,6 +1154,12 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
return [result copy];
}
- (uint)ttl {
// Time to live for all messages should be 1 day
// TODO: Change this to return a value that the user chose
return 1 * kDayInterval;
}
@end
NS_ASSUME_NONNULL_END

@ -1885,6 +1885,9 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
isSilent:isSilent
isOnline:isOnline
registrationId:[cipher throws_remoteRegistrationId:transaction]];
// Loki: Add the ttl to the message params
messageParams.ttl = message.ttl;
NSError *error;
NSDictionary *jsonDict = [MTLJSONAdapter JSONDictionaryFromModel:messageParams error:&error];

@ -23,6 +23,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) NSString *content;
@property (nonatomic, readonly) BOOL silent;
@property (nonatomic, readonly) BOOL online;
@property (nonatomic) uint ttl;
- (instancetype)initWithType:(TSWhisperMessageType)type
recipientId:(NSString *)destination

@ -36,6 +36,7 @@ NS_ASSUME_NONNULL_BEGIN
_content = [content base64EncodedString];
_silent = isSilent;
_online = isOnline;
_ttl = 0;
return self;
}

Loading…
Cancel
Save