Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vvaltman committed Jun 18, 2015
1 parent d976963 commit 638b26d
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
2.0.3
* updated to layer 31 (bot support)
* changed signature of contact_search method
2.0.2
* fixed small bugs
* added block/unblock user method
Expand Down
8 changes: 4 additions & 4 deletions binlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,17 +708,17 @@ static int fetch_comb_binlog_message_new (struct tgl_state *TLS, struct tl_ds_bi
M->reply_id = DS_LVAL (DS_U->reply_id);
}

if (DS_U->reply_markup) {
M->reply_markup = tglf_fetch_alloc_reply_markup (TLS, DS_U->reply_markup);
}

if (flags & 0x10000) {
tglm_message_insert (TLS, M);
}

if (!(flags & TGLMF_UNREAD) && (M->flags & TGLMF_UNREAD)) {
tgls_messages_mark_read (TLS, M, M->flags & TGLMF_OUT, M->id);
}

if (DS_U->reply_markup) {
M->reply_markup = tglf_fetch_alloc_reply_markup (TLS, M->next, DS_U->reply_markup);
}
return 0;
}

Expand Down
23 changes: 8 additions & 15 deletions queries.c
Original file line number Diff line number Diff line change
Expand Up @@ -1784,34 +1784,27 @@ void tgl_do_set_username (struct tgl_state *TLS, const char *username, int usern
/* {{{ Contacts search */

int contact_search_on_answer (struct tgl_state *TLS, struct query *q, void *D) {
struct tl_ds_contacts_found *DS_CF = D;

int n = DS_LVAL (DS_CF->users->cnt);

struct tgl_user **UL = talloc (sizeof (void *) * n);
int i;
for (i = 0; i < n; i++) {
UL[i] = tglf_fetch_alloc_user_new (TLS, DS_CF->users->data[i]);
}
struct tl_ds_user *DS_U = D;

struct tgl_user *U = tglf_fetch_alloc_user_new (TLS, DS_U);

if (q->callback) {
((void (*)(struct tgl_state *,void *, int, int, struct tgl_user **))q->callback) (TLS, q->callback_extra, 1, n, UL);
((void (*)(struct tgl_state *,void *, int, struct tgl_user *))q->callback) (TLS, q->callback_extra, 1, U);
}
tfree (UL, sizeof (void *) * n);

return 0;
}

static struct query_methods contact_search_methods = {
.on_answer = contact_search_on_answer,
.on_error = q_list_on_error,
.type = TYPE_TO_PARAM(contacts_found)
.type = TYPE_TO_PARAM(user)
};

void tgl_do_contact_search (struct tgl_state *TLS, const char *name, int name_len, int limit, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success, int cnt, struct tgl_user *U[]), void *callback_extra) {
void tgl_do_contact_search (struct tgl_state *TLS, const char *name, int name_len, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_user *U), void *callback_extra) {
clear_packet ();
out_int (CODE_contacts_search);
out_int (CODE_contacts_resolve_username);
out_cstring (name, name_len);
out_int (limit);

tglq_send_query (TLS, TLS->DC_working, packet_ptr - packet_buffer, packet_buffer, &contact_search_methods, 0, callback, callback_extra);
}
Expand Down
1 change: 1 addition & 0 deletions scheme31.tl
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ keyboardButton#a2fa4880 text:string = KeyboardButton;

keyboardButtonRow#77608b83 buttons:Vector<KeyboardButton> = KeyboardButtonRow;

replyKeyboardHide#ced6ebbc = ReplyMarkup;
replyKeyboardMarkup#3502758c flags:int rows:Vector<KeyboardButtonRow> = ReplyMarkup;

---functions---
Expand Down
18 changes: 16 additions & 2 deletions structures.c
Original file line number Diff line number Diff line change
Expand Up @@ -1618,11 +1618,12 @@ struct tgl_bot_info *tglf_fetch_alloc_bot_info (struct tgl_state *TLS, struct tl
return B;
}

struct tgl_message_reply_markup *tglf_fetch_alloc_reply_markup (struct tgl_state *TLS, struct tl_ds_reply_markup *DS_RM) {
struct tgl_message_reply_markup *tglf_fetch_alloc_reply_markup (struct tgl_state *TLS, struct tgl_message *M, struct tl_ds_reply_markup *DS_RM) {
if (!DS_RM) { return NULL; }

struct tgl_message_reply_markup *R = talloc0 (sizeof (*R));
R->flags = DS_LVAL (DS_RM->flags);
R->refcnt = 1;

R->rows = DS_LVAL (DS_RM->rows->cnt);

Expand Down Expand Up @@ -1840,8 +1841,21 @@ void tgls_clear_message (struct tgl_state *TLS, struct tgl_message *M) {
}
}

void tgls_free_reply_markup (struct tgl_state *TLS, struct tgl_message_reply_markup *R) {
if (!--R->refcnt) {
tfree (R->buttons, R->row_start[R->rows] * sizeof (void *));
tfree (R->row_start, 4 * (R->rows + 1));
tfree (R, sizeof (*R));
} else {
assert (R->refcnt > 0);
}
}

void tgls_free_message (struct tgl_state *TLS, struct tgl_message *M) {
tgls_clear_message (TLS, M);
if (M->reply_markup) {
tgls_free_reply_markup (TLS, M->reply_markup);
}
tfree (M, sizeof (*M));
}

Expand Down
2 changes: 1 addition & 1 deletion tgl-fetch.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ struct tgl_message *tglf_fetch_alloc_message_short_new (struct tgl_state *TLS, s
struct tgl_message *tglf_fetch_alloc_message_short_chat_new (struct tgl_state *TLS, struct tl_ds_updates *DS_U);
struct tgl_photo *tglf_fetch_alloc_photo_new (struct tgl_state *TLS, struct tl_ds_photo *DS_P);
struct tgl_bot_info *tglf_fetch_alloc_bot_info (struct tgl_state *TLS, struct tl_ds_bot_info *DS_BI);
struct tgl_message_reply_markup *tglf_fetch_alloc_reply_markup (struct tgl_state *TLS, struct tl_ds_reply_markup *DS_RM);
struct tgl_message_reply_markup *tglf_fetch_alloc_reply_markup (struct tgl_state *TLS, struct tgl_message *M, struct tl_ds_reply_markup *DS_RM);
#endif
1 change: 1 addition & 0 deletions tgl-layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ struct tgl_message_media {
};

struct tgl_message_reply_markup {
int refcnt;
int flags;
int rows;
int *row_start;
Expand Down
4 changes: 2 additions & 2 deletions tgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,8 @@ void tgl_do_create_secret_chat (struct tgl_state *TLS, tgl_user_id_t id, void (*
// if limit is > 100 there is a (small) chance of one dialog received twice
void tgl_do_get_dialog_list (struct tgl_state *TLS, int limit, int offset, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success, int size, tgl_peer_id_t peers[], int last_msg_id[], int unread_count[]), void *callback_extra);

// searches contacts by name
void tgl_do_contact_search (struct tgl_state *TLS, const char *pattern, int pattern_len, int limit, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success, int cnt, struct tgl_user *U[]), void *callback_extra);
// resolves username
void tgl_do_contact_search (struct tgl_state *TLS, const char *name, int name_len, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_user *U), void *callback_extra);

// requests contact list
void tgl_do_update_contact_list (struct tgl_state *TLS, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success, int size, struct tgl_user *contacts[]), void *callback_extra);
Expand Down

0 comments on commit 638b26d

Please sign in to comment.