Skip to content

Commit

Permalink
Message actions in Context menu now allow message link copying
Browse files Browse the repository at this point in the history
- Added Copy Message Link to context menu actions
- uses LinkUrl and updated localizable file
- refactor to avoid force unwrapping

Signed-off-by: rapterjet2004 <[email protected]>
  • Loading branch information
rapterjet2004 committed Oct 25, 2024
1 parent 25ebf7e commit efe2a8c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
25 changes: 23 additions & 2 deletions NextcloudTalk/BaseChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions NextcloudTalk/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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";

Expand Down

0 comments on commit efe2a8c

Please sign in to comment.