How to use the matrix-js-sdk.RoomMember function in matrix-js-sdk

To help you get started, we’ve selected a few matrix-js-sdk 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 FabricLabs / fabric / src / components / views / elements / Pill.js View on Github external
'+': Pill.TYPE_GROUP_MENTION,
        }[prefix];

        let member;
        let group;
        let room;
        switch (pillType) {
            case Pill.TYPE_AT_ROOM_MENTION: {
                room = nextProps.room;
            }
                break;
            case Pill.TYPE_USER_MENTION: {
                const localMember = nextProps.room.getMember(resourceId);
                member = localMember;
                if (!localMember) {
                    member = new RoomMember(null, resourceId);
                    this.doProfileLookup(resourceId, member);
                }
            }
                break;
            case Pill.TYPE_ROOM_MENTION: {
                const localRoom = resourceId[0] === '#' ?
                    MatrixClientPeg.get().getRooms().find((r) => {
                        return r.getAliases().includes(resourceId);
                    }) : MatrixClientPeg.get().getRoom(resourceId);
                room = localRoom;
                if (!localRoom) {
                    // TODO: This would require a new API to resolve a room alias to
                    // a room avatar and name.
                    // this.doRoomProfileLookup(resourceId, member);
                }
            }
github matrix-org / matrix-appservice-bridge / lib / components / intent.js View on Github external
room_id: roomId,
            user_id: "",
            event_id: "_",
            state_key: "",
            type: "m.room.power_levels"
        }
        var powerLevelEvent = new MatrixEvent(event);
        // What level do we need for this event type?
        var defaultLevel = event.content.events_default;
        if (STATE_EVENT_TYPES.indexOf(eventType) !== -1) {
            defaultLevel = event.content.state_default;
        }
        var requiredLevel = event.content.events[eventType] || defaultLevel;

        // Parse out what level the client has by abusing the JS SDK
        var roomMember = new RoomMember(roomId, userId);
        roomMember.setPowerLevelEvent(powerLevelEvent);

        if (requiredLevel > roomMember.powerLevel) {
            // can the bot update our power level?
            var bot = new RoomMember(roomId, self.botClient.credentials.userId);
            bot.setPowerLevelEvent(powerLevelEvent);
            var levelRequiredToModifyPowerLevels = event.content.events[
                "m.room.power_levels"
            ] || event.content.state_default;
            if (levelRequiredToModifyPowerLevels > bot.powerLevel) {
                // even the bot has no power here.. give up.
                throw new Error(
                    "Cannot ensure client has power level for event " + eventType +
                    " : client has " + roomMember.powerLevel + " and we require " +
                    requiredLevel + " and the bot doesn't have permission to " +
                    "edit the client's power level."
github matrix-org / matrix-appservice-bridge / lib / components / intent.js View on Github external
}
        var powerLevelEvent = new MatrixEvent(event);
        // What level do we need for this event type?
        var defaultLevel = event.content.events_default;
        if (STATE_EVENT_TYPES.indexOf(eventType) !== -1) {
            defaultLevel = event.content.state_default;
        }
        var requiredLevel = event.content.events[eventType] || defaultLevel;

        // Parse out what level the client has by abusing the JS SDK
        var roomMember = new RoomMember(roomId, userId);
        roomMember.setPowerLevelEvent(powerLevelEvent);

        if (requiredLevel > roomMember.powerLevel) {
            // can the bot update our power level?
            var bot = new RoomMember(roomId, self.botClient.credentials.userId);
            bot.setPowerLevelEvent(powerLevelEvent);
            var levelRequiredToModifyPowerLevels = event.content.events[
                "m.room.power_levels"
            ] || event.content.state_default;
            if (levelRequiredToModifyPowerLevels > bot.powerLevel) {
                // even the bot has no power here.. give up.
                throw new Error(
                    "Cannot ensure client has power level for event " + eventType +
                    " : client has " + roomMember.powerLevel + " and we require " +
                    requiredLevel + " and the bot doesn't have permission to " +
                    "edit the client's power level."
                );
            }
            // update the client's power level first
            return self.botClient.setPowerLevel(
                roomId, userId, requiredLevel, powerLevelEvent
github FabricLabs / fabric / src / components / structures / UserView.js View on Github external
const cli = MatrixClientPeg.get();
        this.setState({loading: true});
        let profileInfo;
        try {
            profileInfo = await cli.getProfileInfo(this.props.userId);
        } catch (err) {
            const ErrorDialog = sdk.getComponent('dialogs.ErrorDialog');
            Modal.createTrackedDialog(_t('Could not load user profile'), '', ErrorDialog, {
                title: _t('Could not load user profile'),
                description: ((err && err.message) ? err.message : _t("Operation failed")),
            });
            this.setState({loading: false});
            return;
        }
        const fakeEvent = new Matrix.MatrixEvent({type: "m.room.member", content: profileInfo});
        const member = new Matrix.RoomMember(null, this.props.userId);
        member.setMembershipEvent(fakeEvent);
        this.setState({member, loading: false});
    }
github FabricLabs / fabric / src / components / structures / MatrixChat.js View on Github external
onUserClick: function(event, userId) {
        event.preventDefault();

        const member = new Matrix.RoomMember(null, userId);
        if (!member) { return; }
        dis.dispatch({
            action: 'view_user',
            member: member,
        });
    },
github vector-im / riot-web / src / skins / vector / views / pages / MatrixChat.js View on Github external
onUserClick: function(event, userId) {
        event.preventDefault();
        var MemberInfo = sdk.getComponent('rooms.MemberInfo');
        var member = new Matrix.RoomMember(null, userId);
        ContextualMenu.createMenu(MemberInfo, {
            member: member,
            right: window.innerWidth - event.pageX,
            top: event.pageY
        });
    },
github vector-im / riot-web / src / components / structures / RightPanel.js View on Github external
getInitialState: function() {
        if (this.props.userId) {
            var member = new Matrix.RoomMember(null, this.props.userId);
            return {
                phase: this.Phase.MemberInfo,
                member: member,
            }
        }
        else {
            return {
                phase: this.Phase.MemberList
            }
        }
    },
github FabricLabs / fabric / src / components / structures / MatrixChat.js View on Github external
waitFor.then(() => {
                if (params.action === 'chat') {
                    this._chatCreateOrReuse(userId);
                    return;
                }

                this._setPage(PageTypes.UserView);
                this.notifyNewScreen('user/' + userId);
                const member = new Matrix.RoomMember(null, userId);
                dis.dispatch({
                    action: 'view_user',
                    member: member,
                });
            });
        } else if (screen.indexOf('group/') == 0) {