Skip to content

Commit

Permalink
Partially implement feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsandriesse committed Oct 14, 2019
1 parent 294d44c commit 7b0e2d0
Show file tree
Hide file tree
Showing 19 changed files with 112 additions and 79 deletions.
4 changes: 4 additions & 0 deletions Signal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@
B82584A02315024B001B41CB /* RSSFeedPoller.swift in Sources */ = {isa = PBXBuildFile; fileRef = B825849F2315024B001B41CB /* RSSFeedPoller.swift */; };
B846365B22B7418B00AF1514 /* Identicon+ObjC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B846365A22B7418B00AF1514 /* Identicon+ObjC.swift */; };
B84664F5235022F30083A1CD /* MentionUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84664F4235022F30083A1CD /* MentionUtilities.swift */; };
B84664F923541F070083A1CD /* DisplayNameUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84664F823541F070083A1CD /* DisplayNameUtilities.swift */; };
B86BD08123399883000F5AE3 /* QRCodeModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B86BD08023399883000F5AE3 /* QRCodeModal.swift */; };
B86BD08423399ACF000F5AE3 /* Modal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B86BD08323399ACF000F5AE3 /* Modal.swift */; };
B86BD08623399CEF000F5AE3 /* SeedModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B86BD08523399CEF000F5AE3 /* SeedModal.swift */; };
Expand Down Expand Up @@ -1380,6 +1381,7 @@
B825849F2315024B001B41CB /* RSSFeedPoller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RSSFeedPoller.swift; sourceTree = "<group>"; };
B846365A22B7418B00AF1514 /* Identicon+ObjC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Identicon+ObjC.swift"; sourceTree = "<group>"; };
B84664F4235022F30083A1CD /* MentionUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MentionUtilities.swift; sourceTree = "<group>"; };
B84664F823541F070083A1CD /* DisplayNameUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayNameUtilities.swift; sourceTree = "<group>"; };
B86BD08023399883000F5AE3 /* QRCodeModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRCodeModal.swift; sourceTree = "<group>"; };
B86BD08323399ACF000F5AE3 /* Modal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modal.swift; sourceTree = "<group>"; };
B86BD08523399CEF000F5AE3 /* SeedModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeedModal.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2671,6 +2673,7 @@
B846365A22B7418B00AF1514 /* Identicon+ObjC.swift */,
241C6312231F5F1D00B4198E /* CGFloat+Rounding.swift */,
241C6310231F5C4400B4198E /* UIColor+Helper.swift */,
B84664F823541F070083A1CD /* DisplayNameUtilities.swift */,
);
path = Loki;
sourceTree = "<group>";
Expand Down Expand Up @@ -3575,6 +3578,7 @@
450998681FD8C0FF00D89EB3 /* AttachmentSharing.m in Sources */,
347850711FDAEB17007B8332 /* OWSUserProfile.m in Sources */,
346129F81FD5F31400532771 /* OWS100RemoveTSRecipientsMigration.m in Sources */,
B84664F923541F070083A1CD /* DisplayNameUtilities.swift in Sources */,
34AC09DF211B39B100997B47 /* OWSNavigationController.m in Sources */,
34074F61203D0CBE004596AE /* OWSSounds.m in Sources */,
34BEDB1721C80BCA007B0EAE /* OWSAnyTouchGestureRecognizer.m in Sources */,
Expand Down
5 changes: 3 additions & 2 deletions Signal/src/Loki/NewPublicChatVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ final class NewPublicChatVC : OWSViewController {
return showError(title: NSLocalizedString("Invalid URL", comment: ""), message: NSLocalizedString("Please check the URL you entered and try again.", comment: ""))
}
updateAddButton(isConnecting: true)
let channelID: UInt64 = 1
let urlAsString = url.absoluteString
let displayName = OWSProfileManager.shared().localProfileName()
LokiPublicChatManager.shared.addChat(server: urlAsString, channel: 1)
LokiPublicChatManager.shared.addChat(server: urlAsString, channel: channelID)
.done(on: .main) { [weak self] _ in
let _ = LokiGroupChatAPI.getMessages(for: 1, on: urlAsString)
let _ = LokiGroupChatAPI.getMessages(for: channelID, on: urlAsString)
let _ = LokiGroupChatAPI.setDisplayName(to: displayName, on: urlAsString)
self?.presentingViewController!.dismiss(animated: true, completion: nil)
}
Expand Down
19 changes: 8 additions & 11 deletions Signal/src/Loki/Utilities/MentionUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ public final class MentionUtilities : NSObject {

override private init() { }

@objc public static func highlightMentions(in string: String, thread: TSThread) -> String {
return highlightMentions(in: string, isOutgoingMessage: false, thread: thread, attributes: [:]).string // isOutgoingMessage and attributes are irrelevant
@objc public static func highlightMentions(in string: String, threadID: String) -> String {
return highlightMentions(in: string, isOutgoingMessage: false, threadID: threadID, attributes: [:]).string // isOutgoingMessage and attributes are irrelevant
}

@objc public static func highlightMentions(in string: String, isOutgoingMessage: Bool, thread: TSThread, attributes: [NSAttributedString.Key:Any]) -> NSAttributedString {
@objc public static func highlightMentions(in string: String, isOutgoingMessage: Bool, threadID: String, attributes: [NSAttributedString.Key:Any]) -> NSAttributedString {
var groupChat: LokiGroupChat?
OWSPrimaryStorage.shared().dbReadConnection.read { transaction in
groupChat = LokiDatabaseUtilities.objc_getGroupChat(for: thread.uniqueId!, in: transaction)
groupChat = LokiDatabaseUtilities.getGroupChat(for: threadID, in: transaction)
}
var string = string
let regex = try! NSRegularExpression(pattern: "@[0-9a-fA-F]*", options: [])
let knownUserHexEncodedPublicKeys = LokiAPI.userHexEncodedPublicKeyCache[thread.uniqueId!] ?? [] // Should always be populated at this point
let knownUserHexEncodedPublicKeys = LokiAPI.userHexEncodedPublicKeyCache[threadID] ?? [] // Should always be populated at this point
var mentions: [NSRange] = []
var outerMatch = regex.firstMatch(in: string, options: .withoutAnchoringBounds, range: NSRange(location: 0, length: string.count))
while let match = outerMatch, thread.isGroupThread() {
while let match = outerMatch {
let hexEncodedPublicKey = String((string as NSString).substring(with: match.range).dropFirst()) // Drop the @
let matchEnd: Int
if knownUserHexEncodedPublicKeys.contains(hexEncodedPublicKey) {
Expand All @@ -27,12 +27,9 @@ public final class MentionUtilities : NSObject {
userDisplayName = OWSProfileManager.shared().localProfileName()
} else {
if let groupChat = groupChat {
OWSPrimaryStorage.shared().dbReadConnection.read { transaction in
let collection = "\(groupChat.server).\(groupChat.channel)"
userDisplayName = transaction.object(forKey: hexEncodedPublicKey, inCollection: collection) as! String?
}
userDisplayName = DisplayNameUtilities.getGroupChatDisplayName(for: hexEncodedPublicKey, in: groupChat.channel, on: groupChat.server)
} else {
userDisplayName = nil // TODO: Implement
userDisplayName = DisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey)
}
}
if let userDisplayName = userDisplayName {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,10 @@ - (BOOL)updateAvatarView
[OWSPrimaryStorage.sharedManager.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
groupChat = [LKDatabaseUtilities getGroupChatForThreadID:self.viewItem.interaction.uniqueThreadId transaction: transaction];
}];

if (groupChat != nil) {
BOOL isModerator = [LKGroupChatAPI isUserModerator:incomingMessage.authorId forGroup:groupChat.channel onServer:groupChat.server];
UIImage *moderatorIcon = [UIImage imageNamed:@"Crown"];
self.moderatorIconImageView.image = moderatorIcon;
self.moderatorIconImageView.hidden = !isModerator;
}
BOOL isModerator = [LKGroupChatAPI isUserModerator:incomingMessage.authorId forGroup:groupChat.channel onServer:groupChat.server];
UIImage *moderatorIcon = [UIImage imageNamed:@"Crown"];
self.moderatorIconImageView.image = moderatorIcon;
self.moderatorIconImageView.hidden = !isModerator;
}

[self.contentView addSubview:self.moderatorIconImageView];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,11 +554,11 @@ - (UILabel *)configureQuotedAuthorLabel

if (quotedAuthor == self.quotedMessage.authorId) {
[OWSPrimaryStorage.sharedManager.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
LKGroupChat *chat = [LKDatabaseUtilities getGroupChatForThreadID:self.quotedMessage.threadId transaction:transaction];
if (chat != nil) {
NSString *collection = [NSString stringWithFormat:@"%@.%@", chat.server, @(chat.channel)];
NSString *displayName = [transaction stringForKey:self.quotedMessage.authorId inCollection:collection];
if (displayName != nil) { quotedAuthor = displayName; }
LKGroupChat *groupChat = [LKDatabaseUtilities getGroupChatForThreadID:self.quotedMessage.threadId transaction:transaction];
if (groupChat != nil) {
quotedAuthor = [LKDisplayNameUtilities getGroupChatDisplayNameFor:self.quotedMessage.authorId in:groupChat.channel on:groupChat.server using:transaction];;
} else {
quotedAuthor = [LKDisplayNameUtilities getPrivateChatDisplayNameFor:self.quotedMessage.authorId];
}
}];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ - (BOOL)userCanDeleteGroupMessage
TSMessage *message = (TSMessage *)self.interaction;
if (!message.isGroupChatMessage) return false;

// Make sure we have the details to contact the server
// Ensure we have the details needed to contact the server
__block LKGroupChat *groupChat;
[self.primaryStorage.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
groupChat = [LKDatabaseUtilities getGroupChatForThreadID:groupThread.uniqueId transaction: transaction];
Expand Down
2 changes: 1 addition & 1 deletion Signal/src/ViewControllers/DebugUI/DebugUIMessages.m
Original file line number Diff line number Diff line change
Expand Up @@ -2016,7 +2016,7 @@ + (DebugUIMessagesAction *)fakeRandomTextAction:(TSThread *)thread
transaction:transaction
conversationStyle:conversationStyle];
quotedMessage = [
[OWSQuotedReplyModel quotedReplyForSendingWithConversationViewItem:viewItem threadId:viewItem.interaction.uniqueThreadId transaction:transaction]
[OWSQuotedReplyModel quotedReplyForSendingWithConversationViewItem:viewItem threadId:viewItem.interaction.uniqueThreadId transaction:transaction]
buildQuotedMessageForSending];
} else {
TSOutgoingMessage *_Nullable messageToQuote = [self createFakeOutgoingMessage:thread
Expand Down
18 changes: 6 additions & 12 deletions Signal/src/ViewControllers/HomeView/HomeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -787,21 +787,15 @@ - (void)updateBarButtonItems
self.navigationItem.leftBarButtonItem = settingsButton;
SET_SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, settingsButton);

UIBarButtonItem *newConversation = [[UIBarButtonItem alloc]
UIBarButtonItem *newPrivateChatButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCompose
target:self
action:@selector(showNewConversationView)
action:@selector(showNewConversationVC)
accessibilityIdentifier:ACCESSIBILITY_IDENTIFIER_WITH_NAME(self, @"compose")];

UIBarButtonItem *newServer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(showNewPublicChatView)
accessibilityIdentifier:ACCESSIBILITY_IDENTIFIER_WITH_NAME(self, @"addServer")];
UIBarButtonItem *newGroupChatButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"group-avatar"] style:UIBarButtonItemStylePlain target:self action:@selector(showNewPublicChatVC)];

self.navigationItem.rightBarButtonItems = @[
newConversation,
newServer,
];
self.navigationItem.rightBarButtonItems = @[ newPrivateChatButton, newGroupChatButton ];
}

- (void)settingsButtonPressed:(id)sender
Expand Down Expand Up @@ -843,7 +837,7 @@ - (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext
[self.navigationController pushViewController:vc animated:NO];
}

- (void)showNewConversationView
- (void)showNewConversationVC
{
LKNewConversationVC *newConversationVC = [LKNewConversationVC new];
OWSNavigationController *navigationController = [[OWSNavigationController alloc] initWithRootViewController:newConversationVC];
Expand Down Expand Up @@ -871,7 +865,7 @@ - (void)showNewConversationView
*/
}

- (void)showNewPublicChatView
- (void)showNewPublicChatVC
{
LKNewPublicChatVC *newPublicChatVC = [LKNewPublicChatVC new];
OWSNavigationController *navigationController = [[OWSNavigationController alloc] initWithRootViewController:newPublicChatVC];
Expand Down
3 changes: 0 additions & 3 deletions Signal/translations/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -2552,7 +2552,6 @@
"Password (Optional)" = "Password (Optional)";
"Next" = "Next";
"Add" = "Add";
"Connecting to server" = "Connecting to server...";
"Please save the seed below in a safe location. It can be used to restore your account if you lose access, or to migrate to a new device." = "Please save the seed below in a safe location. It can be used to restore your account if you lose access, or to migrate to a new device.";
"Restore your account by entering your seed below." = "Restore your account by entering your seed below.";
"Copy" = "Copy";
Expand All @@ -2571,7 +2570,6 @@
"Start a Conversation" = "Start a Conversation";
"Invalid public key" = "Invalid public key";
"No search results" = "No search results";
"Failed to connect to server" = "Failed to connect to server";
"Calculating proof of work" = "Calculating proof of work";
"Failed to calculate proof of work." = "Failed to calculate proof of work.";
"Share Public Key" = "Share Public Key";
Expand Down Expand Up @@ -2648,5 +2646,4 @@
"Enter a URL" = "Enter a URL";
"Enter the URL of the public chat you'd like to join. The Loki Public Chat URL is https://chat.lokinet.org." = "Enter the URL of the public chat you'd like to join. The Loki Public Chat URL is https://chat.lokinet.org.";
"Connecting..." = "Connecting...";
"Add" = "Add";
"Couldn't Connect" = "Couldn't Connect";
39 changes: 39 additions & 0 deletions SignalMessaging/Loki/DisplayNameUtilities.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

@objc(LKDisplayNameUtilities)
public final class DisplayNameUtilities : NSObject {

override private init() { }

private static var userHexEncodedPublicKey: String {
return OWSIdentityManager.shared().identityKeyPair()!.hexEncodedPublicKey
}

private static var userDisplayName: String? {
return OWSProfileManager.shared().localProfileName()
}

@objc public static func getPrivateChatDisplayName(for hexEncodedPublicKey: String) -> String? {
if hexEncodedPublicKey == userHexEncodedPublicKey {
return userDisplayName
} else {
return OWSProfileManager.shared().profileName(forRecipientId: hexEncodedPublicKey)
}
}

@objc public static func getGroupChatDisplayName(for hexEncodedPublicKey: String, in channel: UInt64, on server: String) -> String? {
var result: String?
OWSPrimaryStorage.shared().dbReadConnection.read { transaction in
result = getGroupChatDisplayName(for: hexEncodedPublicKey, in: channel, on: server, using: transaction)
}
return result
}

@objc public static func getGroupChatDisplayName(for hexEncodedPublicKey: String, in channel: UInt64, on server: String, using transaction: YapDatabaseReadTransaction) -> String? {
if hexEncodedPublicKey == userHexEncodedPublicKey {
return userDisplayName
} else {
let collection = "\(server).\(channel)"
return transaction.object(forKey: hexEncodedPublicKey, inCollection: collection) as! String?
}
}
}
2 changes: 0 additions & 2 deletions SignalMessaging/ViewModels/OWSQuotedReplyModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ NS_ASSUME_NONNULL_BEGIN
- (TSQuotedMessage *)buildQuotedMessageForSending;

// Loki

@property (nonatomic, readonly) NSString *threadId;


@end

NS_ASSUME_NONNULL_END
2 changes: 1 addition & 1 deletion SignalMessaging/environment/VersionMigrations.m
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ + (void)clearBloomFilterCache
}
}

# pragma mark Loki - Upgrading to public chat manager
# pragma mark Loki - Upgrading to Public Chat Manager

// Versions less than or equal to 1.2.0 didn't store group chat mappings
+ (void)updatePublicChatMapping
Expand Down
12 changes: 7 additions & 5 deletions SignalMessaging/profiles/OWSProfileManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -535,13 +535,15 @@ - (void)updateServiceWithProfileName:(nullable NSString *)localProfileName
OWSAssertDebug(successBlock);
OWSAssertDebug(failureBlock);

__block NSDictionary *chats;
[SSKEnvironment.shared.primaryStorage.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction * _Nonnull transaction) {
chats = [LKDatabaseUtilities getAllGroupChats:transaction];
__block NSDictionary *groupChats;
[SSKEnvironment.shared.primaryStorage.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
groupChats = [LKDatabaseUtilities getAllGroupChats:transaction];
}];

for (LKGroupChat *chat in chats.allValues) {
[[LKGroupChatAPI setDisplayName:localProfileName on:chat.server] retainUntilComplete];
NSSet *servers = [NSSet setWithArray:[groupChats.allValues map:^NSString *(LKGroupChat *groupChat) { return groupChat.server; }]];

for (NSString *server in servers) {
[[LKGroupChatAPI setDisplayName:localProfileName on:server] retainUntilComplete];
}

successBlock();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

@objc(LKGroupChatPoller)
public final class LokiGroupChatPoller : NSObject {
public final class GroupChatPoller : NSObject {
private let group: LokiGroupChat
private var pollForNewMessagesTimer: Timer? = nil
private var pollForDeletedMessagesTimer: Timer? = nil
Expand Down Expand Up @@ -50,7 +50,7 @@ public final class LokiGroupChatPoller : NSObject {
let endIndex = senderHexEncodedPublicKey.endIndex
let cutoffIndex = senderHexEncodedPublicKey.index(endIndex, offsetBy: -8)
let senderDisplayName = "\(message.displayName) (...\(senderHexEncodedPublicKey[cutoffIndex..<endIndex]))"
let id = group.idAsData!
let id = group.idAsData
let groupContext = SSKProtoGroupContext.builder(id: id, type: .deliver)
groupContext.setName(group.displayName)
let dataMessage = SSKProtoDataMessage.builder()
Expand Down Expand Up @@ -89,7 +89,7 @@ public final class LokiGroupChatPoller : NSObject {
isDuplicate = id != nil
}
guard !isDuplicate else { return }
guard let groupID = group.idAsData else { return }
let groupID = group.idAsData
let thread = TSGroupThread.getOrCreateThread(withGroupId: groupID)
let signalQuote: TSQuotedMessage?
if let quote = message.quote {
Expand Down
Loading

0 comments on commit 7b0e2d0

Please sign in to comment.