Add offline messages (Offline Nachrichten) dialog

Wires up raw TS3 protocol commands for offline messages, since
tsclientlib's generated code has no typed builder for them (same
situation as banlist/complainlist in the previous feature):

- Connector: messagelist, messageget, messageadd, messagedel,
  messageupdateflag as raw OutCommand invocations. Replies parsed via
  the existing StreamItem::MessageEvent pending-flag pattern, reusing
  InMessage::OfflineMessageList (list, no body) and InMessage::OfflineMessage
  (single message with full body, response to messageget).
- Gateway: typed events/methods threading the new commands from
  WebSocket clients through to the connector's stdin protocol.
- Frontend: new "Offline Nachrichten" dialog in the Extras menu with a
  message list (subject/from/timestamp, unread dot), a detail view
  (full body + mark-as-read), delete, and a compose form to send a new
  message to a target client UID. Demo mode gets one scripted message.

Verified against the real test server (192.168.178.108): messagelist
returns a clean DatabaseEmptyResult error for an account with no
messages (falls back to the dialog's existing 6s "unavailable" timeout,
same as banlist/complainlist), and messageadd correctly surfaces a
permissionError for a guest account lacking send rights - both proving
the raw command round-trip works end to end.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
MoepchiandClaude Sonnet 5 committed 2026-08-05 19:57:05 +02:00
1 parent bd0122812d
commit dbe9a3c2df
7 files changed
+552 -1

No files matched your search

+34
View File
@@ -1087,6 +1087,40 @@
gap: 0.5rem;
}
.ts-offline-messages-dialog {
width: 720px;
}
.ts-offline-message-compose,
.ts-offline-message-detail {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.ts-offline-message-detail-header {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 0.5rem;
}
.ts-offline-message-detail-uid {
color: var(--text-muted);
font-size: 12px;
}
.ts-offline-message-detail-body {
white-space: pre-wrap;
border-top: 1px solid var(--border-soft);
padding-top: 0.5rem;
}
.ts-offline-message-compose textarea {
resize: vertical;
font-family: inherit;
}
.ts-server-protocol-log-line {
padding: 0.15rem 0.4rem;
border-bottom: 1px solid var(--border-soft);
+216
View File
@@ -203,6 +203,14 @@ interface ComplainListEntry {
timestamp: string;
}
interface OfflineMessageListEntry {
messageId: number;
clientUid: string;
subject: string;
timestamp: string;
isRead: boolean;
}
type ContactCategory = "acquaintance" | "blocked" | "friend";
interface Contact {
@@ -1379,6 +1387,143 @@ function ComplainListDialog({
);
}
function OfflineMessagesDialog({
entries,
detail,
onSelect,
onDelete,
onMarkRead,
onSend,
onClose,
}: {
entries: OfflineMessageListEntry[] | null;
detail: { messageId: number; clientUid: string; subject: string; message: string; timestamp: string } | null;
onSelect: (messageId: number) => void;
onDelete: (messageId: number) => void;
onMarkRead: (messageId: number) => void;
onSend: (clientUid: string, subject: string, message: string) => void;
onClose: () => void;
}) {
const t = useT();
const backdrop = useBackdropDismiss(onClose);
const [timedOut, setTimedOut] = useState(false);
const [composing, setComposing] = useState(false);
const [composeUid, setComposeUid] = useState("");
const [composeSubject, setComposeSubject] = useState("");
const [composeMessage, setComposeMessage] = useState("");
useEffect(() => {
setTimedOut(false);
if (entries) return;
const id = window.setTimeout(() => setTimedOut(true), 6000);
return () => window.clearTimeout(id);
}, [entries]);
const handleSend = () => {
if (!composeUid.trim() || !composeSubject.trim()) return;
onSend(composeUid.trim(), composeSubject.trim(), composeMessage.trim());
setComposing(false);
setComposeUid("");
setComposeSubject("");
setComposeMessage("");
};
return (
<div className="ts-dialog-backdrop" {...backdrop}>
<div className="ts-dialog ts-offline-messages-dialog" onClick={(e) => e.stopPropagation()}>
<div className="ts-dialog-titlebar">
<span>{t("offlineMessages.title")}</span>
<button onClick={onClose} title={t("dialog.close")}>
✕
</button>
</div>
<div className="ts-dialog-body">
{composing ? (
<div className="ts-offline-message-compose">
<label className="ts-dialog-field ts-dialog-field-grow">
{t("offlineMessages.targetUid")}
<input value={composeUid} onChange={(e) => setComposeUid(e.target.value)} />
</label>
<label className="ts-dialog-field ts-dialog-field-grow">
{t("offlineMessages.subject")}
<input value={composeSubject} onChange={(e) => setComposeSubject(e.target.value)} />
</label>
<label className="ts-dialog-field ts-dialog-field-grow">
{t("offlineMessages.message")}
<textarea value={composeMessage} onChange={(e) => setComposeMessage(e.target.value)} rows={5} />
</label>
</div>
) : detail ? (
<div className="ts-offline-message-detail">
<div className="ts-offline-message-detail-header">
<strong>{detail.subject}</strong>
<span>{detail.timestamp}</span>
</div>
<div className="ts-offline-message-detail-uid">{detail.clientUid}</div>
<div className="ts-offline-message-detail-body">{detail.message}</div>
</div>
) : !entries ? (
<div className="ts-connection-info-loading">
{timedOut ? t("connectionInfo.unavailable") : t("connectionInfo.loading")}
</div>
) : entries.length === 0 ? (
<div className="ts-connection-info-loading">{t("offlineMessages.empty")}</div>
) : (
<table className="ts-ban-list-table">
<thead>
<tr>
<th></th>
<th>{t("offlineMessages.subject")}</th>
<th>{t("offlineMessages.from")}</th>
<th>{t("offlineMessages.timestamp")}</th>
<th></th>
</tr>
</thead>
<tbody>
{entries.map((e) => (
<tr key={e.messageId}>
<td>{e.isRead ? "" : "●"}</td>
<td>
<a href="#" onClick={(ev) => { ev.preventDefault(); onSelect(e.messageId); }}>
{e.subject}
</a>
</td>
<td>{e.clientUid}</td>
<td>{e.timestamp}</td>
<td>
<button onClick={() => onDelete(e.messageId)}>{t("banList.delete")}</button>
</td>
</tr>
))}
</tbody>
</table>
)}
</div>
<div className="ts-dialog-buttons">
<div className="ts-dialog-buttons-left">
{composing ? (
<>
<button onClick={handleSend}>{t("offlineMessages.send")}</button>
<button onClick={() => setComposing(false)}>{t("dialog.cancel")}</button>
</>
) : detail ? (
<>
<button onClick={() => onMarkRead(detail.messageId)}>{t("offlineMessages.markRead")}</button>
<button onClick={() => onSelect(-1)}>{t("offlineMessages.backToList")}</button>
</>
) : (
<button onClick={() => setComposing(true)}>{t("offlineMessages.new")}</button>
)}
</div>
<div className="ts-dialog-buttons-right">
<button onClick={onClose}>{t("dialog.close")}</button>
</div>
</div>
</div>
</div>
);
}
function ServerProtocolLogDialog({
lines,
onClose,
@@ -2861,6 +3006,11 @@ function AppInner() {
const [banList, setBanList] = useState<BanListEntry[] | null>(null);
const [complainListOpen, setComplainListOpen] = useState(false);
const [complainList, setComplainList] = useState<ComplainListEntry[] | null>(null);
const [offlineMessagesOpen, setOfflineMessagesOpen] = useState(false);
const [offlineMessageList, setOfflineMessageList] = useState<OfflineMessageListEntry[] | null>(null);
const [offlineMessageDetail, setOfflineMessageDetail] = useState<
{ messageId: number; clientUid: string; subject: string; message: string; timestamp: string } | null
>(null);
const [treeWidth, setTreeWidth] = useState(260);
const [upperHeight, setUpperHeight] = useState(340);
const [selected, setSelected] = useState<SelectedItem | null>(null);
@@ -3431,6 +3581,18 @@ function AppInner() {
case "complainList":
setComplainList(data.entries);
break;
case "offlineMessageList":
setOfflineMessageList(data.entries);
break;
case "offlineMessage":
setOfflineMessageDetail({
messageId: data.messageId,
clientUid: data.clientUid,
subject: data.subject,
message: data.message,
timestamp: data.timestamp,
});
break;
}
};
@@ -4042,6 +4204,38 @@ function AppInner() {
);
};
const handleShowOfflineMessages = () => {
setOfflineMessagesOpen(true);
setOfflineMessageList(null);
setOfflineMessageDetail(null);
socketRef.current?.send(JSON.stringify({ type: "getOfflineMessageList" }));
};
const handleSelectOfflineMessage = (messageId: number) => {
if (messageId === -1) {
setOfflineMessageDetail(null);
return;
}
socketRef.current?.send(JSON.stringify({ type: "getOfflineMessage", messageId }));
};
const handleDeleteOfflineMessage = (messageId: number) => {
socketRef.current?.send(JSON.stringify({ type: "deleteOfflineMessage", messageId }));
setOfflineMessageList((prev) => (prev ? prev.filter((e) => e.messageId !== messageId) : prev));
setOfflineMessageDetail((prev) => (prev?.messageId === messageId ? null : prev));
};
const handleMarkOfflineMessageRead = (messageId: number) => {
socketRef.current?.send(JSON.stringify({ type: "markOfflineMessageRead", messageId }));
setOfflineMessageList((prev) =>
prev ? prev.map((e) => (e.messageId === messageId ? { ...e, isRead: true } : e)) : prev
);
};
const handleSendOfflineMessage = (clientUid: string, subject: string, message: string) => {
socketRef.current?.send(JSON.stringify({ type: "sendOfflineMessage", clientUid, subject, message }));
};
const handleClientContextMenu = (
e: React.MouseEvent,
clientId: number,
@@ -4422,6 +4616,16 @@ function AppInner() {
<span className="ts-menu-item-label">{t("menu.extras.complaintList")}</span>
<span className="ts-menu-item-shortcut">Strg+Umschalt+C</span>
</button>
<button
className="ts-menu-item"
onClick={() => {
handleShowOfflineMessages();
setExtrasMenuOpen(false);
}}
>
<span className="ts-menu-item-icon">📧</span>
<span className="ts-menu-item-label">{t("menu.extras.offlineMessages")}</span>
</button>
<button className="ts-menu-item" disabled>
<span className="ts-menu-item-icon">🔑</span>
<span className="ts-menu-item-label">{t("menu.extras.serverQueryLogin")}</span>
@@ -4803,6 +5007,18 @@ function AppInner() {
/>
)}
{offlineMessagesOpen && (
<OfflineMessagesDialog
entries={offlineMessageList}
detail={offlineMessageDetail}
onSelect={handleSelectOfflineMessage}
onDelete={handleDeleteOfflineMessage}
onMarkRead={handleMarkOfflineMessageRead}
onSend={handleSendOfflineMessage}
onClose={() => setOfflineMessagesOpen(false)}
/>
)}
{contactsOpen && (
<ContactsDialog
contacts={contacts}
+36
View File
@@ -275,6 +275,42 @@ export class DemoSocket {
case "deleteComplaint":
case "deleteAllComplaintsFor":
break;
case "getOfflineMessageList": {
this.after(400, () =>
this.emit({
type: "offlineMessageList",
entries: [
{
messageId: 1,
clientUid: "demo-uid-sam",
subject: "Missed you online",
timestamp: "2026-08-03 20:11:44",
isRead: false,
},
],
})
);
break;
}
case "getOfflineMessage": {
this.after(300, () =>
this.emit({
type: "offlineMessage",
messageId: msg.messageId,
clientUid: "demo-uid-sam",
subject: "Missed you online",
message: "Hey, we were on last night in the Gaming channel - join us next time!",
timestamp: "2026-08-03 20:11:44",
})
);
break;
}
case "sendOfflineMessage":
case "deleteOfflineMessage":
case "markOfflineMessageRead":
// No observable effect - the frontend already optimistically updates
// its own state for delete/read, and there's no NPC to reply to a send.
break;
// "disconnect" is intentionally unhandled here: handleDisconnect() in
// App.tsx always calls socket.close() right after sending it, and
// close() already emits the "disconnected" event below.
+26
View File
@@ -31,6 +31,7 @@ const translations: Record<Lang, Record<string, string>> = {
"menu.extras.clientLog": "Client Protokoll",
"menu.extras.banList": "Bannliste",
"menu.extras.complaintList": "Beschwerdeliste",
"menu.extras.offlineMessages": "Offline Nachrichten",
"menu.extras.serverQueryLogin": "ServerQuery Login",
"menu.extras.serverLog": "Server Protokoll",
"menu.extras.startRecording": "Aufnahme starten",
@@ -375,6 +376,18 @@ const translations: Record<Lang, Record<string, string>> = {
"complainList.from": "Von",
"complainList.message": "Nachricht",
"complainList.timestamp": "Zeitpunkt",
"offlineMessages.title": "Offline Nachrichten",
"offlineMessages.empty": "Keine Nachrichten vorhanden.",
"offlineMessages.subject": "Betreff",
"offlineMessages.from": "Von",
"offlineMessages.timestamp": "Zeitpunkt",
"offlineMessages.targetUid": "Ziel-UID",
"offlineMessages.message": "Nachricht",
"offlineMessages.send": "Senden",
"offlineMessages.new": "Neue Nachricht",
"offlineMessages.markRead": "Als gelesen markieren",
"offlineMessages.backToList": "Zurück zur Liste",
"dialog.cancel": "Abbrechen",
"clientContext.privateChat": "Privater Chat",
"clientContext.poke": "Anstupsen",
@@ -444,6 +457,7 @@ const translations: Record<Lang, Record<string, string>> = {
"menu.extras.clientLog": "Client Log",
"menu.extras.banList": "Ban List",
"menu.extras.complaintList": "Complaint List",
"menu.extras.offlineMessages": "Offline Messages",
"menu.extras.serverQueryLogin": "ServerQuery Login",
"menu.extras.serverLog": "Server Log",
"menu.extras.startRecording": "Start Recording",
@@ -788,6 +802,18 @@ const translations: Record<Lang, Record<string, string>> = {
"complainList.from": "From",
"complainList.message": "Message",
"complainList.timestamp": "Timestamp",
"offlineMessages.title": "Offline Messages",
"offlineMessages.empty": "No messages found.",
"offlineMessages.subject": "Subject",
"offlineMessages.from": "From",
"offlineMessages.timestamp": "Timestamp",
"offlineMessages.targetUid": "Target UID",
"offlineMessages.message": "Message",
"offlineMessages.send": "Send",
"offlineMessages.new": "New message",
"offlineMessages.markRead": "Mark as read",
"offlineMessages.backToList": "Back to list",
"dialog.cancel": "Cancel",
"clientContext.privateChat": "Private chat",
"clientContext.poke": "Poke",