diff options
author | Eion Robb <eion@robbmob.com> | 2017-05-23 20:30:27 +1200 |
---|---|---|
committer | Eion Robb <eion@robbmob.com> | 2017-05-23 20:30:27 +1200 |
commit | 2a3e07f61e274b945659064245afe8d68068be00 (patch) | |
tree | 90f53ae5c68713f32260e4c07539cc2616ac9d7c | |
parent | d5e8df078fa6045e9d0799b5475acf93e7c57622 (diff) | |
download | purple-matrix-2a3e07f61e274b945659064245afe8d68068be00.tar.gz |
Support HTML formatting on sending/receiving messages
-rw-r--r-- | libmatrix.c | 2 | ||||
-rw-r--r-- | matrix-room.c | 18 |
2 files changed, 15 insertions, 5 deletions
diff --git a/libmatrix.c b/libmatrix.c index 5b3118c..2cc5de0 100644 --- a/libmatrix.c +++ b/libmatrix.c @@ -83,6 +83,8 @@ void matrixprpl_login(PurpleAccount *acct) PurpleConnection *pc = purple_account_get_connection(acct); matrix_connection_new(pc); matrix_connection_start_login(pc); + + pc->flags |= PURPLE_CONNECTION_HTML; } diff --git a/matrix-room.c b/matrix-room.c index 1940620..e7df9ff 100644 --- a/matrix-room.c +++ b/matrix-room.c @@ -872,8 +872,12 @@ void matrix_room_handle_timeline_event(PurpleConversation *conv, } flags = PURPLE_MESSAGE_RECV; - escaped_body = purple_markup_escape_text(tmp_body ? tmp_body : msg_body, -1); - g_free(tmp_body); + if (purple_strequal(matrix_json_object_get_string_member(json_content_obj, "format"), "org.matrix.custom.html")) { + escaped_body = g_strdup(matrix_json_object_get_string_member(json_content_obj, "formatted_body")); + } else { + escaped_body = purple_markup_escape_text(tmp_body ? tmp_body : msg_body, -1); + } + g_free(tmp_body); purple_debug_info("matrixprpl", "got message from %s in %s\n", sender_id, room_id); serv_got_chat_in(conv->account->gc, g_str_hash(room_id), @@ -1187,7 +1191,7 @@ void matrix_room_send_message(PurpleConversation *conv, const gchar *message) PurpleConvChat *chat = PURPLE_CONV_CHAT(conv); const char *type_string = "m.text"; const char *image_start, *image_end; - gchar *message_to_send; + gchar *message_to_send, *message_dup; GData *image_attribs; /* Matrix doesn't have messages that have both images and text in, so @@ -1223,20 +1227,24 @@ void matrix_room_send_message(PurpleConversation *conv, const gchar *message) * escape the message body. Matrix clients don't unescape the bodies * either, so they end up seeing " instead of " */ - message_to_send = purple_unescape_html(message); + message_dup = g_strdup(message); + message_to_send = purple_markup_strip_html(message_dup); if (purple_message_meify(message_to_send, -1)) { type_string = "m.emote"; + purple_message_meify(message_dup, -1); } content = json_object_new(); json_object_set_string_member(content, "msgtype", type_string); json_object_set_string_member(content, "body", message_to_send); + json_object_set_string_member(content, "formatted_body", message_dup); + json_object_set_string_member(content, "format", "org.matrix.custom.html"); _enqueue_event(conv, "m.room.message", content, NULL, NULL); json_object_unref(content); purple_conv_chat_write(chat, _get_my_display_name(conv), - message, PURPLE_MESSAGE_SEND, g_get_real_time()/1000/1000); + message_dup, PURPLE_MESSAGE_SEND, g_get_real_time()/1000/1000); g_free(message_to_send); } |