diff options
author | Dr. David Alan Gilbert <dave@treblig.org> | 2017-05-27 02:31:43 +0100 |
---|---|---|
committer | Dr. David Alan Gilbert <dave@treblig.org> | 2018-02-25 02:08:49 +0000 |
commit | 8e49e86f59739d6e9dae3072864736553f78b466 (patch) | |
tree | 0bfa200e94be42a38b1b1b08fde5ae387e5c9ed2 | |
parent | c155422e38306631c04dad430486b8a868af1921 (diff) | |
download | purple-matrix-8e49e86f59739d6e9dae3072864736553f78b466.tar.gz |
e2e: Add device info action
Add a purple action (i.e. thing on the accounts->matrix-> menu)
to display the device ID and public key.
Signed-off-by: Dr. David Alan Gilbert <dave@treblig.org>
-rw-r--r-- | libmatrix.c | 11 | ||||
-rw-r--r-- | matrix-e2e.c | 31 | ||||
-rw-r--r-- | matrix-e2e.h | 1 |
3 files changed, 42 insertions, 1 deletions
diff --git a/libmatrix.c b/libmatrix.c index e0a1e64..5b2d4ae 100644 --- a/libmatrix.c +++ b/libmatrix.c @@ -35,6 +35,7 @@ #include "version.h" #include "matrix-connection.h" +#include "matrix-e2e.h" #include "matrix-room.h" #include "matrix-api.h" @@ -378,6 +379,14 @@ static void matrixprpl_destroy(PurplePlugin *plugin) { purple_debug_info("matrixprpl", "shutting down\n"); } +static GList *matrixprpl_actions(PurplePlugin *plugin, gpointer context) +{ + GList *list = NULL; + + list = matrix_e2e_actions(list); + + return list; +} static PurplePluginInfo info = { @@ -402,7 +411,7 @@ static PurplePluginInfo info = NULL, /* ui_info */ &prpl_info, /* extra_info */ NULL, /* prefs_info */ - NULL, /* actions */ + matrixprpl_actions, /* actions */ NULL, /* padding... */ NULL, NULL, diff --git a/matrix-e2e.c b/matrix-e2e.c index 7337f2e..9c16a5f 100644 --- a/matrix-e2e.c +++ b/matrix-e2e.c @@ -1704,6 +1704,32 @@ out: return plaintext_parser; } +static void action_device_info(PurplePluginAction *action) +{ + PurpleConnection *pc = (PurpleConnection *) action->context; + + if (!pc) return; + MatrixConnectionData *conn = purple_connection_get_protocol_data(pc); + if (!conn || !conn->e2e) return; + char *title = g_strdup_printf("Device info for %s", conn->user_id); + char *body = g_strdup_printf("Device ID: %s" + "<br>Device Key: %s", + conn->e2e->device_id, + conn->e2e->ed25519_pubkey); + purple_notify_formatted(pc, title, title, NULL, body, NULL, NULL); + g_free(title); + g_free(body); +} + +/* Hook for adding purple 'action' menu items */ +GList *matrix_e2e_actions(GList *list) +{ + list = g_list_append(list, + purple_plugin_action_new(_("Device info"), + action_device_info)); + return list; +} + #else /* ==== Stubs for when e2e is configured out of the build === */ void matrix_e2e_decrypt_d2d(PurpleConnection *pc, JsonObject *cevent) @@ -1734,4 +1760,9 @@ void matrix_e2e_cleanup_conversation(PurpleConversation *conv) { } +GList *matrix_e2e_actions(GList *list) +{ + return list; +} + #endif diff --git a/matrix-e2e.h b/matrix-e2e.h index 3aaab9b..b1282a2 100644 --- a/matrix-e2e.h +++ b/matrix-e2e.h @@ -25,6 +25,7 @@ typedef struct _MatrixE2EData MatrixE2EData; typedef struct _PurpleConversation PurpleConversation; +GList *matrix_e2e_actions(GList *list); int matrix_e2e_get_device_keys(MatrixConnectionData *conn, const gchar *device_id); void matrix_e2e_cleanup_connection(MatrixConnectionData *conn); void matrix_e2e_cleanup_conversation(PurpleConversation *conv); |