How to use the m.room.aliases 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 / modules / static / charybdis / rooms / info.js View on Github external
{
	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
	{
		let data = await request.response;
		mc.rooms.joined[room_id] = room;
		debug.object(data);
		return true;
	}
github matrix-construct / construct / share / webapp / js / rooms.js View on Github external
{
	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
	{
		let data = await request.response;
		mc.rooms.join[room_id] = room;
		debug.object(data);
		return true;
	}
github turt2live / matrix-voyager-bot / src / MatrixHandler.js View on Github external
return new Promise((resolve, reject) => {
            if (itemId[0] == '#' || itemId[0] == '!') {
                var room = this._client.getRoom(itemId);
                if (!room) {
                    var rooms = this._client.getRooms();
                    for (var knownRoom of rooms) {
                        var aliasEvent = knownRoom.currentState.events['m.room.aliases'];
                        if (aliasEvent) {
                            for (var domain in aliasEvent) {
                                var domainEvent = aliasEvent[domain];
                                var aliases = domainEvent.event.content.aliases;
                                if (aliases && aliases.indexOf(itemId) !== -1) {
                                    room = knownRoom;
                                    break;
                                }
                            }
                            if (room)break;
                        }
                    }

                    if (!room)
                        reject();
                }
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,
	};
};
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];
            }
        }

        return roomId;
    }
github matrix-construct / construct / share / webapp / js / room / misc.js View on Github external
room.prototype.realias = function($event, server, index)
{
	let event = this.state['m.room.aliases'][server];
	let pending = this.pending['m.room.aliases'][server];
	let alias = pending.content.aliases[index];
	delete pending.content.aliases;

	if(alias.length)
	{
		if(!alias.startsWith("#"))
			alias = "#" + alias;

		if(!client.m.domid(alias))
			alias += ":" + client.my.domain;

		pending.content.aliases = [alias,];
	}

	if(event.content !== undefined && event.content.aliases !== undefined)
		for(let i = 0; i < event.content.aliases.length; i++)
github matrix-construct / construct / share / webapp / js / room / misc.js View on Github external
room.prototype.realias = function($event, server, index)
{
	let event = this.state['m.room.aliases'][server];
	let pending = this.pending['m.room.aliases'][server];
	let alias = pending.content.aliases[index];
	delete pending.content.aliases;

	if(alias.length)
	{
		if(!alias.startsWith("#"))
			alias = "#" + alias;

		if(!client.m.domid(alias))
			alias += ":" + client.my.domain;

		pending.content.aliases = [alias,];
	}

	if(event.content !== undefined && event.content.aliases !== undefined)