From efe2a8c6fa23924026fa049522cadd66914d1108 Mon Sep 17 00:00:00 2001 From: rapterjet2004 Date: Mon, 21 Oct 2024 09:29:01 -0500 Subject: [PATCH 1/2] Message actions in Context menu now allow message link copying - Added Copy Message Link to context menu actions - uses LinkUrl and updated localizable file - refactor to avoid force unwrapping Signed-off-by: rapterjet2004 --- NextcloudTalk/BaseChatViewController.swift | 25 ++++++++++++++++++++-- NextcloudTalk/en.lproj/Localizable.strings | 6 ++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/NextcloudTalk/BaseChatViewController.swift b/NextcloudTalk/BaseChatViewController.swift index 0e4f2e68d..736013ece 100644 --- a/NextcloudTalk/BaseChatViewController.swift +++ b/NextcloudTalk/BaseChatViewController.swift @@ -964,6 +964,18 @@ import QuickLook NotificationPresenter.shared().present(text: NSLocalizedString("Message copied", comment: ""), dismissAfterDelay: 5.0, includedStyle: .dark) } + func didPressCopyLink(for message: NCChatMessage) { + guard let link = room.linkURL else { + return + } + + let url = "\(link)#message_\(message.messageId)" + let pasteboard = UIPasteboard.general + pasteboard.string = url + + NotificationPresenter.shared().present(text: NSLocalizedString("Message Link copied", comment: ""), dismissAfterDelay: 5.0, includedStyle: .dark) + } + func didPressTranslate(for message: NCChatMessage) { let activeAccount = NCDatabaseManager.sharedInstance().activeAccount() let translateMessageVC = MessageTranslationViewController(message: message.parsedMessage().string, availableTranslations: NCDatabaseManager.sharedInstance().availableTranslations(forAccountId: activeAccount.accountId)) @@ -2821,10 +2833,19 @@ import QuickLook return nil } + var actions: [UIMenuElement] = [] + // Copy option - let menu = UIMenu(children: [UIAction(title: NSLocalizedString("Copy", comment: ""), image: .init(systemName: "square.on.square")) { _ in + actions.append(UIAction(title: NSLocalizedString("Copy", comment: ""), image: .init(systemName: "square.on.square")) { _ in self.didPressCopy(for: message) - }]) + }) + + // Copy Link + actions.append(UIAction(title: NSLocalizedString("Copy Message Link", comment: ""), image: .init(systemName: "link")) { _ in + self.didPressCopyLink(for: message) + }) + + let menu = UIMenu(children: actions) let configuration = UIContextMenuConfiguration(identifier: indexPath as NSIndexPath) { return nil diff --git a/NextcloudTalk/en.lproj/Localizable.strings b/NextcloudTalk/en.lproj/Localizable.strings index 779ab84aa..e9c7631b3 100644 --- a/NextcloudTalk/en.lproj/Localizable.strings +++ b/NextcloudTalk/en.lproj/Localizable.strings @@ -487,6 +487,9 @@ /* No comment provided by engineer. */ "Copy" = "Copy"; +/* No comment provided by engineer. */ +"Copy Message Link" = "Copy Message Link"; + /* No comment provided by engineer. */ "Could not access camera" = "Could not access camera"; @@ -1096,6 +1099,9 @@ /* No comment provided by engineer. */ "Message expiration time" = "Message expiration time"; +/* No comment provided by engineer. */ +"Message Link copied" = "Message Link copied"; + /* No comment provided by engineer. */ "Messages" = "Messages"; From 1d57c7cdcc503589d3002779d81353d69ce6a975 Mon Sep 17 00:00:00 2001 From: Ivan Sein Date: Fri, 25 Oct 2024 18:16:26 +0200 Subject: [PATCH 2/2] Fix capitalization of words. Signed-off-by: Ivan Sein --- NextcloudTalk/BaseChatViewController.swift | 4 ++-- NextcloudTalk/en.lproj/Localizable.strings | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NextcloudTalk/BaseChatViewController.swift b/NextcloudTalk/BaseChatViewController.swift index 736013ece..d7abc71cc 100644 --- a/NextcloudTalk/BaseChatViewController.swift +++ b/NextcloudTalk/BaseChatViewController.swift @@ -973,7 +973,7 @@ import QuickLook let pasteboard = UIPasteboard.general pasteboard.string = url - NotificationPresenter.shared().present(text: NSLocalizedString("Message Link copied", comment: ""), dismissAfterDelay: 5.0, includedStyle: .dark) + NotificationPresenter.shared().present(text: NSLocalizedString("Message link copied", comment: ""), dismissAfterDelay: 5.0, includedStyle: .dark) } func didPressTranslate(for message: NCChatMessage) { @@ -2841,7 +2841,7 @@ import QuickLook }) // Copy Link - actions.append(UIAction(title: NSLocalizedString("Copy Message Link", comment: ""), image: .init(systemName: "link")) { _ in + actions.append(UIAction(title: NSLocalizedString("Copy message link", comment: ""), image: .init(systemName: "link")) { _ in self.didPressCopyLink(for: message) }) diff --git a/NextcloudTalk/en.lproj/Localizable.strings b/NextcloudTalk/en.lproj/Localizable.strings index e9c7631b3..366d54722 100644 --- a/NextcloudTalk/en.lproj/Localizable.strings +++ b/NextcloudTalk/en.lproj/Localizable.strings @@ -488,7 +488,7 @@ "Copy" = "Copy"; /* No comment provided by engineer. */ -"Copy Message Link" = "Copy Message Link"; +"Copy message link" = "Copy message link"; /* No comment provided by engineer. */ "Could not access camera" = "Could not access camera"; @@ -1100,7 +1100,7 @@ "Message expiration time" = "Message expiration time"; /* No comment provided by engineer. */ -"Message Link copied" = "Message Link copied"; +"Message link copied" = "Message link copied"; /* No comment provided by engineer. */ "Messages" = "Messages";