Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
mc.rooms.info.menu["JOIN"].click = async function($event, room_id)
{
if(!room_id)
room_id = mc.rooms.search.value.split(" ")[0];
if(!(room_id in mc.rooms))
mc.rooms[room_id] = new mc.room({room_id: room_id});
let room = mc.rooms[room_id];
// Try to join room by canon alias first
let alias = room.state['m.room.canonical_alias'].content.alias;
// Fallback to any alias
if(empty(alias)) try
{
let aliases = room.state['m.room.aliases'];
let state_key = Object.keys(aliases)[0];
alias = aliases[state_key].content.aliases[0];
}
catch(e) {}
// Fallback to room id
if(empty(alias))
alias = room_id;
let request = mc.m.join.post(alias); try
{
mc.rooms.info.menu["JOIN"].click = async function($event, room_id)
{
if(!room_id)
room_id = mc.rooms.search.value.split(" ")[0];
if(!(room_id in mc.rooms))
mc.rooms[room_id] = new mc.room({room_id: room_id});
let room = mc.rooms[room_id];
// Try to join room by canon alias first
let alias = room.state['m.room.canonical_alias'].content.alias;
// Fallback to any alias
if(empty(alias)) try
{
let aliases = room.state['m.room.aliases'];
let state_key = Object.keys(aliases)[0];
alias = aliases[state_key].content.aliases[0];
}
catch(e) {}
// Fallback to room id
if(empty(alias))
alias = room_id;
let request = mc.m.join.post(alias); try
{
getRoomAlias(roomId) {
var room = this._client.getRoom(roomId);
if (!room)return roomId;
var canonicalAliasEvent = room.currentState.events['m.room.canonical_alias'];
if (canonicalAliasEvent) {
var alias = canonicalAliasEvent[''].event.content.alias;
if (alias) return alias;
}
var aliasEvent = room.currentState.events['m.room.aliases'];
if (!aliasEvent) return roomId;
for (var domain in aliasEvent) {
var domainEvent = aliasEvent[domain];
var aliases = domainEvent.event.content.aliases;
if (aliases && aliases.length > 0) {
return aliases[0];
}
}
room.state.summary = function(state)
{
let members = state['m.room.member'];
let is_join = (mxid) => maybe(() => members[mxid].content.membership == "join");
let aliases = [];
Object.each(state['m.room.aliases'], (state_key, event) =>
{
aliases = aliases.concat(event.content.aliases);
});
return {
room_id: state['m.room.create'][''].room_id,
name: state['m.room.name'][''].content.name,
topic: state['m.room.topic'][''].content.topic,
canonical_alias: state['m.room.canonical_alias'][''].content.alias,
world_readable: state['m.room.history_visibility'][''].content.history_visibility == "world_readable",
guest_can_join: state['m.room.guest_access'][''].content.guest_access == "can_join",
num_joined_members: Array.count(Object.keys(members), is_join),
aliases: aliases,
};
};