From 0422c4717819e7a1e51be33e64a174adbb1aa119 Mon Sep 17 00:00:00 2001 From: Adrian Perez de Castro Date: Sun, 10 Jul 2016 01:45:49 +0300 Subject: [PATCH] Make room:get_alias_or_id() return the shortest alias This makes the room:get_alias_or_id() method return the shortest of the room aliases in case that a canonical_alias is not set. In general this will save screen real estate when a client uses the method to get a readable room identifier to display to the user. --- matrix/client.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/matrix/client.lua b/matrix/client.lua index 1e5b9da..268b16d 100644 --- a/matrix/client.lua +++ b/matrix/client.lua @@ -210,8 +210,16 @@ end function Room:get_alias_or_id() if self.canonical_alias then return self.canonical_alias - elseif #self.aliases > 0 then + elseif #self.aliases == 1 then return self.aliases[1] + elseif #self.aliases > 1 then + local shorter_index = 1 + for index, alias in ipairs(self.aliases) do + if #alias < #self.aliases[shorter_index] then + shorter_index = index + end + end + return self.aliases[shorter_index] else return self.room_id end