From c2de4bfd85bd2c9bdb465cf2ab1a8b5c0ebb2cd4 Mon Sep 17 00:00:00 2001 From: Adrian Perez de Castro Date: Sat, 9 Jul 2016 00:30:59 +0300 Subject: [PATCH] Add method room:get_alias_or_id() This new methods returns the most adequate identifier for a room: 1. If defined, the room's canonical alias. 2. Otherwise, the first alias. 3. As a last resort, the room identifier is returned. --- matrix/client.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/matrix/client.lua b/matrix/client.lua index 0c8ae0c..1e5b9da 100644 --- a/matrix/client.lua +++ b/matrix/client.lua @@ -207,6 +207,16 @@ function Room:update_aliases() return false end +function Room:get_alias_or_id() + if self.canonical_alias then + return self.canonical_alias + elseif #self.aliases > 0 then + return self.aliases[1] + else + return self.room_id + end +end + local make_unimplemented_handler = function (self, event) local env_value = os.getenv("MATRIX_CLIENT_LOG_UNHANDLED_EVENTS") if env_value and #env_value > 0 and env_value ~= "0" then