mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-01 00:42:49 +08:00
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:
1 parent
bd0122812d
commit
dbe9a3c2df
7 files changed
+552
-1
No files matched your search
@@ -174,6 +174,26 @@ wss.on("connection", (socket: WebSocket) => {
|
||||
await connection?.deleteAllComplaintsFor(msg.targetClientDbId);
|
||||
break;
|
||||
}
|
||||
case "getOfflineMessageList": {
|
||||
await connection?.getOfflineMessageList();
|
||||
break;
|
||||
}
|
||||
case "getOfflineMessage": {
|
||||
await connection?.getOfflineMessage(msg.messageId);
|
||||
break;
|
||||
}
|
||||
case "sendOfflineMessage": {
|
||||
await connection?.sendOfflineMessage(msg.clientUid, msg.subject, msg.message);
|
||||
break;
|
||||
}
|
||||
case "deleteOfflineMessage": {
|
||||
await connection?.deleteOfflineMessage(msg.messageId);
|
||||
break;
|
||||
}
|
||||
case "markOfflineMessageRead": {
|
||||
await connection?.markOfflineMessageRead(msg.messageId);
|
||||
break;
|
||||
}
|
||||
case "disconnect": {
|
||||
await connection?.disconnect(msg.message ?? "");
|
||||
break;
|
||||
|
||||
@@ -57,6 +57,14 @@ export interface ComplainListEntry {
|
||||
timestamp: string;
|
||||
}
|
||||
|
||||
export interface OfflineMessageListEntry {
|
||||
messageId: number;
|
||||
clientUid: string;
|
||||
subject: string;
|
||||
timestamp: string;
|
||||
isRead: boolean;
|
||||
}
|
||||
|
||||
export type ServerLogEntry =
|
||||
| { kind: "clientJoin"; client: string; channel: string }
|
||||
| { kind: "clientLeave"; client: string }
|
||||
@@ -115,7 +123,16 @@ export type Ts3ConnectionEvent =
|
||||
}
|
||||
| { type: "serverProtocolLog"; lines: string[] }
|
||||
| { type: "banList"; entries: BanListEntry[] }
|
||||
| { type: "complainList"; entries: ComplainListEntry[] };
|
||||
| { type: "complainList"; entries: ComplainListEntry[] }
|
||||
| { type: "offlineMessageList"; entries: OfflineMessageListEntry[] }
|
||||
| {
|
||||
type: "offlineMessage";
|
||||
messageId: number;
|
||||
clientUid: string;
|
||||
subject: string;
|
||||
message: string;
|
||||
timestamp: string;
|
||||
};
|
||||
|
||||
export interface Ts3ConnectOptions {
|
||||
host: string;
|
||||
@@ -257,6 +274,24 @@ export class Ts3Connection {
|
||||
message: string;
|
||||
timestamp: string;
|
||||
}[];
|
||||
}
|
||||
| {
|
||||
type: "offlineMessageList";
|
||||
entries: {
|
||||
message_id: number;
|
||||
client_uid: string;
|
||||
subject: string;
|
||||
timestamp: string;
|
||||
is_read: boolean;
|
||||
}[];
|
||||
}
|
||||
| {
|
||||
type: "offlineMessage";
|
||||
message_id: number;
|
||||
client_uid: string;
|
||||
subject: string;
|
||||
message: string;
|
||||
timestamp: string;
|
||||
};
|
||||
|
||||
if (event.type === "connected") {
|
||||
@@ -359,6 +394,26 @@ export class Ts3Connection {
|
||||
timestamp: e.timestamp,
|
||||
})),
|
||||
});
|
||||
} else if (event.type === "offlineMessageList") {
|
||||
this.emit({
|
||||
type: "offlineMessageList",
|
||||
entries: event.entries.map((e) => ({
|
||||
messageId: e.message_id,
|
||||
clientUid: e.client_uid,
|
||||
subject: e.subject,
|
||||
timestamp: e.timestamp,
|
||||
isRead: e.is_read,
|
||||
})),
|
||||
});
|
||||
} else if (event.type === "offlineMessage") {
|
||||
this.emit({
|
||||
type: "offlineMessage",
|
||||
messageId: event.message_id,
|
||||
clientUid: event.client_uid,
|
||||
subject: event.subject,
|
||||
message: event.message,
|
||||
timestamp: event.timestamp,
|
||||
});
|
||||
} else {
|
||||
this.emit(event);
|
||||
}
|
||||
@@ -459,6 +514,27 @@ export class Ts3Connection {
|
||||
this.child?.stdin.write(`complaindelall ${targetClientDbId}\n`);
|
||||
}
|
||||
|
||||
async getOfflineMessageList(): Promise<void> {
|
||||
this.child?.stdin.write(`messagelist\n`);
|
||||
}
|
||||
|
||||
async getOfflineMessage(messageId: number): Promise<void> {
|
||||
this.child?.stdin.write(`messageget ${messageId}\n`);
|
||||
}
|
||||
|
||||
async sendOfflineMessage(clientUid: string, subject: string, message: string): Promise<void> {
|
||||
const sanitize = (s: string) => s.replace(/[\r\n\t]+/g, " ").trim();
|
||||
this.child?.stdin.write(`messageadd ${sanitize(clientUid)}\t${sanitize(subject)}\t${sanitize(message)}\n`);
|
||||
}
|
||||
|
||||
async deleteOfflineMessage(messageId: number): Promise<void> {
|
||||
this.child?.stdin.write(`messagedel ${messageId}\n`);
|
||||
}
|
||||
|
||||
async markOfflineMessageRead(messageId: number): Promise<void> {
|
||||
this.child?.stdin.write(`messageupdateflag ${messageId} 1\n`);
|
||||
}
|
||||
|
||||
async sendChatMessage(message: string): Promise<void> {
|
||||
const sanitized = message.replace(/[\r\n]+/g, " ").trim();
|
||||
if (sanitized) this.child?.stdin.write(`chat ${sanitized}\n`);
|
||||
|
||||
Reference in new issue
Block a user