eleven / messenger Public

Clone
git clone https://amadan.net/eleven/messenger

Plain git — no account needed to clone.

Download

Download this file

1import SwiftUI
2
3// A DM partner renamed themself while I hold my own name for them (#577): a
4// slim inline row between the header and the feed — occupying layout space,
5// never floating — offering the choice once. Renders nothing when there's
6// nothing to ask. The native twin of the web's #rename-banner (shell.js);
7// the same choice also lives on the member's profile card.
8public struct RenameBanner: View {
9 @ObservedObject var store: ThreadStore
10 let thread: ChatThread
11
12 public init(store: ThreadStore, thread: ChatThread) {
13 self.store = store
14 self.thread = thread
15 }
16
17 private var other: String? {
18 guard thread.kind == "dm" else { return nil }
19 return thread.members.first { $0 != store.myUserId }
20 }
21
22 public var body: some View {
23 if let other, let notice = store.renameNotice(for: other) {
24 HStack(spacing: 10) {
25 (Text(notice.from).bold() + Text(" now goes by ") + Text(notice.to).bold())
26 .font(.subheadline)
27 .lineLimit(1)
28 Button("Use \(notice.to)") {
29 Task { await store.resolveRename(uid: other, keep: false) }
30 }
31 Button("Keep \(notice.from)") {
32 Task { await store.resolveRename(uid: other, keep: true) }
33 }
34 }
35 .buttonStyle(.bordered)
36 .controlSize(.small)
37 .padding(.horizontal, 12)
38 .padding(.vertical, 6)
39 .frame(maxWidth: .infinity)
40 .background(.bar)
41 .overlay(alignment: .bottom) { Divider() }
42 .accessibilityElement(children: .contain)
43 }
44 }
45}
46