GNUWeeb / GNUWeebBot

High-performance bot Telegram, running on Linux environment, written in C.
GNU General Public License v2.0
13 stars 8 forks source link

[core] Reply to message abstraction #17

Closed ammarfaizi2 closed 3 years ago

ammarfaizi2 commented 3 years ago

Short technical explanation

Currently, reply_to field for any event is set to NULL as we haven't created any mechanism to parse replied message.

Sample of event can be taken from text message:

struct tgev {
    /* 
     * We need to hold the JSON object to release
     * the resource, as it holds the reference
     * to `const char *`.
     *
     * It hurts the performance if we allocate
     * new memory and copy it. So let it here.
     */
    json_object *json;

    uint64_t    update_id;
    tgev_type_t type;
    struct_pad(0, 4);
    union {
        struct tgev_gif     msg_gif;
        struct tgev_text    msg_text;
        struct tgev_photo   msg_photo;
        struct tgev_sticker msg_sticker;
    };
};

struct tgev_text {
    uint64_t               msg_id;
    struct tgevi_from      from;
    struct tgevi_from      forward_from;
    const char             *fwd_sender_name;
    struct tgevi_chat      chat;
    struct tgevi_chat      sender_chat;
    time_t                 date;
    time_t                 forward_date;
    const char             *text;
    uint16_t               entity_c; /* How many entities[n] there are? */
    struct tgevi_entity    *entities;
    struct tgev            *reply_to;
    bool                   is_forwarded;
    bool                   is_unknown_fwd;
};

reply_to contains a pointer struct tgev, which means if the JSON keys are completely identical, we can use recursive call inside event parser.

TODO List