diff --git a/lua-tg.c b/lua-tg.c index a035f79..f878928 100644 --- a/lua-tg.c +++ b/lua-tg.c @@ -1141,8 +1141,16 @@ static int parse_lua_function (lua_State *L, struct lua_function *F) { ok = 0; break; } - P = get_peer (s); - if (!P || !(P->flags & FLAG_CREATED)) { + if (sscanf (s, "user#id%lld", &num) == 1 && num > 0) { + tgl_insert_empty_user (num); + P = tgl_peer_get (TGL_MK_USER (num)); + } else if (sscanf (s, "chat#id%lld", &num) == 1 && num > 0) { + tgl_insert_empty_chat (num); + P = tgl_peer_get (TGL_MK_CHAT (num)); + } else { + P = get_peer (s); + } + if (!P/* || !(P->flags & FLAG_CREATED)*/) { ok = 0; break; } diff --git a/structures.c b/structures.c index 90da68e..bffbb8f 100644 --- a/structures.c +++ b/structures.c @@ -88,6 +88,7 @@ char *tgls_default_create_print_name (tgl_peer_id_t id, const char *a1, const ch char *s = buf; while (*s) { if (*s == ' ') { *s = '_'; } + if (*s == '#') { *s = '@'; } s++; } s = buf; @@ -1421,6 +1422,22 @@ void tglp_insert_chat (tgl_peer_t *P) { Peers[peer_num ++] = P; } +void tgl_insert_empty_user (int uid) { + tgl_peer_id_t id = TGL_MK_USER (uid); + if (tgl_peer_get (id)) { return; } + tgl_peer_t *P = talloc0 (sizeof (*P)); + P->id = id; + tglp_insert_user (P); +} + +void tgl_insert_empty_chat (int cid) { + tgl_peer_id_t id = TGL_MK_CHAT (cid); + if (tgl_peer_get (id)) { return; } + tgl_peer_t *P = talloc0 (sizeof (*P)); + P->id = id; + tglp_insert_chat (P); +} + /* {{{ Free */ void tgls_free_user (struct tgl_user *U) { if (U->first_name) { tfree_str (U->first_name); } diff --git a/tgl.h b/tgl.h index 668bad0..a6b40bd 100644 --- a/tgl.h +++ b/tgl.h @@ -307,5 +307,7 @@ void tgl_dc_iterator_ex (void (*iterator)(struct tgl_dc *DC, void *extra), void double tglt_get_double_time (void); +void tgl_insert_empty_user (int id); +void tgl_insert_empty_chat (int id); #endif