Refactor
This commit is contained in:
parent
5b43cbc25a
commit
ccd2d30f61
|
@ -5,7 +5,7 @@
|
||||||
<key>BuildDetails</key>
|
<key>BuildDetails</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>CarthageVersion</key>
|
<key>CarthageVersion</key>
|
||||||
<string>0.33.0</string>
|
<string>0.34.0</string>
|
||||||
<key>OSXVersion</key>
|
<key>OSXVersion</key>
|
||||||
<string>10.15.2</string>
|
<string>10.15.2</string>
|
||||||
<key>WebRTCCommit</key>
|
<key>WebRTCCommit</key>
|
||||||
|
|
|
@ -182,7 +182,7 @@ final class ConversationCell : UITableViewCell {
|
||||||
private func getDisplayName() -> String {
|
private func getDisplayName() -> String {
|
||||||
if threadViewModel.isGroupThread {
|
if threadViewModel.isGroupThread {
|
||||||
if threadViewModel.name.isEmpty {
|
if threadViewModel.name.isEmpty {
|
||||||
return DisplayNameUtilities.getDisplayName(for: threadViewModel.threadRecord as! TSGroupThread)
|
return GroupDisplayNameUtilities.getDefaultDisplayName(for: threadViewModel.threadRecord as! TSGroupThread)
|
||||||
} else {
|
} else {
|
||||||
return threadViewModel.name
|
return threadViewModel.name
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ final class ConversationCell : UITableViewCell {
|
||||||
return NSLocalizedString("Note to Self", comment: "")
|
return NSLocalizedString("Note to Self", comment: "")
|
||||||
} else {
|
} else {
|
||||||
let hexEncodedPublicKey = threadViewModel.contactIdentifier!
|
let hexEncodedPublicKey = threadViewModel.contactIdentifier!
|
||||||
return DisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey) ?? hexEncodedPublicKey
|
return UserDisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey) ?? hexEncodedPublicKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ final class ConversationTitleView : UIView {
|
||||||
let title: String
|
let title: String
|
||||||
if thread.isGroupThread() {
|
if thread.isGroupThread() {
|
||||||
if thread.name().isEmpty {
|
if thread.name().isEmpty {
|
||||||
title = DisplayNameUtilities.getDisplayName(for: thread as! TSGroupThread)
|
title = GroupDisplayNameUtilities.getDefaultDisplayName(for: thread as! TSGroupThread)
|
||||||
} else {
|
} else {
|
||||||
title = thread.name()
|
title = thread.name()
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ final class ConversationTitleView : UIView {
|
||||||
title = NSLocalizedString("Note to Self", comment: "")
|
title = NSLocalizedString("Note to Self", comment: "")
|
||||||
} else {
|
} else {
|
||||||
let hexEncodedPublicKey = thread.contactIdentifier()!
|
let hexEncodedPublicKey = thread.contactIdentifier()!
|
||||||
title = DisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey) ?? hexEncodedPublicKey
|
title = UserDisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey) ?? hexEncodedPublicKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
titleLabel.text = title
|
titleLabel.text = title
|
||||||
|
|
|
@ -122,7 +122,7 @@ final class FriendRequestView : UIView {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
let contactID = message.authorId
|
let contactID = message.authorId
|
||||||
let displayName = DisplayNameUtilities.getPrivateChatDisplayName(for: contactID) ?? contactID
|
let displayName = UserDisplayNameUtilities.getPrivateChatDisplayName(for: contactID) ?? contactID
|
||||||
label.text = String(format: format, displayName)
|
label.text = String(format: format, displayName)
|
||||||
case .outgoing:
|
case .outgoing:
|
||||||
guard let message = message as? TSOutgoingMessage else { preconditionFailure() }
|
guard let message = message as? TSOutgoingMessage else { preconditionFailure() }
|
||||||
|
@ -139,7 +139,7 @@ final class FriendRequestView : UIView {
|
||||||
}()
|
}()
|
||||||
if let format = format {
|
if let format = format {
|
||||||
let contactID = message.thread.contactIdentifier()!
|
let contactID = message.thread.contactIdentifier()!
|
||||||
let displayName = DisplayNameUtilities.getPrivateChatDisplayName(for: contactID) ?? contactID
|
let displayName = UserDisplayNameUtilities.getPrivateChatDisplayName(for: contactID) ?? contactID
|
||||||
label.text = String(format: format, displayName)
|
label.text = String(format: format, displayName)
|
||||||
}
|
}
|
||||||
label.isHidden = (format == nil)
|
label.isHidden = (format == nil)
|
||||||
|
|
|
@ -72,7 +72,7 @@ final class SessionRestorationView : UIView {
|
||||||
mainStackView.pin(to: self, withInset: Values.mediumSpacing)
|
mainStackView.pin(to: self, withInset: Values.mediumSpacing)
|
||||||
// Update explanation label if possible
|
// Update explanation label if possible
|
||||||
if let contactID = thread.contactIdentifier() {
|
if let contactID = thread.contactIdentifier() {
|
||||||
let displayName = DisplayNameUtilities.getPrivateChatDisplayName(for: contactID) ?? contactID
|
let displayName = UserDisplayNameUtilities.getPrivateChatDisplayName(for: contactID) ?? contactID
|
||||||
explanationLabel.text = String(format: NSLocalizedString("Would you like to restore your session with %@?", comment: ""), displayName)
|
explanationLabel.text = String(format: NSLocalizedString("Would you like to restore your session with %@?", comment: ""), displayName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,9 @@ public final class MentionUtilities : NSObject {
|
||||||
displayName = OWSProfileManager.shared().localProfileName()
|
displayName = OWSProfileManager.shared().localProfileName()
|
||||||
} else {
|
} else {
|
||||||
if let publicChat = publicChat {
|
if let publicChat = publicChat {
|
||||||
displayName = DisplayNameUtilities.getPublicChatDisplayName(for: hexEncodedPublicKey, in: publicChat.channel, on: publicChat.server)
|
displayName = UserDisplayNameUtilities.getPublicChatDisplayName(for: hexEncodedPublicKey, in: publicChat.channel, on: publicChat.server)
|
||||||
} else {
|
} else {
|
||||||
displayName = DisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey)
|
displayName = UserDisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let displayName = displayName {
|
if let displayName = displayName {
|
||||||
|
|
|
@ -5,7 +5,7 @@ final class GroupMembersVC : UIViewController, UITableViewDataSource {
|
||||||
|
|
||||||
private lazy var members: [String] = {
|
private lazy var members: [String] = {
|
||||||
func getDisplayName(for hexEncodedPublicKey: String) -> String {
|
func getDisplayName(for hexEncodedPublicKey: String) -> String {
|
||||||
return DisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey) ?? "Unknown Contact"
|
return UserDisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey) ?? "Unknown Contact"
|
||||||
}
|
}
|
||||||
return GroupUtilities.getClosedGroupMembers(thread).sorted { getDisplayName(for: $0) < getDisplayName(for: $1) }
|
return GroupUtilities.getClosedGroupMembers(thread).sorted { getDisplayName(for: $0) < getDisplayName(for: $1) }
|
||||||
}()
|
}()
|
||||||
|
@ -139,7 +139,7 @@ private extension GroupMembersVC {
|
||||||
private func update() {
|
private func update() {
|
||||||
profilePictureView.hexEncodedPublicKey = hexEncodedPublicKey
|
profilePictureView.hexEncodedPublicKey = hexEncodedPublicKey
|
||||||
profilePictureView.update()
|
profilePictureView.update()
|
||||||
displayNameLabel.text = DisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey) ?? "Unknown Contact"
|
displayNameLabel.text = UserDisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey) ?? "Unknown Contact"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ final class NewClosedGroupVC : UIViewController, UITableViewDataSource, UITableV
|
||||||
result.append(hexEncodedPublicKey)
|
result.append(hexEncodedPublicKey)
|
||||||
}
|
}
|
||||||
func getDisplayName(for hexEncodedPublicKey: String) -> String {
|
func getDisplayName(for hexEncodedPublicKey: String) -> String {
|
||||||
return DisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey) ?? "Unknown Contact"
|
return UserDisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey) ?? "Unknown Contact"
|
||||||
}
|
}
|
||||||
let userHexEncodedPublicKey = getUserHexEncodedPublicKey()
|
let userHexEncodedPublicKey = getUserHexEncodedPublicKey()
|
||||||
var linkedDeviceHexEncodedPublicKeys: Set<String> = [ userHexEncodedPublicKey ]
|
var linkedDeviceHexEncodedPublicKeys: Set<String> = [ userHexEncodedPublicKey ]
|
||||||
|
@ -261,7 +261,7 @@ private extension NewClosedGroupVC {
|
||||||
private func update() {
|
private func update() {
|
||||||
profilePictureView.hexEncodedPublicKey = hexEncodedPublicKey
|
profilePictureView.hexEncodedPublicKey = hexEncodedPublicKey
|
||||||
profilePictureView.update()
|
profilePictureView.update()
|
||||||
displayNameLabel.text = DisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey) ?? "Unknown Contact"
|
displayNameLabel.text = UserDisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey) ?? "Unknown Contact"
|
||||||
tickImageView.image = hasTick ? #imageLiteral(resourceName: "CircleCheck") : #imageLiteral(resourceName: "Circle")
|
tickImageView.image = hasTick ? #imageLiteral(resourceName: "CircleCheck") : #imageLiteral(resourceName: "Circle")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -554,9 +554,9 @@ const CGFloat kRemotelySourcedContentRowSpacing = 4;
|
||||||
[OWSPrimaryStorage.sharedManager.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
[OWSPrimaryStorage.sharedManager.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||||
LKPublicChat *publicChat = [LKDatabaseUtilities getPublicChatForThreadID:self.quotedMessage.threadId transaction:transaction];
|
LKPublicChat *publicChat = [LKDatabaseUtilities getPublicChatForThreadID:self.quotedMessage.threadId transaction:transaction];
|
||||||
if (publicChat != nil) {
|
if (publicChat != nil) {
|
||||||
quotedAuthor = [LKDisplayNameUtilities getPublicChatDisplayNameFor:self.quotedMessage.authorId in:publicChat.channel on:publicChat.server using:transaction];
|
quotedAuthor = [LKUserDisplayNameUtilities getPublicChatDisplayNameFor:self.quotedMessage.authorId in:publicChat.channel on:publicChat.server using:transaction];
|
||||||
} else {
|
} else {
|
||||||
quotedAuthor = [LKDisplayNameUtilities getPrivateChatDisplayNameFor:self.quotedMessage.authorId];
|
quotedAuthor = [LKUserDisplayNameUtilities getPrivateChatDisplayNameFor:self.quotedMessage.authorId];
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
|
@ -684,12 +684,12 @@ class MediaPageViewController: UIPageViewController, UIPageViewControllerDataSou
|
||||||
publicChat = LokiDatabaseUtilities.getPublicChat(for: incomingMessage.thread.uniqueId!, in: transaction)
|
publicChat = LokiDatabaseUtilities.getPublicChat(for: incomingMessage.thread.uniqueId!, in: transaction)
|
||||||
}
|
}
|
||||||
if let publicChat = publicChat {
|
if let publicChat = publicChat {
|
||||||
return DisplayNameUtilities.getPublicChatDisplayName(for: hexEncodedPublicKey, in: publicChat.channel, on: publicChat.server) ?? hexEncodedPublicKey
|
return UserDisplayNameUtilities.getPublicChatDisplayName(for: hexEncodedPublicKey, in: publicChat.channel, on: publicChat.server) ?? hexEncodedPublicKey
|
||||||
} else {
|
} else {
|
||||||
return hexEncodedPublicKey
|
return hexEncodedPublicKey
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return DisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey) ?? hexEncodedPublicKey
|
return UserDisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey) ?? hexEncodedPublicKey
|
||||||
}
|
}
|
||||||
case is TSOutgoingMessage:
|
case is TSOutgoingMessage:
|
||||||
return NSLocalizedString("MEDIA_GALLERY_SENDER_NAME_YOU", comment: "Short sender label for media sent by you")
|
return NSLocalizedString("MEDIA_GALLERY_SENDER_NAME_YOU", comment: "Short sender label for media sent by you")
|
||||||
|
|
|
@ -530,7 +530,7 @@ const CGFloat kIconViewLength = 24;
|
||||||
[topRow autoPinEdgesToSuperviewMarginsExcludingEdge:ALEdgeBottom];
|
[topRow autoPinEdgesToSuperviewMarginsExcludingEdge:ALEdgeBottom];
|
||||||
|
|
||||||
UILabel *subtitleLabel = [UILabel new];
|
UILabel *subtitleLabel = [UILabel new];
|
||||||
subtitleLabel.text = [NSString stringWithFormat:NSLocalizedString(@"When enabled, messages between you and %@ will disappear after they have been seen.", ""), [LKDisplayNameUtilities getPrivateChatDisplayNameFor:self.thread.contactIdentifier]];
|
subtitleLabel.text = [NSString stringWithFormat:NSLocalizedString(@"When enabled, messages between you and %@ will disappear after they have been seen.", ""), [LKUserDisplayNameUtilities getPrivateChatDisplayNameFor:self.thread.contactIdentifier]];
|
||||||
subtitleLabel.textColor = LKColors.text;
|
subtitleLabel.textColor = LKColors.text;
|
||||||
subtitleLabel.font = [UIFont systemFontOfSize:LKValues.smallFontSize];
|
subtitleLabel.font = [UIFont systemFontOfSize:LKValues.smallFontSize];
|
||||||
subtitleLabel.numberOfLines = 0;
|
subtitleLabel.numberOfLines = 0;
|
||||||
|
|
|
@ -32,7 +32,7 @@ disappearingMessagesConfiguration:(nullable OWSDisappearingMessagesConfiguration
|
||||||
|
|
||||||
SSKProtoContactDetailsBuilder *contactBuilder =
|
SSKProtoContactDetailsBuilder *contactBuilder =
|
||||||
[SSKProtoContactDetails builderWithNumber:signalAccount.recipientId];
|
[SSKProtoContactDetails builderWithNumber:signalAccount.recipientId];
|
||||||
[contactBuilder setName:[LKDisplayNameUtilities getPrivateChatDisplayNameFor:signalAccount.recipientId] ?: signalAccount.recipientId];
|
[contactBuilder setName:[LKUserDisplayNameUtilities getPrivateChatDisplayNameFor:signalAccount.recipientId] ?: signalAccount.recipientId];
|
||||||
[contactBuilder setColor:conversationColorName];
|
[contactBuilder setColor:conversationColorName];
|
||||||
|
|
||||||
if (recipientIdentity != nil) {
|
if (recipientIdentity != nil) {
|
||||||
|
|
|
@ -333,9 +333,9 @@ public final class LokiAPI : NSObject {
|
||||||
candidates = cache.flatMap { hexEncodedPublicKey in
|
candidates = cache.flatMap { hexEncodedPublicKey in
|
||||||
let uncheckedDisplayName: String?
|
let uncheckedDisplayName: String?
|
||||||
if let publicChat = publicChat {
|
if let publicChat = publicChat {
|
||||||
uncheckedDisplayName = DisplayNameUtilities.getPublicChatDisplayName(for: hexEncodedPublicKey, in: publicChat.channel, on: publicChat.server)
|
uncheckedDisplayName = UserDisplayNameUtilities.getPublicChatDisplayName(for: hexEncodedPublicKey, in: publicChat.channel, on: publicChat.server)
|
||||||
} else {
|
} else {
|
||||||
uncheckedDisplayName = DisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey)
|
uncheckedDisplayName = UserDisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey)
|
||||||
}
|
}
|
||||||
guard let displayName = uncheckedDisplayName else { return nil }
|
guard let displayName = uncheckedDisplayName else { return nil }
|
||||||
guard !displayName.hasPrefix("Anonymous") else { return nil }
|
guard !displayName.hasPrefix("Anonymous") else { return nil }
|
||||||
|
|
|
@ -86,7 +86,7 @@ public final class LokiPublicChatPoller : NSObject {
|
||||||
}
|
}
|
||||||
var senderDisplayName = ""
|
var senderDisplayName = ""
|
||||||
if let masterHexEncodedPublicKey = masterHexEncodedPublicKey {
|
if let masterHexEncodedPublicKey = masterHexEncodedPublicKey {
|
||||||
senderDisplayName = DisplayNameUtilities.getPublicChatDisplayName(for: senderHexEncodedPublicKey, in: publicChat.channel, on: publicChat.server) ?? generateDisplayName(from: NSLocalizedString("Anonymous", comment: ""))
|
senderDisplayName = UserDisplayNameUtilities.getPublicChatDisplayName(for: senderHexEncodedPublicKey, in: publicChat.channel, on: publicChat.server) ?? generateDisplayName(from: NSLocalizedString("Anonymous", comment: ""))
|
||||||
} else {
|
} else {
|
||||||
senderDisplayName = generateDisplayName(from: message.displayName)
|
senderDisplayName = generateDisplayName(from: message.displayName)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
|
||||||
// TODO: Rename some of these functions to make the distinctions between them clearer.
|
// MARK: - User Display Name Utilities
|
||||||
|
|
||||||
@objc(LKDisplayNameUtilities)
|
@objc(LKUserDisplayNameUtilities)
|
||||||
public final class DisplayNameUtilities : NSObject {
|
public final class UserDisplayNameUtilities : NSObject {
|
||||||
|
|
||||||
override private init() { }
|
override private init() { }
|
||||||
|
|
||||||
|
@ -23,18 +23,6 @@ public final class DisplayNameUtilities : NSObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Closed Groups
|
|
||||||
@objc public static func getDisplayName(for group: TSGroupThread) -> String {
|
|
||||||
let members = group.groupModel.groupMemberIds
|
|
||||||
let displayNames = members.map { hexEncodedPublicKey -> String in
|
|
||||||
guard let displayName = DisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey) else { return hexEncodedPublicKey }
|
|
||||||
let regex = try! NSRegularExpression(pattern: ".* \\(\\.\\.\\.[0-9a-fA-F]*\\)")
|
|
||||||
guard regex.hasMatch(input: displayName) else { return displayName }
|
|
||||||
return String(displayName[displayName.startIndex..<(displayName.index(displayName.endIndex, offsetBy: -14))])
|
|
||||||
}.sorted()
|
|
||||||
return displayNames.joined(separator: ", ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: Open Groups
|
// MARK: Open Groups
|
||||||
@objc public static func getPublicChatDisplayName(for hexEncodedPublicKey: String, in channel: UInt64, on server: String) -> String? {
|
@objc public static func getPublicChatDisplayName(for hexEncodedPublicKey: String, in channel: UInt64, on server: String) -> String? {
|
||||||
var result: String?
|
var result: String?
|
||||||
|
@ -53,3 +41,23 @@ public final class DisplayNameUtilities : NSObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Group Display Name Utilities
|
||||||
|
|
||||||
|
@objc(LKGroupDisplayNameUtilities)
|
||||||
|
public final class GroupDisplayNameUtilities : NSObject {
|
||||||
|
|
||||||
|
override private init() { }
|
||||||
|
|
||||||
|
// MARK: Closed Groups
|
||||||
|
@objc public static func getDefaultDisplayName(for group: TSGroupThread) -> String {
|
||||||
|
let members = group.groupModel.groupMemberIds
|
||||||
|
let displayNames = members.map { hexEncodedPublicKey -> String in
|
||||||
|
guard let displayName = UserDisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey) else { return hexEncodedPublicKey }
|
||||||
|
let regex = try! NSRegularExpression(pattern: ".* \\(\\.\\.\\.[0-9a-fA-F]*\\)")
|
||||||
|
guard regex.hasMatch(input: displayName) else { return displayName }
|
||||||
|
return String(displayName[displayName.startIndex..<(displayName.index(displayName.endIndex, offsetBy: -14))])
|
||||||
|
}.sorted()
|
||||||
|
return displayNames.joined(separator: ", ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue