Files
buzz/mobile/ios/Runner/ConversationMenuRow.swift
klopez4212 e802de8777 Give mobile Solo sessions their own settings and actions (#9888)
## Summary

Long-pressing a Solo or channel in the mobile list opens a system menu
anchored to its row (UIKit context menu on iOS and a rounded Android
PopupWindow with leading icons and an anchored scale and fade). Both
menus use Buzz’s Tabler icons. The actions appear in this order when
available: Mark unread (or Mark read), Rename, Move to section (Change
workspace for personal Solos), Archive (or Unarchive). Tapping the
conversation title opens full settings.

Solo settings include Agent, Rename, workspace, members, and
role-specific management actions. Channel settings put Members below the
quick actions, include Huddle, and offer Leave to eligible members,
including co-owners. A sole owner sees Delete channel. DMs retain the
Huddle header shortcut.

## Snapshots

The iOS simulator shows a sample Solo row. The Android screenshot is
from a physical Pixel.

| UIKit context menu on iOS 26.5 | Android system popup on Pixel 10 |
| --- | --- |
| ![Simulator interaction using sample
rows](https://github.com/user-attachments/assets/dddb43e1-4d2b-4737-a3a4-0dff58ed9e63)
| ![Pixel popup cropped to its four
actions](https://github.com/user-attachments/assets/80008353-f717-41aa-a45e-2cedebafa653)
|

Flutter-rendered details previews with sample data. The previous
ellipsis opened a separate settings sheet. The updated Solo details page
includes those controls.

| Previous ellipsis sheet | Updated settings | Updated members and
management |
| --- | --- | --- |
| ![Previous Agent and Workspace
sheet](https://github.com/user-attachments/assets/75c40f2a-0093-4ebc-811e-fe31ea7acc30)
| ![Solo quick actions, agent and
workspace](https://github.com/user-attachments/assets/00a320ac-b106-4a63-9ef3-babddb98ded1)
| ![Solo roster and owner
actions](https://github.com/user-attachments/assets/3c394e74-6ad3-480d-9666-22ecabc98cb2)
|

Long-pressing a message puts Mark unread first in its quick actions.

![Message quick actions with Mark unread
first](https://github.com/user-attachments/assets/4819ad0c-473b-4f2a-b93a-e2cfb66f2e76)

## Testing

The list journey tests exercise the popover from the channel list and
Solo list, shared Solo filing, read-state changes and dismissal. The
title settings tests cover editing, roster, and lifecycle actions.

## Related issue

No matching issue found.

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
2026-11-23 20:19:55 +00:00

129 lines
4.9 KiB
Swift

import Flutter
import UIKit
/// One interaction on the Flutter host. Flutter identifies the touched row
/// and sends its bounds only when a pointer goes down.
final class ConversationMenu: NSObject, UIContextMenuInteractionDelegate {
private let host: () -> UIViewController?
private let bridge: FlutterMethodChannel
private lazy var interaction = UIContextMenuInteraction(delegate: self)
private var touchId = 0
private var armedRect: CGRect?
private var snapshot: UIView?
private var updatedLabels: [String]?
private var selection: String?
private var active = false
init(messenger: FlutterBinaryMessenger, host: @escaping () -> UIViewController?) {
self.host = host
bridge = FlutterMethodChannel(name: "buzz/conversation_menu", binaryMessenger: messenger)
super.init()
bridge.setMethodCallHandler { [weak self] call, result in
guard let self else { result(nil); return }
switch call.method {
case "attach", "arm":
if let view = self.host()?.view, self.interaction.view !== view {
self.interaction.view?.removeInteraction(self.interaction)
view.addInteraction(self.interaction)
}
if let bounds = call.arguments as? [CGFloat], bounds.count == 5 {
self.touchId = Int(bounds[4])
self.armedRect = CGRect(x: bounds[0], y: bounds[1], width: bounds[2], height: bounds[3])
}
case "disarm": self.armedRect = nil
case "dismiss": self.interaction.dismissMenu()
case "update":
if self.active, let labels = call.arguments as? [String] {
self.updatedLabels = labels
self.interaction.updateVisibleMenu { _ in UIMenu(children: self.actions(labels)) }
}
default: result(FlutterMethodNotImplemented); return
}
result(nil)
}
}
private func actions(_ labels: [String]) -> [UIAction] {
let icons = [
"Rename": "tabler-pencil", "Archive": "archive", "Unarchive": "archive",
"Mark read": "mail", "Mark unread": "mail",
"Change workspace": "folder", "Move to section…": "folder-input",
]
return labels.map { label in
UIAction(title: label, image: icons[label].flatMap { NativeTabler.image($0, size: 24) }) {
[weak self] _ in
self?.selection = label
}
}
}
func contextMenuInteraction(
_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint
) -> UIContextMenuConfiguration? {
guard !active, let view = interaction.view, let window = view.window,
let rect = armedRect, rect.contains(location),
let copy = window.resizableSnapshotView(from: view.convert(rect, to: window),
afterScreenUpdates: false, withCapInsets: .zero) else { return nil }
active = true
selection = nil
updatedLabels = nil
copy.frame = rect
copy.isUserInteractionEnabled = false
view.addSubview(copy)
snapshot = copy
let requestId = touchId
return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { [weak self] _ in
let deferred = UIDeferredMenuElement.uncached { [weak self] completion in
guard let self, self.active else {
completion([])
return
}
self.bridge.invokeMethod("prepare", arguments: requestId) { [weak self] result in
guard let self, self.active, let labels = result as? [String] else {
completion([])
return
}
completion(self.actions(self.updatedLabels ?? labels))
}
}
return UIMenu(children: [deferred])
}
}
func contextMenuInteraction(_ interaction: UIContextMenuInteraction,
previewForHighlightingMenuWithConfiguration configuration: UIContextMenuConfiguration
) -> UITargetedPreview? {
snapshot.map { UITargetedPreview(view: $0) }
}
func contextMenuInteraction(_ interaction: UIContextMenuInteraction,
previewForDismissingMenuWithConfiguration configuration: UIContextMenuConfiguration
) -> UITargetedPreview? {
snapshot.map { UITargetedPreview(view: $0) }
}
func contextMenuInteraction(
_ interaction: UIContextMenuInteraction, willDisplayMenuFor configuration: UIContextMenuConfiguration,
animator: UIContextMenuInteractionAnimating?
) {
animator?.addCompletion { [weak self] in
guard let self, self.active, let labels = self.updatedLabels else { return }
interaction.updateVisibleMenu { _ in UIMenu(children: self.actions(labels)) }
}
}
func contextMenuInteraction(
_ interaction: UIContextMenuInteraction, willEndFor configuration: UIContextMenuConfiguration,
animator: UIContextMenuInteractionAnimating?
) {
let finish = { [weak self] in
guard let self else { return }
self.snapshot?.removeFromSuperview()
self.snapshot = nil
self.active = false
self.bridge.invokeMethod("end", arguments: self.selection)
}
if let animator { animator.addCompletion(finish) } else { finish() }
}
}