Retire legacy implementations and flatten managed layout
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using AppKit;
|
||||
using CoreGraphics;
|
||||
using VoiceCat.Core;
|
||||
using Voicecat.V1;
|
||||
|
||||
namespace VoiceCat.Mac;
|
||||
|
||||
internal sealed class PrivateMessageWindowController : NSWindowController
|
||||
{
|
||||
private readonly VoiceCatClient client;
|
||||
private readonly uint otherUserId;
|
||||
private readonly uint selfId;
|
||||
private readonly NSTextView transcript = new(new CGRect(0, 0, 430, 300)) { Editable = false, Selectable = true };
|
||||
private readonly NSTextField compose = new(new CGRect(20, 20, 350, 28)) { PlaceholderString = "Private message" };
|
||||
|
||||
internal PrivateMessageWindowController(VoiceCatClient client, uint otherUserId, uint selfId, string nickname) : base(new NSWindow(
|
||||
new CGRect(0, 0, 480, 400), NSWindowStyle.Titled | NSWindowStyle.Closable | NSWindowStyle.Resizable,
|
||||
NSBackingStore.Buffered, false))
|
||||
{
|
||||
this.client = client; this.otherUserId = otherUserId; this.selfId = selfId;
|
||||
Window!.Title = $"Private message — {nickname}"; Window.Center();
|
||||
NSView view = Window.ContentView!;
|
||||
var scroll = new NSScrollView(new CGRect(20, 65, 440, 315)) { DocumentView = transcript, HasVerticalScroller = true };
|
||||
scroll.AccessibilityLabel = $"Private conversation with {nickname}"; view.AddSubview(scroll);
|
||||
((INSAccessibility)compose).AccessibilityLabel = $"Message to {nickname}"; compose.Activated += Send; view.AddSubview(compose);
|
||||
var button = new NSButton(new CGRect(380, 18, 80, 32)) { Title = "Send" }; button.Activated += Send; view.AddSubview(button);
|
||||
}
|
||||
|
||||
private void Send(object? sender, EventArgs args)
|
||||
{
|
||||
string value = compose.StringValue.Trim(); if (value.Length == 0) return;
|
||||
client.Send(new() { TextMessage = new() { Scope = TextScope.TextPrivate, TargetId = otherUserId, Body = value, ClientMsgId = Guid.NewGuid().ToString("N") } });
|
||||
compose.StringValue = "";
|
||||
}
|
||||
|
||||
internal void Append(TextMessage message, string sender)
|
||||
{
|
||||
string line = $"[{DateTime.Now:t}] {(message.SenderId == selfId ? "You" : sender)}: {message.Body}";
|
||||
transcript.Value = transcript.Value.Length == 0 ? line : transcript.Value + "\n" + line;
|
||||
transcript.ScrollRangeToVisible(new Foundation.NSRange(transcript.Value.Length, 0));
|
||||
Window?.MakeKeyAndOrderFront(this);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user