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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user