How to use the m.room.message 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 vector-im / riot-web / src / controllers / molecules / MemberInfo.js View on Github external
var target = this.props.member.userId;
        var self = this;
        var room = MatrixClientPeg.get().getRoom(roomId);
        if (!room) {
            return;
        }
        var powerLevelEvent = room.currentState.getStateEvents(
            "m.room.power_levels", ""
        );
        if (!powerLevelEvent) {
            return;
        }
        var isMuted = this.state.muted;
        var powerLevels = powerLevelEvent.getContent();
        var levelToSend = (
            (powerLevels.events ? powerLevels.events["m.room.message"] : null) ||
            powerLevels.events_default
        );
        var level;
        if (isMuted) { // unmute
            level = levelToSend;
        }
        else { // mute
            level = levelToSend - 1;
        }

        MatrixClientPeg.get().setPowerLevel(roomId, target, level, powerLevelEvent).done(
        function() {
            // NO-OP; rely on the m.room.member event coming down else we could
            // get out of sync if we force setState here!
            console.log("Mute toggle success");
        }, function(err) {
github FabricLabs / fabric / src / components / views / rooms / MemberInfo.js View on Github external
if (target === this.props.matrixClient.getUserId()) {
            try {
                if (!(await this._warnSelfDemote())) return;
            } catch (e) {
                console.error("Failed to warn about self demotion: ", e);
                return;
            }
        }

        const powerLevelEvent = room.currentState.getStateEvents("m.room.power_levels", "");
        if (!powerLevelEvent) return;

        const isMuted = this.state.muted;
        const powerLevels = powerLevelEvent.getContent();
        const levelToSend = (
            (powerLevels.events ? powerLevels.events["m.room.message"] : null) ||
            powerLevels.events_default
        );
        let level;
        if (isMuted) { // unmute
            level = levelToSend;
        } else { // mute
            level = levelToSend - 1;
        }
        level = parseInt(level);

        if (!isNaN(level)) {
            this.setState({ updating: this.state.updating + 1 });
            this.props.matrixClient.setPowerLevel(roomId, target, level, powerLevelEvent).then(
                function() {
                    // NO-OP; rely on the m.room.member event coming down else we could
                    // get out of sync if we force setState here!
github matrix-org / matrix-js-sdk / src / models / event-timeline-set.js View on Github external
EventTimelineSet.prototype.setRelationsTarget = function(event) {
    if (!this._unstableClientRelationAggregation) {
        return;
    }

    const relationsForEvent = this._relations[event.getId()];
    if (!relationsForEvent) {
        return;
    }
    // don't need it for non m.replace relations for now
    const relationsWithRelType = relationsForEvent["m.replace"];
    if (!relationsWithRelType) {
        return;
    }
    // only doing replacements for messages for now (e.g. edits)
    const relationsWithEventType = relationsWithRelType["m.room.message"];

    if (relationsWithEventType) {
        relationsWithEventType.setTargetEvent(event);
    }
};
github mozilla / releases-comm-central / chat / protocols / matrix / lib / matrix-sdk / models / event-timeline-set.js View on Github external
EventTimelineSet.prototype.setRelationsTarget = function (event) {
    if (!this._unstableClientRelationAggregation) {
        return;
    }

    const relationsForEvent = this._relations[event.getId()];
    if (!relationsForEvent) {
        return;
    }
    // don't need it for non m.replace relations for now
    const relationsWithRelType = relationsForEvent["m.replace"];
    if (!relationsWithRelType) {
        return;
    }
    // only doing replacements for messages for now (e.g. edits)
    const relationsWithEventType = relationsWithRelType["m.room.message"];

    if (relationsWithEventType) {
        relationsWithEventType.setTargetEvent(event);
    }
};