Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set custom power_levels on room creation #503

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions config.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ ircService:
modePowerMap:
o: 50

# A map of levels needed to do some action on the Matrix room. Those levels will be set
# on the room on creation. With corresponding modePowerMap, this allows Matrix users who
# are ops on the IRC side to edit the room settings.
powerLevels:
avatar: 50
name: 50
canonicalAlias: 50
historyVisibility: 50
redact: 50

botConfig:
# Enable the presence of the bot in IRC channels. The bot serves as the entity
# which maps from IRC -> Matrix. You can disable the bot entirely which
Expand Down
10 changes: 8 additions & 2 deletions lib/bridge/IrcHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,10 @@ IrcHandler.prototype.onInvite = Promise.coroutine(function*(req, server, fromUse

if (matrixRooms.length === 0) {
let ircRoom = yield this.ircBridge.trackChannel(server, channel, null);
let response = yield this.ircBridge.getAppServiceBridge().getIntent(
let userIntent = this.ircBridge.getAppServiceBridge().getIntent(
virtualMatrixUser.getId()
).createRoom({
);
let response = yield userIntent.createRoom({
options: {
room_alias_name: roomAlias.split(":")[0].substring(1), // localpart
name: channel,
Expand All @@ -303,6 +304,11 @@ IrcHandler.prototype.onInvite = Promise.coroutine(function*(req, server, fromUse
content: {
history_visibility: "joined"
}
},
{
type: "m.room.power_levels",
state_key: "",
content: ircServer.getPowerLevels(userIntent.getClient().credentials.userId)
}
]
}
Expand Down
19 changes: 16 additions & 3 deletions lib/bridge/MatrixHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,8 @@ MatrixHandler.prototype._onAdminMessage = Promise.coroutine(function*(req, event
// track the channel then invite them.
// TODO: Dupes onAliasQuery a lot
let ircRoom = yield this.ircBridge.trackChannel(ircServer, ircChannel, key);
let response = yield this.ircBridge.getAppServiceBridge().getIntent(
event.user_id
).createRoom({
let userIntent = this.ircBridge.getAppServiceBridge().getIntent(event.user_id);
let response = yield userIntent.createRoom({
options: {
name: ircChannel,
visibility: "private",
Expand All @@ -416,6 +415,13 @@ MatrixHandler.prototype._onAdminMessage = Promise.coroutine(function*(req, event
content: {
history_visibility: "joined"
}
},
{
type: "m.room.power_levels",
state_key: "",
content: ircServer.getPowerLevels(
userIntent.getClient().credentials.userId
)
}
]
}
Expand Down Expand Up @@ -1353,6 +1359,13 @@ MatrixHandler.prototype._onAliasQuery = Promise.coroutine(function*(req, roomAli
content: {
history_visibility: "joined"
}
},
{
type: "m.room.power_levels",
state_key: "",
content: channelInfo.server.getPowerLevels(
botIntent.getClient().credentials.userIdl
)
}
]
}
Expand Down
13 changes: 13 additions & 0 deletions lib/config/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@ properties:
"^[a-zA-Z]$":
type: number
minimum: 0
powerLevels:
type: "object"
properties:
avatar:
type: "number"
name:
type: "number"
canonical_alias:
type: "number"
history_visibility:
type: "number"
redact:
type: "number"
botConfig:
type: "object"
properties:
Expand Down
24 changes: 24 additions & 0 deletions lib/irc/IrcServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,30 @@ IrcServer.prototype.getModePowerMap = function() {
return this.config.modePowerMap || {};
}

/**
* Get a map of power levels to set.
* @param {string} userId : The room creator user ID.
* @return {Object}
*/
IrcServer.prototype.getPowerLevels = function(userId) {
var powerLevels = this.config.powerLevels || {};
var content = {
redact: powerLevels.redact || 50,
events_default: 0,
state_default: 50,
events: {
"m.room.avatar": powerLevels.avatar || 50,
"m.room.name": powerLevels.name || 50,
"m.room.canonical_alias": powerLevels.canonicalAlias || 50,
"m.room.history_visibility": powerLevels.historyVisibility || 100,
"m.room.power_levels": 100
},
users: {}
}
content["users"][userId] = 100;
return content;
}

IrcServer.prototype.getHardCodedRoomIds = function() {
var roomIds = new Set();
var channels = Object.keys(this.config.mappings);
Expand Down