How to use the m.room.canonical_alias function in m

To help you get started, we’ve selected a few m examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github matrix-construct / construct / share / webapp / js / rooms.js View on Github external
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
	{
github matrix-construct / construct / modules / static / charybdis / rooms / info.js View on Github external
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
	{
github turt2live / matrix-voyager-bot / src / MatrixHandler.js View on Github external
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];
            }
        }
github matrix-construct / construct / share / webapp / js / room / state.js View on Github external
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,
	};
};