diff --git a/telegram-purple.c b/telegram-purple.c index e43d5cb..0c1ba4d 100644 --- a/telegram-purple.c +++ b/telegram-purple.c @@ -244,11 +244,7 @@ static void update_marked_read (struct tgl_state *TLS, int num, struct tgl_messa } else { to_id = list[i]->to_id; } - PurpleConversation *conv = p2tgl_find_conversation_with_account (TLS, to_id); - if (conv) { - p2tgl_conversation_write (conv, to_id, _("Message marked as read."), - PURPLE_MESSAGE_NO_LOG | PURPLE_MESSAGE_SYSTEM, (int)time (NULL)); - } + tgp_msg_sys_out (TLS, _("Message marked as read."), to_id, TRUE); } } diff --git a/tgp-msg.c b/tgp-msg.c index c852123..76a5e2b 100644 --- a/tgp-msg.c +++ b/tgp-msg.c @@ -37,8 +37,6 @@ #include "tgp-chat.h" #include "msglog.h" -static void tgp_msg_err_out (struct tgl_state *TLS, const char *error, tgl_peer_id_t to); - static char *format_service_msg (struct tgl_state *TLS, struct tgl_message *M) { assert (M && M->flags & TGLMF_SERVICE); connection_data *conn = TLS->ev_base; @@ -233,7 +231,7 @@ static int tgp_msg_send_split (struct tgl_state *TLS, const char *message, tgl_p return 1; } -static void tgp_msg_err_out (struct tgl_state *TLS, const char *error, tgl_peer_id_t to) { +void tgp_msg_err_out (struct tgl_state *TLS, const char *error, tgl_peer_id_t to) { int flags = PURPLE_MESSAGE_ERROR | PURPLE_MESSAGE_SYSTEM; time_t now; time (&now); @@ -243,11 +241,34 @@ static void tgp_msg_err_out (struct tgl_state *TLS, const char *error, tgl_peer_ break; case TGL_PEER_USER: case TGL_PEER_ENCR_CHAT: - p2tgl_got_im (TLS, to, error, flags, now); + serv_got_im (tg_get_conn (TLS), tgp_blist_peer_get_name (TLS, to), error, flags, now); break; } } +void tgp_msg_sys_out (struct tgl_state *TLS, const char *msg, tgl_peer_id_t to_id, int no_log) { + int flags = PURPLE_MESSAGE_SYSTEM; + if (no_log) { + flags |= PURPLE_MESSAGE_NO_LOG; + } + time_t now; + time (&now); + + switch (tgl_get_peer_type (to_id)) { + case TGL_PEER_CHAT: + p2tgl_got_chat_in (TLS, to_id, to_id, msg, flags, now); + break; + case TGL_PEER_USER: + case TGL_PEER_ENCR_CHAT: { + PurpleConversation *conv = p2tgl_find_conversation_with_account (TLS, to_id); + if (conv) { + purple_conversation_write (conv, tgp_blist_peer_get_name (TLS, to_id), msg, flags, now); + } + break; + } + } +} + void send_inline_picture_done (struct tgl_state *TLS, void *extra, int success, struct tgl_message *msg) { if (!success) { char *errormsg = g_strdup_printf ("%d: %s", TLS->error_code, TLS->error); diff --git a/tgp-msg.h b/tgp-msg.h index e671aad..c071239 100644 --- a/tgp-msg.h +++ b/tgp-msg.h @@ -38,4 +38,7 @@ void tgp_msg_recv (struct tgl_state *TLS, struct tgl_message *M); */ int tgp_msg_send (struct tgl_state *TLS, const char *msg, tgl_peer_id_t to); +void tgp_msg_err_out (struct tgl_state *TLS, const char *error, tgl_peer_id_t to); +void tgp_msg_sys_out (struct tgl_state *TLS, const char *msg, tgl_peer_id_t to_id, int no_log); + #endif