Skip to content

Bad parsing for ChatId

The generated class ChatId are generated like:

        ChatId:
            type: object
            properties:
                broadcast_status_peer_id:
                    $ref: '#/components/schemas/RsPeerId'

But to send a message you need to a chat you need to use:

curl -u  "loc:pass"  -d '{ "id": {"type":2,"distant_chat_id":""},"msg":"hiya" }' http://127.0.0.1:9092/rsMsgs/sendChat

Where id is a ChatId. If we look at the code of this class we see this:

// Identifier for an chat endpoint like
// neighbour peer, distant peer, chatlobby, broadcast
class ChatId : RsSerializable
{
public:
    ChatId();
    virtual ~ChatId() = default;

    explicit ChatId(RsPeerId     id);
    explicit ChatId(ChatLobbyId  id);
    explicit ChatId(DistantChatPeerId id);
    explicit ChatId(std::string str);
    static ChatId makeBroadcastId();

    std::string toStdString() const;
    bool operator<(const ChatId& other) const;
    bool isSameEndpoint(const ChatId& other) const;

    bool operator==(const ChatId& other) const { return isSameEndpoint(other) ; }

    bool isNotSet() const;
    bool isPeerId() const;
    bool isDistantChatId() const;
    bool isLobbyId() const;
    bool isBroadcast() const;

    RsPeerId    toPeerId()  const;
    ChatLobbyId toLobbyId() const;
    DistantChatPeerId toDistantChatId() const;

    // for the very specific case of transfering a status string
    // from the chatservice to the gui,
    // this defines from which peer the status string came from
    RsPeerId broadcast_status_peer_id;
private:
    enum Type : uint8_t
    {    TYPE_NOT_SET,
        TYPE_PRIVATE,            // private chat with directly connected friend, peer_id is valid
        TYPE_PRIVATE_DISTANT,    // private chat with distant peer, gxs_id is valid
        TYPE_LOBBY,              // chat lobby id, lobby_id is valid
        TYPE_BROADCAST           // message to/from all connected peers
    };

    Type type;
    RsPeerId peer_id;
    DistantChatPeerId distant_chat_id;
    ChatLobbyId lobby_id;

    // RsSerializable interface
public:
    void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) {
        RS_SERIAL_PROCESS(broadcast_status_peer_id);
        RS_SERIAL_PROCESS(type);
        RS_SERIAL_PROCESS(peer_id);
        RS_SERIAL_PROCESS(distant_chat_id);
        RS_SERIAL_PROCESS(lobby_id);
    }
};

So as we can see, we need to expose also the private attributes:

    Type type;
    RsPeerId peer_id;
    DistantChatPeerId distant_chat_id;
    ChatLobbyId lobby_id;

This class will not be supported in the future because the chat backend will change, but by the way, I suggest an easy fix creating an exception to expose also private attributes.