Supported user#id... and chat#id... from lua
This commit is contained in:
parent
c711019ea8
commit
6fb56f1496
3 changed files with 29 additions and 2 deletions
12
lua-tg.c
12
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;
|
||||
}
|
||||
|
|
17
structures.c
17
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); }
|
||||
|
|
2
tgl.h
2
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
|
||||
|
|
Loading…
Add table
Reference in a new issue