This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 832
Scalar Messaging: Expose join_rules and restrict to currently viewed room #443
Merged
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
54f21c9
Expose join rules of a room
1c29c95
Only current room works with postMessage
efccdab
Better error message for room not viewed
310e660
Fix ref to dispatcher
fa3387b
Code review
cb4df84
Missing curly bracket
3977ea0
Add ability to set power level
4bfa57b
Getting join rules does not need user ID
31d2a81
Get power levels before setting them
ce68a5b
clean up
f605b17
Better log
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,7 @@ Example: | |
|
||
const SdkConfig = require('./SdkConfig'); | ||
const MatrixClientPeg = require("./MatrixClientPeg"); | ||
var dis = require("./dispatcher"); | ||
|
||
function sendResponse(event, res) { | ||
const data = JSON.parse(JSON.stringify(event.data)); | ||
|
@@ -193,12 +194,16 @@ function getMembershipState(event, roomId, userId) { | |
returnStateEvent(event, roomId, "m.room.member", userId); | ||
} | ||
|
||
function getJoinRules(event, roomId) { | ||
console.log(`join_rules of ${roomId} requested.`); | ||
returnStateEvent(event, roomId, "m.room.join_rules"); | ||
} | ||
|
||
function botOptions(event, roomId, userId) { | ||
console.log(`bot_options of ${userId} in room ${roomId} requested.`); | ||
returnStateEvent(event, roomId, "m.room.bot.options", "_" + userId); | ||
} | ||
|
||
|
||
function returnStateEvent(event, roomId, eventType, stateKey) { | ||
const client = MatrixClientPeg.get(); | ||
if (!client) { | ||
|
@@ -218,6 +223,18 @@ function returnStateEvent(event, roomId, eventType, stateKey) { | |
sendResponse(event, stateEvent.getContent()); | ||
} | ||
|
||
var currentRoomId = null; | ||
|
||
// Listen for when a room is viewed | ||
dis.register(onAction); | ||
function onAction(payload) { | ||
switch (payload.action) { | ||
case 'view_room': | ||
currentRoomId = payload.room_id; | ||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would just do: function onAction(payload) {
if (payload.action !== "view_room") {
return;
}
currentRoomId = payload.room_id;
} We don't expect to add more listeners so the |
||
} | ||
} | ||
|
||
const onMessage = function(event) { | ||
if (!event.origin) { // stupid chrome | ||
event.origin = event.originalEvent.origin; | ||
|
@@ -243,6 +260,15 @@ const onMessage = function(event) { | |
sendError(event, "Missing room_id in request"); | ||
return; | ||
} | ||
if (!currentRoomId) { | ||
sendError(event, "Must be viewing a room"); | ||
return; | ||
} | ||
if (roomId !== currentRoomId) { | ||
sendError(event, "Room " + roomId + " not in view"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/not in view/not visible/ |
||
return; | ||
} | ||
|
||
switch (event.data.action) { | ||
case "membership_state": | ||
getMembershipState(event, roomId, userId); | ||
|
@@ -256,6 +282,9 @@ const onMessage = function(event) { | |
case "set_bot_options": | ||
setBotOptions(event, roomId, userId); | ||
break; | ||
case "join_rules_state": | ||
getJoinRules(event, roomId); | ||
break; | ||
default: | ||
console.warn("Unhandled postMessage event with action '" + event.data.action +"'"); | ||
break; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a
state_key
of""
: