// SPDX-FileCopyrightText: 2026 Matvey Shcherbinin // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL // KOutNet - what a chat transport must be able to do. // // one backend per transport translates one protocol into the window's terms. // the window routes everything through ChatBackendRegistry keyed on the chat // id alone, so QML never sees a prefix: adding a transport is one backend // class, a registration in main.cpp and, if its rows look different, one // Connections block for its receive signals. // // Backends have no Q_OBJECT and no signals: receive paths are genuinely // per-transport (LAN multiplexes everything through one message packet, Matrix // has one signal per row kind), so each backend emits its own and Main.qml // listens to the backend objects it registered. // // everything is keyed on the chat id string - the one namespace every model // and the history on disk already share (see core/chat/ChatAddress.h). #pragma once #include #include #include #include "core/chat/ChatAddress.h" namespace koutnet { class ChatBackend : public QObject { public: explicit ChatBackend(QObject *parent = nullptr) : QObject(parent) { } // which transport this backend is, and whether a chat id belongs to it. virtual chatid::Transport transport() const = 0; virtual bool canHandle(const QString &chatId) const = 0; // Capabilities decide what the interface offers for a conversation on this // transport. False is a statement, not a bug: the window must not offer // what the transport does not have. // // serverOwnsTimeline: rows come back through the ingest path under the id // the whole room sees, so the window must not render a local row before // sending (Matrix; Rocket.Chat and Telegram will be the same). LAN renders // locally and sends a datagram, so it is false. // // hasRooms: chats carry room furniture - a member list, an info column, a // leave action (Matrix, Rocket.Chat, Telegram). A LAN chat is a peer card // or nothing. // // supportsCalls / supportsTyping / supportsEdits / supportsReactions: the // LAN protocol has all four; Matrix now carries typing, edits, unsends and // reactions through the standard endpoints (only calls are left). The // window offers each only when the flag says so. virtual bool serverOwnsTimeline(const QString &chatId) const = 0; virtual bool hasRooms(const QString &chatId) const = 0; virtual bool supportsCalls(const QString &chatId) const = 0; virtual bool supportsTyping(const QString &chatId) const = 0; virtual bool supportsEdits(const QString &chatId) const = 0; virtual bool supportsReactions(const QString &chatId) const = 0; // True for a backend that is wired into the registry and addressable but // not yet carrying live traffic - a scaffold the interface shows as // "preview" rather than offering its actions. Real backends (LAN, Matrix) // answer false; the Rocket.Chat / Telegram / Tox scaffolds answer true // until each is filled in. Defaults to false so an existing backend needs // no change to keep being treated as shipping. virtual bool isPreview() const { return false; } // Outgoing actions. False means refused here (unknown chat, not signed in, // the transport's own reason): the caller must not invent a result. virtual bool sendText(const QString &chatId, const QString &text) = 0; virtual bool sendFile(const QString &chatId, const QString &localFilePath) = 0; virtual void markRead(const QString &chatId) = 0; virtual void sendTyping(const QString &chatId) = 0; virtual void sendReaction(const QString &chatId, const QVariant &identifier, const QString &emoji, bool added) = 0; virtual bool leaveChat(const QString &chatId) = 0; // Rewriting a message already on the server replaces it there; deleting it // redacts it, which is the closest the transports get to each other's // unsend. Defaults refuse, so a transport without edits answers the same // way it answers a message it cannot carry - and the capability flags keep // the window from asking in the first place. // // identifier: a QVariant carrying either a double (LAN stamp) or a string // (Matrix event id). Each backend resolves it to whatever its protocol // needs. virtual bool sendEdit(const QString &chatId, const QVariant &identifier, const QString &newText) { Q_UNUSED(chatId) Q_UNUSED(identifier) Q_UNUSED(newText) return false; } virtual bool sendDelete(const QString &chatId, const QVariant &identifier) { Q_UNUSED(chatId) Q_UNUSED(identifier) return false; } // Room-shaped metadata, empty when the chat has none. Keys a window may // rely on: roomId (present exactly when there is a room), displayName, // topic, avatarUrl (empty, http(s), or an mxc:// the Matrix network factory // rewrites), joinedCount, encrypted. A backend may add its own keys on top; // the window must not read a key it does not know. virtual QVariantMap roomInfo(const QString &chatId) const = 0; virtual QVariantList roomMembers(const QString &chatId) const = 0; virtual QVariantMap memberInfo(const QString &chatId, const QString &userId) const = 0; }; } // namespace koutnet