Implement sending side of revocation
This commit is contained in:
parent
936424e344
commit
850346acf2
|
@ -112,17 +112,17 @@ final class DeviceLinksVC : UIViewController, UITableViewDataSource, UITableView
|
|||
|
||||
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
defer { tableView.deselectRow(at: indexPath, animated: true) }
|
||||
let device = deviceLinks[indexPath.row].other
|
||||
let deviceLink = deviceLinks[indexPath.row]
|
||||
let sheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
|
||||
sheet.addAction(UIAlertAction(title: NSLocalizedString("Change Name", comment: ""), style: .default) { [weak self] _ in
|
||||
guard let self = self else { return }
|
||||
let deviceNameModal = DeviceNameModal()
|
||||
deviceNameModal.device = device
|
||||
deviceNameModal.device = deviceLink.other
|
||||
deviceNameModal.delegate = self
|
||||
self.present(deviceNameModal, animated: true, completion: nil)
|
||||
})
|
||||
sheet.addAction(UIAlertAction(title: NSLocalizedString("Unlink", comment: ""), style: .destructive) { _ in
|
||||
// TODO: Implement
|
||||
sheet.addAction(UIAlertAction(title: NSLocalizedString("Unlink", comment: ""), style: .destructive) { [weak self] _ in
|
||||
self?.removeDeviceLink(deviceLink)
|
||||
})
|
||||
sheet.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .cancel) { _ in })
|
||||
present(sheet, animated: true, completion: nil)
|
||||
|
@ -132,6 +132,19 @@ final class DeviceLinksVC : UIViewController, UITableViewDataSource, UITableView
|
|||
dismiss(animated: true, completion: nil)
|
||||
updateUI()
|
||||
}
|
||||
|
||||
private func removeDeviceLink(_ deviceLink: DeviceLink) {
|
||||
LokiStorageAPI.removeDeviceLink(deviceLink).done { [weak self] in
|
||||
guard let thread = TSContactThread.fetch(uniqueId: TSContactThread.threadId(fromContactId: deviceLink.other.hexEncodedPublicKey)) else { return }
|
||||
let unlinkDeviceMessage = UnlinkDeviceMessage(thread: thread)!
|
||||
ThreadUtil.enqueue(unlinkDeviceMessage)
|
||||
self?.updateDeviceLinks()
|
||||
}.catch { [weak self] _ in
|
||||
let alert = UIAlertController(title: NSLocalizedString("Couldn't Unlink Device", comment: ""), message: NSLocalizedString("Please check your internet connection and try again", comment: ""), preferredStyle: .alert)
|
||||
alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: ""), accessibilityIdentifier: nil, style: .default, handler: nil))
|
||||
self?.present(alert, animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Cell
|
||||
|
|
|
@ -2665,3 +2665,5 @@
|
|||
"Enter a Name" = "Enter a Name";
|
||||
"Error" = "Error";
|
||||
"Please pick a name" = "Please pick a name";
|
||||
"Couldn't Unlink Device" = "Couldn't Unlink Device";
|
||||
"Please check your internet connection and try again" = "Please check your internet connection and try again";
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class LKDeviceLinkMessage;
|
||||
@class LKUnlinkDeviceMessage;
|
||||
@class OWSBlockingManager;
|
||||
@class OWSContact;
|
||||
@class OWSContactsManager;
|
||||
|
@ -47,6 +48,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
+ (TSOutgoingMessage *)enqueueFriendRequestAcceptanceMessageInThread:(TSThread *)thread;
|
||||
+ (void)enqueueDeviceLinkMessage:(LKDeviceLinkMessage *)message;
|
||||
+ (void)enqueueUnlinkDeviceMessage:(LKUnlinkDeviceMessage *)message;
|
||||
|
||||
+ (TSOutgoingMessage *)enqueueMessageWithText:(NSString *)fullMessageText
|
||||
inThread:(TSThread *)thread
|
||||
|
|
|
@ -101,6 +101,13 @@ typedef void (^BuildOutgoingMessageCompletionBlock)(TSOutgoingMessage *savedMess
|
|||
}];
|
||||
}
|
||||
|
||||
+ (void)enqueueUnlinkDeviceMessage:(LKUnlinkDeviceMessage *)message
|
||||
{
|
||||
[self.dbConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self.messageSenderJobQueue addMessage:message transaction:transaction];
|
||||
}];
|
||||
}
|
||||
|
||||
+ (TSOutgoingMessage *)enqueueMessageWithText:(NSString *)fullMessageText
|
||||
inThread:(TSThread *)thread
|
||||
quotedReplyModel:(nullable OWSQuotedReplyModel *)quotedReplyModel
|
||||
|
|
|
@ -148,6 +148,7 @@ message DataMessage {
|
|||
END_SESSION = 1;
|
||||
EXPIRATION_TIMER_UPDATE = 2;
|
||||
PROFILE_KEY_UPDATE = 4;
|
||||
UNLINK_DEVICE = 8;
|
||||
}
|
||||
|
||||
message Quote {
|
||||
|
@ -247,7 +248,7 @@ message DataMessage {
|
|||
// Loki: A custom message for our profile
|
||||
message LokiProfile {
|
||||
optional string displayName = 1;
|
||||
optional AttachmentPointer avatar = 2;
|
||||
optional string profilePicture = 2;
|
||||
}
|
||||
|
||||
optional string body = 1;
|
||||
|
|
|
@ -92,7 +92,7 @@ public final class LokiStorageAPI : LokiDotNetAPI {
|
|||
let url = URL(string: "\(server)/users/me")!
|
||||
let request = TSRequest(url: url, method: "PATCH", parameters: parameters)
|
||||
request.allHTTPHeaderFields = [ "Content-Type" : "application/json", "Authorization" : "Bearer \(token)" ]
|
||||
return TSNetworkManager.shared().perform(request, withCompletionQueue: DispatchQueue.global()).map { _ in }.recover(on: DispatchQueue.global()) { error in
|
||||
return TSNetworkManager.shared().perform(request, withCompletionQueue: DispatchQueue.global()).map { _ in }.retryingIfNeeded(maxRetryCount: 8).recover(on: DispatchQueue.global()) { error in
|
||||
print("Couldn't update device links due to error: \(error).")
|
||||
throw error
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
typedef NS_ENUM(NSUInteger, LKDeviceLinkMessageKind) {
|
||||
LKDeviceLinkMessageKindRequest = 1,
|
||||
LKDeviceLinkMessageKindAuthorization = 2,
|
||||
LKDeviceLinkMessageKindRevocation = 3
|
||||
};
|
||||
|
||||
NS_SWIFT_NAME(DeviceLinkMessage)
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
#import "TSOutgoingMessage.h"
|
||||
|
||||
NS_SWIFT_NAME(UnlinkDeviceMessage)
|
||||
@interface LKUnlinkDeviceMessage : TSOutgoingMessage
|
||||
|
||||
- (instancetype)initWithThread:(TSThread *)thread;
|
||||
|
||||
@end
|
|
@ -0,0 +1,26 @@
|
|||
#import "LKUnlinkDeviceMessage.h"
|
||||
#import <SignalCoreKit/NSDate+OWS.h>
|
||||
#import <SignalServiceKit/SignalServiceKit-Swift.h>
|
||||
|
||||
@implementation LKUnlinkDeviceMessage
|
||||
|
||||
#pragma mark Initialization
|
||||
- (instancetype)initWithThread:(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 Building
|
||||
- (nullable SSKProtoDataMessageBuilder *)dataMessageBuilder
|
||||
{
|
||||
SSKProtoDataMessageBuilder *builder = super.dataMessageBuilder;
|
||||
if (builder == nil) { return nil; }
|
||||
[builder setFlags:SSKProtoDataMessageFlagsUnlinkDevice];
|
||||
return builder;
|
||||
}
|
||||
|
||||
#pragma mark Settings
|
||||
- (BOOL)shouldSyncTranscript { return NO; }
|
||||
- (BOOL)shouldBeSaved { return NO; }
|
||||
|
||||
@end
|
|
@ -3433,6 +3433,7 @@ extension SSKProtoDataMessageLokiProfile.SSKProtoDataMessageLokiProfileBuilder {
|
|||
case endSession = 1
|
||||
case expirationTimerUpdate = 2
|
||||
case profileKeyUpdate = 4
|
||||
case unlinkDevice = 8
|
||||
}
|
||||
|
||||
private class func SSKProtoDataMessageFlagsWrap(_ value: SignalServiceProtos_DataMessage.Flags) -> SSKProtoDataMessageFlags {
|
||||
|
@ -3440,6 +3441,7 @@ extension SSKProtoDataMessageLokiProfile.SSKProtoDataMessageLokiProfileBuilder {
|
|||
case .endSession: return .endSession
|
||||
case .expirationTimerUpdate: return .expirationTimerUpdate
|
||||
case .profileKeyUpdate: return .profileKeyUpdate
|
||||
case .unlinkDevice: return .unlinkDevice
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3448,6 +3450,7 @@ extension SSKProtoDataMessageLokiProfile.SSKProtoDataMessageLokiProfileBuilder {
|
|||
case .endSession: return .endSession
|
||||
case .expirationTimerUpdate: return .expirationTimerUpdate
|
||||
case .profileKeyUpdate: return .profileKeyUpdate
|
||||
case .unlinkDevice: return .unlinkDevice
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -881,6 +881,7 @@ struct SignalServiceProtos_DataMessage {
|
|||
case endSession // = 1
|
||||
case expirationTimerUpdate // = 2
|
||||
case profileKeyUpdate // = 4
|
||||
case unlinkDevice // = 8
|
||||
|
||||
init() {
|
||||
self = .endSession
|
||||
|
@ -891,6 +892,7 @@ struct SignalServiceProtos_DataMessage {
|
|||
case 1: self = .endSession
|
||||
case 2: self = .expirationTimerUpdate
|
||||
case 4: self = .profileKeyUpdate
|
||||
case 8: self = .unlinkDevice
|
||||
default: return nil
|
||||
}
|
||||
}
|
||||
|
@ -900,6 +902,7 @@ struct SignalServiceProtos_DataMessage {
|
|||
case .endSession: return 1
|
||||
case .expirationTimerUpdate: return 2
|
||||
case .profileKeyUpdate: return 4
|
||||
case .unlinkDevice: return 8
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3476,6 +3479,7 @@ extension SignalServiceProtos_DataMessage.Flags: SwiftProtobuf._ProtoNameProvidi
|
|||
1: .same(proto: "END_SESSION"),
|
||||
2: .same(proto: "EXPIRATION_TIMER_UPDATE"),
|
||||
4: .same(proto: "PROFILE_KEY_UPDATE"),
|
||||
8: .same(proto: "UNLINK_DEVICE"),
|
||||
]
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue