mirror of https://github.com/oxen-io/session-ios
Merge branch 'mkirk/profile-key-flag'
commit
1aeccc6a4e
@ -0,0 +1,50 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class DebugUIProfile: DebugUIPage {
|
||||
|
||||
let TAG = "[DebugUIProfile]"
|
||||
|
||||
// MARK: Dependencies
|
||||
|
||||
var messageSender: MessageSender {
|
||||
return Environment.getCurrent().messageSender
|
||||
}
|
||||
var profileManager: OWSProfileManager {
|
||||
return OWSProfileManager.shared()
|
||||
}
|
||||
|
||||
// MARK: Overrides
|
||||
|
||||
override func name() -> String {
|
||||
return "Profile"
|
||||
}
|
||||
|
||||
override func section(thread aThread: TSThread?) -> OWSTableSection? {
|
||||
let sectionItems = [
|
||||
OWSTableItem(title: "Clear Profile Whitelist") {
|
||||
self.profileManager.clearProfileWhitelist()
|
||||
},
|
||||
OWSTableItem(title: "Log Profile Whitelist") {
|
||||
self.profileManager.logProfileWhitelist()
|
||||
},
|
||||
OWSTableItem(title: "Regenerate Profile/ProfileKey") {
|
||||
self.profileManager.regenerateLocalProfile()
|
||||
},
|
||||
OWSTableItem(title: "Send profile key message.") {
|
||||
let message = OWSProfileKeyMessage(timestamp: NSDate.ows_millisecondTimeStamp(), in: aThread)
|
||||
self.messageSender.sendPromise(message: message).then {
|
||||
Logger.info("Successfully sent profile key message to thread: \(String(describing: aThread))")
|
||||
}.catch { _ in
|
||||
owsFail("Failed to send profile key message to thread: \(String(describing: aThread))")
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
return OWSTableSection(title: "Profile", items: sectionItems)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TSOutgoingMessage.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface OWSProfileKeyMessage : TSOutgoingMessage
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -0,0 +1,50 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OWSProfileKeyMessage.h"
|
||||
#import "OWSSignalServiceProtos.pb.h"
|
||||
#import "ProfileManagerProtocol.h"
|
||||
#import "ProtoBuf+OWS.h"
|
||||
#import "TextSecureKitEnv.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@implementation OWSProfileKeyMessage
|
||||
|
||||
- (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
// override superclass with no-op.
|
||||
//
|
||||
// There's no need to save this message, since it's not displayed to the user.
|
||||
}
|
||||
|
||||
- (BOOL)shouldSyncTranscript
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (OWSSignalServiceProtosDataMessage *)buildDataMessage:(NSString *_Nullable)recipientId
|
||||
{
|
||||
OWSAssert(self.thread);
|
||||
|
||||
OWSSignalServiceProtosDataMessageBuilder *builder = [self dataMessageBuilder];
|
||||
[builder addLocalProfileKey];
|
||||
[builder setFlags:OWSSignalServiceProtosDataMessageFlagsProfileKey];
|
||||
|
||||
if (recipientId.length > 0) {
|
||||
// Once we've shared our profile key with a user (perhaps due to being
|
||||
// a member of a whitelisted group), make sure they're whitelisted.
|
||||
id<ProfileManagerProtocol> profileManager = [TextSecureKitEnv sharedEnv].profileManager;
|
||||
// FIXME PERF avoid this dispatch. It's going to happen for *each* recipient in a group message.
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[profileManager addUserToProfileWhitelist:recipientId];
|
||||
});
|
||||
}
|
||||
|
||||
return [builder build];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
Loading…
Reference in New Issue