Fix read recipes only sent on next incoming message / read recipe
This commit is contained in:
parent
18a4d51b94
commit
601440004a
5 changed files with 20 additions and 18 deletions
|
@ -63,11 +63,6 @@ int p2tgl_status_is_present (PurpleStatus *status) {
|
|||
return !(strcmp (name, "unavailable") == 0 || strcmp (name, "away") == 0);
|
||||
}
|
||||
|
||||
int p2tgl_send_notifications (PurpleAccount *acct) {
|
||||
int ret = purple_account_get_bool (acct, TGP_KEY_SEND_READ_NOTIFICATIONS, TGP_DEFAULT_SEND_READ_NOTIFICATIONS);
|
||||
debug ("sending notifications: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void p2tgl_got_chat_in (struct tgl_state *TLS, tgl_peer_id_t chat, tgl_peer_id_t who,
|
||||
const char *message, int flags, time_t when) {
|
||||
|
|
|
@ -33,7 +33,6 @@ connection_data *pbn_get_data (PurpleBlistNode *node);
|
|||
struct tgl_state *gc_get_tls (PurpleConnection *gc);
|
||||
|
||||
int p2tgl_status_is_present (PurpleStatus *status);
|
||||
int p2tgl_send_notifications (PurpleAccount *acct);
|
||||
|
||||
void p2tgl_got_chat_in (struct tgl_state *TLS, tgl_peer_id_t chat, tgl_peer_id_t who, const char *message, int flags, time_t when);
|
||||
void p2tgl_got_im_combo (struct tgl_state *TLS, tgl_peer_id_t who, const char *msg, int flags, time_t when);
|
||||
|
|
|
@ -535,12 +535,10 @@ static void tgp_msg_display (struct tgl_state *TLS, struct tgp_msg_loading *C) {
|
|||
if (tgp_chat_show (TLS, &P->chat)) {
|
||||
p2tgl_got_chat_in (TLS, M->to_id, M->from_id, text, flags, M->date);
|
||||
}
|
||||
pending_reads_add (conn->pending_reads, M->to_id);
|
||||
break;
|
||||
}
|
||||
case TGL_PEER_ENCR_CHAT: {
|
||||
p2tgl_got_im_combo (TLS, M->to_id, text, flags, M->date);
|
||||
pending_reads_add (conn->pending_reads, M->to_id);
|
||||
break;
|
||||
}
|
||||
case TGL_PEER_USER: {
|
||||
|
@ -550,7 +548,6 @@ static void tgp_msg_display (struct tgl_state *TLS, struct tgp_msg_loading *C) {
|
|||
p2tgl_got_im_combo (TLS, M->to_id, text, flags, M->date);
|
||||
} else {
|
||||
p2tgl_got_im_combo (TLS, M->from_id, text, flags, M->date);
|
||||
pending_reads_add (conn->pending_reads, M->from_id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -576,8 +573,10 @@ static void tgp_msg_process_in_ready (struct tgl_state *TLS) {
|
|||
}
|
||||
g_queue_pop_head (conn->new_messages);
|
||||
|
||||
pending_reads_send_all (TLS);
|
||||
tgp_msg_display (TLS, C);
|
||||
pending_reads_add (conn->pending_reads, C->msg);
|
||||
pending_reads_send_all (TLS);
|
||||
|
||||
if (C->data) {
|
||||
g_free (C->data);
|
||||
}
|
||||
|
|
|
@ -29,24 +29,33 @@ static gint pending_reads_compare (gconstpointer a, gconstpointer b) {
|
|||
}
|
||||
|
||||
void pending_reads_send_all (struct tgl_state *TLS) {
|
||||
debug ("send all pending ack");
|
||||
if (! p2tgl_status_is_present (purple_account_get_active_status (tls_get_pa (TLS))) ||
|
||||
! p2tgl_send_notifications (tls_get_pa (TLS))) {
|
||||
if (! purple_account_get_bool (tls_get_pa (TLS), TGP_KEY_SEND_READ_NOTIFICATIONS,
|
||||
TGP_DEFAULT_SEND_READ_NOTIFICATIONS)) {
|
||||
debug ("automatic read recipes disabled, not sending recipes");
|
||||
return;
|
||||
}
|
||||
if (! p2tgl_status_is_present (purple_account_get_active_status (tls_get_pa (TLS)))) {
|
||||
debug ("user is present, not sending recipes");
|
||||
return;
|
||||
}
|
||||
debug ("sending all pending recipes");
|
||||
|
||||
tgl_peer_id_t *pending;
|
||||
GQueue *queue = tls_get_data (TLS)->pending_reads;
|
||||
while ((pending = (tgl_peer_id_t*) g_queue_pop_head(queue))) {
|
||||
while ((pending = (tgl_peer_id_t*) g_queue_pop_head (queue))) {
|
||||
tgl_do_mark_read (TLS, *pending, tgp_notify_on_error_gw, NULL);
|
||||
debug ("tgl_do_mark_read (%d)", tgl_get_peer_id (*pending));
|
||||
info ("tgl_do_mark_read (%d)", tgl_get_peer_id (*pending));
|
||||
free (pending);
|
||||
}
|
||||
}
|
||||
|
||||
void pending_reads_add (GQueue *queue, tgl_peer_id_t id) {
|
||||
void pending_reads_add (GQueue *queue, struct tgl_message *M) {
|
||||
tgl_peer_id_t *copy = malloc (sizeof(tgl_peer_id_t));
|
||||
*copy = id;
|
||||
if (tgl_get_peer_type(M->to_id) == TGL_PEER_USER) {
|
||||
*copy = M->from_id;
|
||||
} else {
|
||||
*copy = M->to_id;
|
||||
}
|
||||
if (! g_queue_find_custom (queue, copy, pending_reads_compare)) {
|
||||
g_queue_push_tail (queue, copy);
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ struct tgp_msg_sending {
|
|||
};
|
||||
|
||||
void pending_reads_send_all (struct tgl_state *TLS);
|
||||
void pending_reads_add (GQueue *queue, tgl_peer_id_t id);
|
||||
void pending_reads_add (GQueue *queue, struct tgl_message *M);
|
||||
void used_images_add (connection_data *data, gint imgid);
|
||||
void *connection_data_free (connection_data *conn);
|
||||
connection_data *connection_data_init (struct tgl_state *TLS, PurpleConnection *gc, PurpleAccount *pa);
|
||||
|
|
Loading…
Add table
Reference in a new issue