pull/220/head
nielsandriesse 5 years ago
parent f59816af7d
commit 2e8663a1b0

@ -1 +1 @@
Subproject commit 1b860835167058d16fb18db2416f8482d08b982c Subproject commit 62dbf6a4090b77d62b3e073eed44b4b36b866797

@ -155,6 +155,7 @@ final class ConversationCell : UITableViewCell {
let randomUsers = users.sorted().prefix(2) // Sort to provide a level of stability let randomUsers = users.sorted().prefix(2) // Sort to provide a level of stability
profilePictureView.hexEncodedPublicKey = randomUsers.count >= 1 ? randomUsers[0] : "" profilePictureView.hexEncodedPublicKey = randomUsers.count >= 1 ? randomUsers[0] : ""
profilePictureView.additionalHexEncodedPublicKey = randomUsers.count >= 2 ? randomUsers[1] : "" profilePictureView.additionalHexEncodedPublicKey = randomUsers.count >= 2 ? randomUsers[1] : ""
profilePictureView.isRSSFeed = false
} }
} else { // A one-on-one chat } else { // A one-on-one chat
profilePictureView.hexEncodedPublicKey = threadViewModel.contactIdentifier! profilePictureView.hexEncodedPublicKey = threadViewModel.contactIdentifier!

@ -75,6 +75,7 @@ extern const NSUInteger kOWSProfileManager_MaxAvatarDiameter;
- (nullable OWSAES256Key *)profileKeyForRecipientId:(NSString *)recipientId; - (nullable OWSAES256Key *)profileKeyForRecipientId:(NSString *)recipientId;
- (nullable NSString *)profileNameForRecipientWithID:(NSString *)recipientID; - (nullable NSString *)profileNameForRecipientWithID:(NSString *)recipientID;
- (nullable NSString *)profileNameForRecipientWithID:(NSString *)recipientID transaction:(YapDatabaseReadWriteTransaction *)transaction;
- (nullable UIImage *)profileAvatarForRecipientId:(NSString *)recipientId; - (nullable UIImage *)profileAvatarForRecipientId:(NSString *)recipientId;
- (nullable NSData *)profileAvatarDataForRecipientId:(NSString *)recipientId; - (nullable NSData *)profileAvatarDataForRecipientId:(NSString *)recipientId;

@ -176,13 +176,12 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
#pragma mark - Local Profile #pragma mark - Local Profile
- (OWSUserProfile *)localUserProfile - (OWSUserProfile *)getLocalUserProfileWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@synchronized(self) @synchronized(self)
{ {
if (!_localUserProfile) { if (!_localUserProfile) {
_localUserProfile = [OWSUserProfile getOrBuildUserProfileForRecipientId:kLocalProfileUniqueId _localUserProfile = [OWSUserProfile getOrBuildUserProfileForRecipientId:kLocalProfileUniqueId transaction:transaction];
dbConnection:self.dbConnection];
} }
} }
@ -1023,13 +1022,22 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
} }
- (nullable NSString *)profileNameForRecipientWithID:(NSString *)recipientID - (nullable NSString *)profileNameForRecipientWithID:(NSString *)recipientID
{
__block NSString *result;
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
result = [self profileNameForRecipientWithID:recipientID transaction:transaction];
} error:nil];
return result;
}
- (nullable NSString *)profileNameForRecipientWithID:(NSString *)recipientID transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
OWSAssertDebug(recipientID.length > 0); OWSAssertDebug(recipientID.length > 0);
// For "local reads", use the local user profile. // For "local reads", use the local user profile.
OWSUserProfile *userProfile = ([self.tsAccountManager.localNumber isEqualToString:recipientID] OWSUserProfile *userProfile = [self.tsAccountManager.localNumber isEqualToString:recipientID]
? self.localUserProfile ? [self getLocalUserProfileWithTransaction:transaction]
: [OWSUserProfile getOrBuildUserProfileForRecipientId:recipientID dbConnection:self.dbConnection]); : [OWSUserProfile getOrBuildUserProfileForRecipientId:recipientID transaction:transaction];
return userProfile.profileName; return userProfile.profileName;
} }

@ -86,13 +86,13 @@ public extension LokiAPI {
let parameters: [String:Any] = [ "pubKey" : hexEncodedPublicKey ] let parameters: [String:Any] = [ "pubKey" : hexEncodedPublicKey ]
return getRandomSnode().then2 { return getRandomSnode().then2 {
invoke(.getSwarm, on: $0, associatedWith: hexEncodedPublicKey, parameters: parameters) invoke(.getSwarm, on: $0, associatedWith: hexEncodedPublicKey, parameters: parameters)
}.map2 { }.map2 { rawSnodes in
parseTargets(from: $0) let swarm = parseTargets(from: rawSnodes)
}.get2 { swarm in
swarmCache[hexEncodedPublicKey] = swarm swarmCache[hexEncodedPublicKey] = swarm
try! Storage.writeSync { transaction in try! Storage.writeSync { transaction in
storage.setSwarm(swarm, for: hexEncodedPublicKey, in: transaction) storage.setSwarm(swarm, for: hexEncodedPublicKey, in: transaction)
} }
return swarm
} }
} }
} }

@ -94,6 +94,7 @@ public final class LokiPoller : NSObject {
} }
private func poll(_ target: LokiAPITarget, seal longTermSeal: Resolver<Void>) -> Promise<Void> { private func poll(_ target: LokiAPITarget, seal longTermSeal: Resolver<Void>) -> Promise<Void> {
guard !hasStopped else { return Promise { $0.fulfill(()) } }
return LokiAPI.getRawMessages(from: target, usingLongPolling: false).then2 { [weak self] rawResponse -> Promise<Void> in return LokiAPI.getRawMessages(from: target, usingLongPolling: false).then2 { [weak self] rawResponse -> Promise<Void> in
guard let strongSelf = self, !strongSelf.hasStopped else { return Promise { $0.fulfill(()) } } guard let strongSelf = self, !strongSelf.hasStopped else { return Promise { $0.fulfill(()) } }
let messages = LokiAPI.parseRawMessagesResponse(rawResponse, from: target) let messages = LokiAPI.parseRawMessagesResponse(rawResponse, from: target)

@ -237,7 +237,7 @@ public final class SyncMessagesProtocol : NSObject {
} }
@objc(handleOpenGroupSyncMessageIfNeeded:wrappedIn:using:) @objc(handleOpenGroupSyncMessageIfNeeded:wrappedIn:using:)
public static func handleOpenGroupSyncMessageIfNeeded(_ syncMessage: SSKProtoSyncMessage, wrappedIn envelope: SSKProtoEnvelope, using transaction: YapDatabaseReadTransaction) { public static func handleOpenGroupSyncMessageIfNeeded(_ syncMessage: SSKProtoSyncMessage, wrappedIn envelope: SSKProtoEnvelope, using transaction: YapDatabaseReadWriteTransaction) {
let hexEncodedPublicKey = envelope.source! // Set during UD decryption let hexEncodedPublicKey = envelope.source! // Set during UD decryption
let linkedDevices = LokiDatabaseUtilities.getLinkedDeviceHexEncodedPublicKeys(for: hexEncodedPublicKey, in: transaction) let linkedDevices = LokiDatabaseUtilities.getLinkedDeviceHexEncodedPublicKeys(for: hexEncodedPublicKey, in: transaction)
let wasSentByLinkedDevice = linkedDevices.contains(hexEncodedPublicKey) let wasSentByLinkedDevice = linkedDevices.contains(hexEncodedPublicKey)
@ -249,7 +249,7 @@ public final class SyncMessagesProtocol : NSObject {
let openGroupManager = LokiPublicChatManager.shared let openGroupManager = LokiPublicChatManager.shared
guard openGroupManager.getChat(server: openGroup.url, channel: openGroup.channel) == nil else { return } guard openGroupManager.getChat(server: openGroup.url, channel: openGroup.channel) == nil else { return }
let userPublicKey = UserDefaults.standard[.masterHexEncodedPublicKey] ?? getUserHexEncodedPublicKey() let userPublicKey = UserDefaults.standard[.masterHexEncodedPublicKey] ?? getUserHexEncodedPublicKey()
let displayName = SSKEnvironment.shared.profileManager.profileNameForRecipient(withID: userPublicKey) let displayName = SSKEnvironment.shared.profileManager.profileNameForRecipient(withID: userPublicKey, transaction: transaction)
LokiPublicChatAPI.setDisplayName(to: displayName, on: openGroup.url) LokiPublicChatAPI.setDisplayName(to: displayName, on: openGroup.url)
openGroupManager.addChat(server: openGroup.url, channel: openGroup.channel) openGroupManager.addChat(server: openGroup.url, channel: openGroup.channel)
} }

@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable NSString *)localProfileName; - (nullable NSString *)localProfileName;
- (nullable NSString *)profileNameForRecipientWithID:(NSString *)recipientID; - (nullable NSString *)profileNameForRecipientWithID:(NSString *)recipientID;
- (nullable NSString *)profileNameForRecipientWithID:(NSString *)recipientID transaction:(YapDatabaseReadWriteTransaction *)transaction;
- (nullable NSString *)profilePictureURL; - (nullable NSString *)profilePictureURL;
- (nullable NSData *)profileKeyDataForRecipientId:(NSString *)recipientId; - (nullable NSData *)profileKeyDataForRecipientId:(NSString *)recipientId;

Loading…
Cancel
Save