diff options
author | Richard van der Hoff <richard@matrix.org> | 2015-11-02 18:03:09 +0000 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2015-11-02 18:03:09 +0000 |
commit | 8efee869304ed95823767363df39a5617e38ce7c (patch) | |
tree | 03a802fd6a89e035632ec2e36817d33744c05bdf | |
parent | e78ea22ac644ecb3bb08ca2059068825fc77324c (diff) | |
download | purple-matrix-8efee869304ed95823767363df39a5617e38ce7c.tar.gz |
Implement get_cb_real_name
Fixing this means purple is slightly less confused about who the users in our
chats are.
-rw-r--r-- | libmatrix.c | 20 | ||||
-rw-r--r-- | matrix-room.c | 9 | ||||
-rw-r--r-- | matrix-room.h | 10 | ||||
-rw-r--r-- | matrix-roommembers.c | 24 | ||||
-rw-r--r-- | matrix-roommembers.h | 10 |
5 files changed, 72 insertions, 1 deletions
diff --git a/libmatrix.c b/libmatrix.c index 49cee43..e74c317 100644 --- a/libmatrix.c +++ b/libmatrix.c @@ -199,6 +199,24 @@ static int matrixprpl_chat_send(PurpleConnection *gc, int id, } +/** + * Get the user_id of a user, given their displayname in a room + * + * @returns a string, which will be freed by the caller + */ +static char *matrixprpl_get_cb_real_name(PurpleConnection *gc, int id, + const char *who) +{ + PurpleConversation *conv = purple_find_chat(gc, id); + gchar *res; + if(conv == NULL) + return NULL; + res = matrix_room_displayname_to_userid(conv, who); + purple_debug_info("matrixprpl", "%s's real id in %s is %s\n", who, + conv->name, res); + return res; +} + /****************************************************************************** * The following comes from the 'nullprpl' dummy protocol. TODO: clear this out @@ -993,7 +1011,7 @@ static PurplePluginProtocolInfo prpl_info = matrixprpl_normalize, /* normalize */ matrixprpl_set_buddy_icon, /* set_buddy_icon */ matrixprpl_remove_group, /* remove_group */ - NULL, /* get_cb_real_name */ + matrixprpl_get_cb_real_name, /* get_cb_real_name */ matrixprpl_set_chat_topic, /* set_chat_topic */ NULL, /* find_blist_chat */ matrixprpl_roomlist_get_list, /* roomlist_get_list */ diff --git a/matrix-room.c b/matrix-room.c index d53b6e4..845d481 100644 --- a/matrix-room.c +++ b/matrix-room.c @@ -608,3 +608,12 @@ void matrix_room_send_message(PurpleConversation *conv, const gchar *message) purple_conv_chat_write(chat, _get_my_display_name(conv), message, PURPLE_MESSAGE_SEND, g_get_real_time()/1000/1000); } + + +gchar *matrix_room_displayname_to_userid(struct _PurpleConversation *conv, + const gchar *who) +{ + MatrixRoomMemberTable *member_table = + matrix_room_get_member_table(conv); + return matrix_roommembers_displayname_to_userid(member_table, who); +} diff --git a/matrix-room.h b/matrix-room.h index 90978d1..911b1af 100644 --- a/matrix-room.h +++ b/matrix-room.h @@ -82,4 +82,14 @@ void matrix_room_handle_timeline_event(struct _PurpleConversation *conv, void matrix_room_send_message(struct _PurpleConversation *conv, const gchar *message); + +/** + * Get the userid of a member of a room, given their displayname + * + * @returns a string, which will be freed by the caller + */ +gchar *matrix_room_displayname_to_userid(struct _PurpleConversation *conv, + const gchar *who); + + #endif diff --git a/matrix-roommembers.c b/matrix-roommembers.c index a437796..cfe36a0 100644 --- a/matrix-roommembers.c +++ b/matrix-roommembers.c @@ -314,3 +314,27 @@ GList *matrix_roommembers_get_active_members( } return members; } + + +/** + * Get the userid of a member of a room, given their displayname + * + * @returns a string, which will be freed by the caller, or null if not known + */ +gchar *matrix_roommembers_displayname_to_userid( + MatrixRoomMemberTable *table, const gchar *who) +{ + /* TODO: make this more efficient */ + GHashTableIter iter; + gpointer key, value; + g_hash_table_iter_init (&iter, table->hash_table); + while (g_hash_table_iter_next (&iter, &key, &value)) { + const gchar *user_id = key; + MatrixRoomMember *member = value; + if(member->current_displayname != NULL + && strcmp(who, member->current_displayname) == 0) { + return g_strdup(user_id); + } + } + return NULL; +} diff --git a/matrix-roommembers.h b/matrix-roommembers.h index e00cc70..2ae5538 100644 --- a/matrix-roommembers.h +++ b/matrix-roommembers.h @@ -107,4 +107,14 @@ void matrix_roommembers_get_renamed_members(MatrixRoomMemberTable *table, void matrix_roommembers_get_left_members(MatrixRoomMemberTable *table, GList **names); + +/** + * Get the userid of a member of a room, given their displayname + * + * @returns a string, which will be freed by the caller, or null if not known + */ +gchar *matrix_roommembers_displayname_to_userid( + MatrixRoomMemberTable *table, const gchar *who); + + #endif /* MATRIX_ROOMMEMBERS_H_ */ |