diff --git a/src/matrix-handles.c b/src/matrix-handles.c index 7bb2b4d..e703e6c 100644 --- a/src/matrix-handles.c +++ b/src/matrix-handles.c @@ -18,6 +18,8 @@ #include "matrix-handles.h" +#include + #define MATRIX_DEBUG_FLAG MATRIX_DEBUG_PARSER #include "matrix-debug.h" @@ -40,3 +42,20 @@ matrix_id_is_valid(const gchar *matrix_id, gboolean strict_mode) return TRUE; } + +gchar * +matrix_normalize_id(const gchar *id, GError **err) +{ + if (!matrix_id_is_valid(id, FALSE)) { + g_set_error(err, + TP_ERROR, TP_ERROR_INVALID_HANDLE, + "Invalid Matrix ID"); + + return NULL; + } + + /* telepathy-idle sets the nickname to lowercase here. I’m not + * sure it can be done with Matrix IDs. TODO: check if it can. + */ + return g_strdup(id); +} diff --git a/src/matrix-handles.h b/src/matrix-handles.h index eda9e5a..aa9bf3a 100644 --- a/src/matrix-handles.h +++ b/src/matrix-handles.h @@ -22,5 +22,6 @@ #include gboolean matrix_id_is_valid(const gchar *matrix_id, gboolean strict_mode); +gchar *matrix_normalize_id(const gchar *id, GError **err); #endif /* __MATRIX_HANDLES_H__ */ diff --git a/src/matrix-protocol.c b/src/matrix-protocol.c index e604daa..2f19905 100644 --- a/src/matrix-protocol.c +++ b/src/matrix-protocol.c @@ -83,6 +83,14 @@ new_connection(TpBaseProtocol *protocol G_GNUC_UNUSED, NULL); } +static gchar * +normalize_contact(TpBaseProtocol *protocol G_GNUC_UNUSED, + const gchar *contact, + GError **err) +{ + return matrix_normalize_id(contact, err); +} + static void matrix_protocol_class_init(MatrixProtocolClass *klass) { @@ -90,8 +98,8 @@ matrix_protocol_class_init(MatrixProtocolClass *klass) base_class->get_parameters = get_parameters; base_class->new_connection = new_connection; - /* base_class->normalize_contact = normalize_contact; + /* base_class->identify_account = identify_account; base_class->get_interfaces_array = get_interfaces_array; base_class->get_connection_details = get_connection_details;