Fix outgoing messages for Adium and old libpurple versions
This commit is contained in:
parent
c85b8da619
commit
3b940fca1d
3 changed files with 66 additions and 11 deletions
|
@ -255,7 +255,6 @@ static char *format_message (struct tgl_message *M) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static void tgl_do_send_unescape_message (struct tgl_state *TLS, const char *message, tgl_peer_id_t to) {
|
||||
gchar *raw = purple_unescape_html(message);
|
||||
tgl_do_send_message (TLS, to, raw, (int)strlen (raw), 0, 0);
|
||||
|
@ -345,14 +344,11 @@ static void update_message_received (struct tgl_state *TLS, struct tgl_message *
|
|||
(M->flags & (FLAG_MESSAGE_EMPTY | FLAG_DELETED)) ||
|
||||
!(M->flags & FLAG_CREATED) ||
|
||||
!M->message ||
|
||||
our_msg (TLS, M) // Message sent in this application, already added to history
|
||||
our_msg (TLS, M) ||
|
||||
!tgl_get_peer_type (M->to_id)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (!tgl_get_peer_type (M->to_id)) {
|
||||
warning ("Bad msg\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (M->media.type == tgl_message_media_photo) {
|
||||
tgl_do_load_photo (TLS, &M->media.photo, on_message_load_photo, M);
|
||||
|
@ -367,7 +363,7 @@ static void update_message_received (struct tgl_state *TLS, struct tgl_message *
|
|||
|
||||
case TGL_PEER_ENCR_CHAT:
|
||||
p2tgl_got_im (TLS, M->to_id, text, PURPLE_MESSAGE_RECV, M->date);
|
||||
|
||||
|
||||
pending_reads_add (conn->pending_reads, M->to_id);
|
||||
if (p2tgl_status_is_present (purple_account_get_active_status(conn->pa))) {
|
||||
pending_reads_send_all (conn->pending_reads, conn->TLS);
|
||||
|
@ -377,9 +373,7 @@ static void update_message_received (struct tgl_state *TLS, struct tgl_message *
|
|||
case TGL_PEER_USER:
|
||||
|
||||
if (out_msg (TLS, M)) {
|
||||
// Outgoing message sent from a different device
|
||||
// :TODO: figure out how to add messages from different devices to history
|
||||
p2tgl_got_im (TLS, M->to_id, text, PURPLE_MESSAGE_SEND, M->date);
|
||||
p2tgl_got_im_combo (TLS, M->to_id, text, PURPLE_MESSAGE_SEND, M->date);
|
||||
} else {
|
||||
p2tgl_got_im (TLS, M->from_id, text, PURPLE_MESSAGE_RECV, M->date);
|
||||
|
||||
|
|
58
tgp-2prpl.c
58
tgp-2prpl.c
|
@ -117,6 +117,31 @@ void p2tgl_got_im (struct tgl_state *TLS, tgl_peer_id_t who, const char *msg, in
|
|||
g_free (name);
|
||||
}
|
||||
|
||||
void p2tgl_got_im_combo (struct tgl_state *TLS, tgl_peer_id_t who, const char *msg, int flags, time_t when) {
|
||||
|
||||
/*
|
||||
Outgoing messages are not well supported in different libpurple clients,
|
||||
p2tgl_conversation_write should have the best among different versions. Unfortunately
|
||||
this causes buggy formatting in Adium, so we don't use this workaround in that case.
|
||||
|
||||
NOTE: Outgoing messages will not work in Adium <= 1.6.0, there is no way to print outgoing
|
||||
messages in those versions at all.
|
||||
*/
|
||||
#ifndef __ADIUM_
|
||||
if (flags & PURPLE_MESSAGE_SEND) {
|
||||
PurpleConversation *conv = p2tgl_find_conversation_with_account (TLS, who);
|
||||
if (!conv) {
|
||||
conv = p2tgl_conversation_new(TLS, who);
|
||||
}
|
||||
p2tgl_conversation_write (conv, who, msg, PURPLE_MESSAGE_SEND, when);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
p2tgl_got_im (TLS, who, msg, flags, when);
|
||||
}
|
||||
|
||||
|
||||
void p2tgl_got_typing (struct tgl_state *TLS, tgl_peer_id_t user, int timeout) {
|
||||
char *who = g_strdup_printf("%d", tgl_get_peer_id(user));
|
||||
|
||||
|
@ -135,6 +160,39 @@ PurpleBuddy *p2tgl_buddy_find (struct tgl_state *TLS, tgl_peer_id_t user) {
|
|||
return b;
|
||||
}
|
||||
|
||||
PurpleConversation *p2tgl_find_conversation_with_account (struct tgl_state *TLS, tgl_peer_id_t peer) {
|
||||
int type = PURPLE_CONV_TYPE_IM;
|
||||
if (tgl_get_peer_type (peer) == TGL_PEER_CHAT) {
|
||||
type = PURPLE_CONV_TYPE_CHAT;
|
||||
}
|
||||
char *who = g_strdup_printf("%d", tgl_get_peer_id(peer));
|
||||
|
||||
PurpleConversation *conv = purple_find_conversation_with_account (type, who, tg_get_acc(TLS));
|
||||
|
||||
g_free (who);
|
||||
return conv;
|
||||
}
|
||||
|
||||
void p2tgl_conversation_write (PurpleConversation *conv, tgl_peer_id_t who, const char *message, int flags, int date) {
|
||||
char *name = p2tgl_peer_strdup_id (who);
|
||||
|
||||
purple_conv_im_write(purple_conversation_get_im_data(conv), name, message, flags, date);
|
||||
// purple_conversation_write (conv, name, message, flags, date);
|
||||
|
||||
g_free (name);
|
||||
}
|
||||
|
||||
PurpleConversation *p2tgl_conversation_new (struct tgl_state *TLS, tgl_peer_id_t who) {
|
||||
int type = tgl_get_peer_type (who) == TGL_PEER_CHAT ? PURPLE_CONV_TYPE_CHAT : PURPLE_CONV_TYPE_IM;
|
||||
|
||||
char *name = p2tgl_peer_strdup_id (who);
|
||||
PurpleConversation *conv = purple_conversation_new(type, tg_get_acc(TLS), name);
|
||||
g_free (name);
|
||||
|
||||
return conv;
|
||||
}
|
||||
|
||||
|
||||
PurpleBuddy *p2tgl_buddy_new (struct tgl_state *TLS, tgl_peer_t *user) {
|
||||
char *alias = p2tgl_strdup_alias (user);
|
||||
char *name = p2tgl_peer_strdup_id (user->id);
|
||||
|
|
|
@ -45,6 +45,7 @@ void p2tgl_got_chat_in (struct tgl_state *TLS, tgl_peer_id_t chat, tgl_peer_id_t
|
|||
|
||||
void p2tgl_got_alias (struct tgl_state *TLS, tgl_peer_id_t who, const char *alias);
|
||||
void p2tgl_got_im (struct tgl_state *TLS, tgl_peer_id_t who, const char *msg, 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);
|
||||
void p2tgl_got_typing (struct tgl_state *TLS, tgl_peer_id_t name, int timeout);
|
||||
|
||||
|
||||
|
@ -60,7 +61,9 @@ void p2tgl_connection_set_display_name(struct tgl_state *TLS, tgl_peer_t *user);
|
|||
void p2tgl_conv_del_user (PurpleConversation *conv, tgl_peer_id_t user);
|
||||
void p2tgl_conv_add_users (PurpleConversation *conv, struct tgl_chat_user *list);
|
||||
void p2tgl_conv_add_user (PurpleConversation *conv, struct tgl_chat_user user, char *message, int flags, int new_arrival);
|
||||
|
||||
PurpleConversation *p2tgl_find_conversation_with_account (struct tgl_state *TLS, tgl_peer_id_t peer);
|
||||
void p2tgl_conversation_write (PurpleConversation *conv, tgl_peer_id_t who, const char *message, int flags, int date);
|
||||
PurpleConversation *p2tgl_conversation_new (struct tgl_state *TLS, tgl_peer_id_t who);
|
||||
|
||||
PurpleChat *p2tgl_chat_new (struct tgl_state *TLS, struct tgl_chat *chat);
|
||||
PurpleChat *p2tgl_chat_find (struct tgl_state *TLS, tgl_peer_id_t chat);
|
||||
|
|
Loading…
Add table
Reference in a new issue