From 482e9d97fb02d1d332bea2c156b2f915779c6fd4 Mon Sep 17 00:00:00 2001 From: Eion Robb Date: Sun, 12 Mar 2017 12:52:15 +1300 Subject: Re-use the device-id provided by the server so we don't show up once for each login --- matrix-api.c | 10 +++++++--- matrix-api.h | 1 + matrix-connection.c | 6 +++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/matrix-api.c b/matrix-api.c index b72af20..9cd7670 100644 --- a/matrix-api.c +++ b/matrix-api.c @@ -585,7 +585,7 @@ void matrix_api_cancel(MatrixApiRequestData *data) } -gchar *_build_login_body(const gchar *username, const gchar *password) +gchar *_build_login_body(const gchar *username, const gchar *password, const gchar *device_id) { JsonObject *body; JsonNode *node; @@ -596,7 +596,10 @@ gchar *_build_login_body(const gchar *username, const gchar *password) json_object_set_string_member(body, "type", "m.login.password"); json_object_set_string_member(body, "user", username); json_object_set_string_member(body, "password", password); - + json_object_set_string_member(body, "initial_device_display_name", "purple-matrix"); + if (device_id != NULL) + json_object_set_string_member(body, "device_id", device_id); + node = json_node_new(JSON_NODE_OBJECT); json_node_set_object(node, body); json_object_unref(body); @@ -612,6 +615,7 @@ gchar *_build_login_body(const gchar *username, const gchar *password) MatrixApiRequestData *matrix_api_password_login(MatrixConnectionData *conn, const gchar *username, const gchar *password, + const gchar *device_id, MatrixApiCallback callback, gpointer user_data) { @@ -625,7 +629,7 @@ MatrixApiRequestData *matrix_api_password_login(MatrixConnectionData *conn, url = g_strconcat(conn->homeserver, "_matrix/client/api/v1/login", NULL); - json = _build_login_body(username, password); + json = _build_login_body(username, password, device_id); fetch_data = matrix_api_start(url, "POST", json, conn, callback, NULL, NULL, user_data, 0); diff --git a/matrix-api.h b/matrix-api.h index 8463a93..183405c 100644 --- a/matrix-api.h +++ b/matrix-api.h @@ -134,6 +134,7 @@ void matrix_api_cancel(MatrixApiRequestData *request); MatrixApiRequestData *matrix_api_password_login(MatrixConnectionData *conn, const gchar *username, const gchar *password, + const gchar *device_id, MatrixApiCallback callback, gpointer user_data); diff --git a/matrix-connection.c b/matrix-connection.c index 893e3db..91c660a 100644 --- a/matrix-connection.c +++ b/matrix-connection.c @@ -181,6 +181,8 @@ static void _login_completed(MatrixConnectionData *conn, conn->access_token = g_strdup(access_token); conn->user_id = g_strdup(matrix_json_object_get_string_member(root_obj, "user_id")); + purple_account_set_string(pc->account, "device_id", + matrix_json_object_get_string_member(root_obj, "device_id")); /* start the sync loop */ next_batch = purple_account_get_string(pc->account, @@ -233,7 +235,9 @@ void matrix_connection_start_login(PurpleConnection *pc) purple_connection_update_progress(pc, _("Logging in"), 0, 3); matrix_api_password_login(conn, acct->username, - purple_account_get_password(acct), _login_completed, conn); + purple_account_get_password(acct), + purple_account_get_string(acct, "device_id", NULL), + _login_completed, conn); } -- cgit From 2f9471dffd8ed4c82d1723f7909b6c7324bbd518 Mon Sep 17 00:00:00 2001 From: Eion Robb Date: Sun, 12 Mar 2017 13:02:41 +1300 Subject: Support display of room topics --- matrix-room.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/matrix-room.c b/matrix-room.c index a0f91de..1940620 100644 --- a/matrix-room.c +++ b/matrix-room.c @@ -169,6 +169,19 @@ static void _on_member_change(PurpleConversation *conv, new_state->content); } +/** + * Called when there is a change to the topic. + */ +static void _on_topic_change(PurpleConversation *conv, + MatrixRoomEvent *new_state) +{ + PurpleConvChat *chat = PURPLE_CONV_CHAT(conv); + + purple_conv_chat_set_topic(chat, new_state->sender, + matrix_json_object_get_string_member(new_state->content, + "topic")); +} + /** * Called when there is a state update. @@ -196,6 +209,9 @@ static void _on_state_update(const gchar *event_type, strcmp(event_type, "m.room.name") == 0) { _schedule_name_update(conv); } + else if(strcmp(event_type, "m.room.topic") == 0) { + _on_topic_change(conv, new_state); + } } void matrix_room_handle_state_event(struct _PurpleConversation *conv, -- cgit From ceec85597aef96b4bd8b952fee20a7ceab63c0be Mon Sep 17 00:00:00 2001 From: "Dr. David Alan Gilbert" Date: Mon, 17 Apr 2017 17:36:58 +0100 Subject: Fix image download I had an extra / after the hostname, and it doesn't need the access key. (Interestingly my server would take the extra / but matrix.org wouldn't) Signed-off-by: Dr. David Alan Gilbert --- matrix-api.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/matrix-api.c b/matrix-api.c index 9cd7670..3bc1b00 100644 --- a/matrix-api.c +++ b/matrix-api.c @@ -875,10 +875,8 @@ MatrixApiRequestData *matrix_api_download_file(MatrixConnectionData *conn, return NULL; } url = g_string_new(conn->homeserver); - g_string_append(url, "/_matrix/media/r0/download/"); + g_string_append(url, "_matrix/media/r0/download/"); g_string_append(url, uri + 6); /* i.e. after the mxc:// */ - g_string_append(url, "?access_token="); - g_string_append(url, purple_url_encode(conn->access_token)); /* I'd like to validate the headers etc a bit before downloading the * data (maybe using _handle_header_completed), also I'm not convinced -- cgit From 2a3e07f61e274b945659064245afe8d68068be00 Mon Sep 17 00:00:00 2001 From: Eion Robb Date: Tue, 23 May 2017 20:30:27 +1200 Subject: Support HTML formatting on sending/receiving messages --- libmatrix.c | 2 ++ 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); } -- cgit From 758d318343d24a301162fccf3671f2262406ca8e Mon Sep 17 00:00:00 2001 From: "Dr. David Alan Gilbert" Date: Sat, 27 May 2017 02:38:11 +0100 Subject: Fix image upload I made the same mistake in image upload I had in download - an extra / at the start triggered a 500. Signed-off-by: Dr. David Alan Gilbert --- matrix-api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix-api.c b/matrix-api.c index 3bc1b00..3d72728 100644 --- a/matrix-api.c +++ b/matrix-api.c @@ -837,7 +837,7 @@ MatrixApiRequestData *matrix_api_upload_file(MatrixConnectionData *conn, MatrixApiRequestData *fetch_data; url = g_string_new(conn->homeserver); - g_string_append(url, "/_matrix/media/r0/upload"); + g_string_append(url, "_matrix/media/r0/upload"); g_string_append(url, "?access_token="); g_string_append(url, purple_url_encode(conn->access_token)); -- cgit From 3f9ec31a3da6bd3942c889543f35e091ccc7b5d2 Mon Sep 17 00:00:00 2001 From: Eion Robb Date: Sun, 28 May 2017 14:16:42 +1200 Subject: Fix whitespace and a memleak --- libmatrix.c | 2 +- matrix-room.c | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/libmatrix.c b/libmatrix.c index 2cc5de0..acb188b 100644 --- a/libmatrix.c +++ b/libmatrix.c @@ -84,7 +84,7 @@ void matrixprpl_login(PurpleAccount *acct) matrix_connection_new(pc); matrix_connection_start_login(pc); - pc->flags |= PURPLE_CONNECTION_HTML; + pc->flags |= PURPLE_CONNECTION_HTML; } diff --git a/matrix-room.c b/matrix-room.c index e7df9ff..9e8f805 100644 --- a/matrix-room.c +++ b/matrix-room.c @@ -872,12 +872,12 @@ void matrix_room_handle_timeline_event(PurpleConversation *conv, } flags = PURPLE_MESSAGE_RECV; - 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); + 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), @@ -1227,12 +1227,12 @@ 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_dup = g_strdup(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); + purple_message_meify(message_dup, -1); } content = json_object_new(); @@ -1246,5 +1246,7 @@ void matrix_room_send_message(PurpleConversation *conv, const gchar *message) purple_conv_chat_write(chat, _get_my_display_name(conv), message_dup, PURPLE_MESSAGE_SEND, g_get_real_time()/1000/1000); + g_free(message_to_send); + g_free(message_dup); } -- cgit