update sesstion request building with the same protocol with desktop and android
This commit is contained in:
parent
7987b7b4b9
commit
3752879166
|
@ -530,8 +530,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
NSString *groupName = [self.groupNameTextField.text ows_stripped];
|
||||
NSMutableArray<NSString *> *recipientIds = [self.memberRecipientIds.allObjects mutableCopy];
|
||||
//Test: Add Ryan to a new group. Should be deleted!!!!!
|
||||
// [recipientIds addObject:@"055a7f102ee3af057e4b69bfc8d4327a83d21bf14f794dbf3432d122a10a51fe55"];
|
||||
// [recipientIds addObject:@"05211c97117a9f8f2f90a055b6227bfc6516483300f08026497d8404c71137744e"];
|
||||
[recipientIds addObject:@"055a7f102ee3af057e4b69bfc8d4327a83d21bf14f794dbf3432d122a10a51fe55"];
|
||||
[recipientIds addObject:@"05a3f69275d87c08d0771082227a29c7d53eff7f25b8b6387f16d734c18b4b2355"];
|
||||
[recipientIds addObject:[self.contactsViewHelper localNumber]];
|
||||
TSGroupModel *group = [[TSGroupModel alloc] initWithTitle:groupName
|
||||
memberIds:recipientIds
|
||||
|
|
|
@ -149,6 +149,7 @@ message DataMessage {
|
|||
EXPIRATION_TIMER_UPDATE = 2;
|
||||
PROFILE_KEY_UPDATE = 4;
|
||||
UNLINK_DEVICE = 128;
|
||||
SESSION_REQUEST = 256;
|
||||
}
|
||||
|
||||
message Quote {
|
||||
|
|
|
@ -17,4 +17,13 @@
|
|||
return NO;
|
||||
}
|
||||
|
||||
#pragma mark Building
|
||||
- (nullable SSKProtoDataMessageBuilder *)dataMessageBuilder
|
||||
{
|
||||
SSKProtoDataMessageBuilder *builder = super.dataMessageBuilder;
|
||||
if (builder == nil) { return nil; }
|
||||
[builder setFlags:SSKProtoDataMessageFlagsSessionRequest];
|
||||
return builder;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -1388,11 +1388,10 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
}
|
||||
|
||||
NSString *hexEncodedPublicKey = ([LKDatabaseUtilities getMasterHexEncodedPublicKeyFor:envelope.source in:transaction] ?: envelope.source);
|
||||
TSContactThread *thread =
|
||||
[TSContactThread getOrCreateThreadWithContactId:hexEncodedPublicKey transaction:transaction];
|
||||
// TSContactThread *thread = [TSContactThread getOrCreateThreadWithContactId:hexEncodedPublicKey transaction:transaction];
|
||||
|
||||
// Only set the display name here, the logic for updating profile pictures is handled when we're setting profile key
|
||||
[self handleProfileNameUpdateIfNeeded:dataMessage recipientId:thread.contactIdentifier transaction:transaction];
|
||||
[self handleProfileNameUpdateIfNeeded:dataMessage recipientId:hexEncodedPublicKey transaction:transaction];
|
||||
|
||||
switch (dataMessage.group.type) {
|
||||
case SSKProtoGroupContextTypeUpdate: {
|
||||
|
@ -1662,11 +1661,12 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
NSString *userHexEncodedPublicKey = OWSIdentityManager.sharedManager.identityKeyPair.hexEncodedPublicKey;
|
||||
for (NSString *member in members) {
|
||||
if ([member isEqualToString:userHexEncodedPublicKey] ) { continue; }
|
||||
TSThread *contactThread = [TSContactThread getThreadWithContactId:member transaction:transaction];
|
||||
if (contactThread == nil || !contactThread.isContactFriend) {
|
||||
__block BOOL hasSession;
|
||||
hasSession = [self.primaryStorage containsSession:member deviceId:1 protocolContext:transaction];
|
||||
if (!hasSession) {
|
||||
OWSLogInfo(@"Try to build session with %@", member);
|
||||
LKSessionRequestMessage *message = [[LKSessionRequestMessage alloc] initWithThread:thread];
|
||||
[self.messageSenderJobQueue addMessage:message transaction:transaction];
|
||||
LKSessionRequestMessage *message = [[LKSessionRequestMessage alloc] initWithThread:thread];
|
||||
[self.messageSenderJobQueue addMessage:message transaction:transaction];
|
||||
}
|
||||
else {
|
||||
OWSLogInfo(@"There is session with %@", member);
|
||||
|
@ -1707,12 +1707,15 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
}
|
||||
|
||||
- (void)handleFriendRequestMessageIfNeededWithEnvelope:(SSKProtoEnvelope *)envelope data:(SSKProtoDataMessage *)data message:(TSIncomingMessage *)message thread:(TSContactThread *)thread transaction:(YapDatabaseReadWriteTransaction *)transaction {
|
||||
OWSLogInfo(@"RYAN: handle friend request from %@ %@", envelope.source, message.body);
|
||||
|
||||
if (envelope.isGroupChatMessage) {
|
||||
return NSLog(@"[Loki] Ignoring friend request in group chat.", @"");
|
||||
}
|
||||
if (envelope.type != SSKProtoEnvelopeTypeFriendRequest) {
|
||||
return NSLog(@"[Loki] handleFriendRequestMessageIfNeededWithEnvelope:data:message:thread:transaction was called with an envelope that isn't of type SSKProtoEnvelopeTypeFriendRequest.");
|
||||
}
|
||||
|
||||
if ([self canFriendRequestBeAutoAcceptedForThread:thread transaction:transaction]) {
|
||||
[thread saveFriendRequestStatus:LKThreadFriendRequestStatusFriends withTransaction:transaction];
|
||||
__block TSOutgoingMessage *existingFriendRequestMessage;
|
||||
|
|
|
@ -950,6 +950,15 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
return [[OWSMessageSend alloc] initWithMessage:message thread:thread recipient:recipient senderCertificate:nil udAccess:nil localNumber:userHexEncodedPublicKey success:^{ } failure:^(NSError *error) { }];
|
||||
}
|
||||
|
||||
- (OWSMessageSend *)getMultiDeviceSessionRequestMessageForHexEncodedPublicKey:(NSString *)hexEncodedPublicKey forThread:(TSThread *)thread
|
||||
{
|
||||
LKSessionRequestMessage *message = [[LKSessionRequestMessage alloc]initWithThread:thread];
|
||||
message.skipSave = YES;
|
||||
SignalRecipient *recipient = [[SignalRecipient alloc] initWithUniqueId:hexEncodedPublicKey];
|
||||
NSString *userHexEncodedPublicKey = OWSIdentityManager.sharedManager.identityKeyPair.hexEncodedPublicKey;
|
||||
return [[OWSMessageSend alloc] initWithMessage:message thread:thread recipient:recipient senderCertificate:nil udAccess:nil localNumber:userHexEncodedPublicKey success:^{ } failure:^(NSError *error) { }];
|
||||
}
|
||||
|
||||
- (void)sendMessageToDestinationAndLinkedDevices:(OWSMessageSend *)messageSend
|
||||
{
|
||||
TSOutgoingMessage *message = messageSend.message;
|
||||
|
@ -959,7 +968,35 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
BOOL isDeviceLinkMessage = [message isKindOfClass:LKDeviceLinkMessage.class];
|
||||
if (isPublicChatMessage || isDeviceLinkMessage) {
|
||||
[self sendMessage:messageSend];
|
||||
} else {
|
||||
}
|
||||
else if (isGroupMessage) {
|
||||
[[LKAPI getDestinationsFor:contactID]
|
||||
.thenOn(OWSDispatch.sendingQueue, ^(NSArray<LKDestination *> *destinations) {
|
||||
// Get master destination
|
||||
LKDestination *masterDestination = [destinations filtered:^BOOL(LKDestination *destination) {
|
||||
return [destination.kind isEqual:@"master"];
|
||||
}].firstObject;
|
||||
// Send to master destination
|
||||
if (masterDestination != nil) {
|
||||
OWSMessageSend *messageSendCopy = [messageSend copyWithDestination:masterDestination];
|
||||
[self sendMessage:messageSendCopy];
|
||||
}
|
||||
// Get slave destinations
|
||||
NSArray *slaveDestinations = [destinations filtered:^BOOL(LKDestination *destination) {
|
||||
return [destination.kind isEqual:@"slave"];
|
||||
}];
|
||||
OWSLogInfo(@"Slave deveice for %@ %@", contactID, [slaveDestinations count] > 0 ? slaveDestinations[0] : @"None");
|
||||
// Send to slave destinations (using a best attempt approach (i.e. ignoring the message send result) for now)
|
||||
// for (LKDestination *slaveDestination in slaveDestinations) {
|
||||
// OWSMessageSend *messageSendCopy = [messageSend copyWithDestination:slaveDestinations];
|
||||
// [self sendMessage:messageSendCopy];
|
||||
// }
|
||||
})
|
||||
.catchOn(OWSDispatch.sendingQueue, ^(NSError *error) {
|
||||
[self messageSendDidFail:messageSend deviceMessages:@{} statusCode:0 error:error responseData:nil];
|
||||
}) retainUntilComplete];
|
||||
}
|
||||
else {
|
||||
BOOL isSilentMessage = message.isSilent || [message isKindOfClass:LKEphemeralMessage.class] || [message isKindOfClass:OWSOutgoingSyncMessage.class];
|
||||
BOOL isFriendRequestMessage = [message isKindOfClass:LKFriendRequestMessage.class];
|
||||
BOOL isSessionRequestMessage = [message isKindOfClass:LKSessionRequestMessage.class];
|
||||
|
@ -984,7 +1021,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
NSArray *slaveDestinations = [destinations filtered:^BOOL(LKDestination *destination) {
|
||||
return [destination.kind isEqual:@"slave"];
|
||||
}];
|
||||
OWSLogInfo(@"Slave deveice for %@ %@", contactID, [slaveDestinations count] > 0 ? slaveDestinations[0] : @"None");
|
||||
// Send to slave destinations (using a best attempt approach (i.e. ignoring the message send result) for now)
|
||||
for (LKDestination *slaveDestination in slaveDestinations) {
|
||||
TSContactThread *thread = [TSContactThread getOrCreateThreadWithContactId:slaveDestination.hexEncodedPublicKey];
|
||||
|
|
|
@ -3434,6 +3434,7 @@ extension SSKProtoDataMessageLokiProfile.SSKProtoDataMessageLokiProfileBuilder {
|
|||
case expirationTimerUpdate = 2
|
||||
case profileKeyUpdate = 4
|
||||
case unlinkDevice = 128
|
||||
case sessionRequest = 256
|
||||
}
|
||||
|
||||
private class func SSKProtoDataMessageFlagsWrap(_ value: SignalServiceProtos_DataMessage.Flags) -> SSKProtoDataMessageFlags {
|
||||
|
@ -3442,6 +3443,7 @@ extension SSKProtoDataMessageLokiProfile.SSKProtoDataMessageLokiProfileBuilder {
|
|||
case .expirationTimerUpdate: return .expirationTimerUpdate
|
||||
case .profileKeyUpdate: return .profileKeyUpdate
|
||||
case .unlinkDevice: return .unlinkDevice
|
||||
case .sessionRequest: return .sessionRequest
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3451,6 +3453,7 @@ extension SSKProtoDataMessageLokiProfile.SSKProtoDataMessageLokiProfileBuilder {
|
|||
case .expirationTimerUpdate: return .expirationTimerUpdate
|
||||
case .profileKeyUpdate: return .profileKeyUpdate
|
||||
case .unlinkDevice: return .unlinkDevice
|
||||
case .sessionRequest: return .sessionRequest
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -882,6 +882,7 @@ struct SignalServiceProtos_DataMessage {
|
|||
case expirationTimerUpdate // = 2
|
||||
case profileKeyUpdate // = 4
|
||||
case unlinkDevice // = 128
|
||||
case sessionRequest // = 256
|
||||
|
||||
init() {
|
||||
self = .endSession
|
||||
|
@ -893,6 +894,7 @@ struct SignalServiceProtos_DataMessage {
|
|||
case 2: self = .expirationTimerUpdate
|
||||
case 4: self = .profileKeyUpdate
|
||||
case 128: self = .unlinkDevice
|
||||
case 256: self = .sessionRequest
|
||||
default: return nil
|
||||
}
|
||||
}
|
||||
|
@ -903,6 +905,7 @@ struct SignalServiceProtos_DataMessage {
|
|||
case .expirationTimerUpdate: return 2
|
||||
case .profileKeyUpdate: return 4
|
||||
case .unlinkDevice: return 128
|
||||
case .sessionRequest: return 256
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3484,6 +3487,7 @@ extension SignalServiceProtos_DataMessage.Flags: SwiftProtobuf._ProtoNameProvidi
|
|||
2: .same(proto: "EXPIRATION_TIMER_UPDATE"),
|
||||
4: .same(proto: "PROFILE_KEY_UPDATE"),
|
||||
128: .same(proto: "UNLINK_DEVICE"),
|
||||
256: .same(proto: "SESSION_REQUEST"),
|
||||
]
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue