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

Add maySendStateEvent method, ported from react-sdk (but fixed). #94

Merged
merged 4 commits into from
Mar 16, 2016

Conversation

dbkr
Copy link
Member

@dbkr dbkr commented Mar 3, 2016

Plus tests.

@dbkr
Copy link
Member Author

dbkr commented Mar 3, 2016

(Jenkins is broken)

var user_levels = [];
var current_user_level = 0;

var state_default = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this 0, but 50 at line 262? it is odd that the required power level is 50 if there is an m.room.power_levels with no state_default, but 0 if there is no m.room.power_levels at all

(It is also odd that the spec doesn't clarify this)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, so in this case I'd like your opinion on matrix-org/matrix-spec-proposals#286 which is where I'm fixing the spec to document the default levels. I think it's a bug in synapse that the default is 0 with no power levels event, but apparently this is now baked into room history so we have to make the spec fit the bug.

@richvdh
Copy link
Member

richvdh commented Mar 3, 2016

It is not the easiest to follow bit of code, but looks ok to me modulo the above comment

@richvdh
Copy link
Member

richvdh commented Mar 3, 2016

A quick thought: could we make this maySendEvent with a boolean param for stateEvent, since the algorithm is identical modulo a single key lookup?

@dbkr
Copy link
Member Author

dbkr commented Mar 4, 2016

Could do: my plan was probably to make a separate maySendEvent function if necessary and then probably back both functions with the same one internally. Either way it's a backwards compatible change (assuming you'd add the param to the end).

@richvdh
Copy link
Member

richvdh commented Mar 4, 2016

Just trying to fend off having to support three functions in the js-sdk API forever. No strong feelings here though.

* according to the room's state.
*/
RoomState.prototype.maySendStateEvent = function(stateEventType, userId) {
if (!this.getMember(userId)) { return false; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only tests for presence of m.room.member events. This will return a RoomMember with membership = leave if they leave the room.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also help yourself by using RoomMember.powerLevel to get the actual power level of that member, which already takes into account users_default and explicit users entries.

dbkr added a commit that referenced this pull request Mar 16, 2016
Add maySendStateEvent method, ported from react-sdk (but fixed).
@dbkr dbkr merged commit 8e903c0 into develop Mar 16, 2016
@t3chguy t3chguy deleted the dbkr/may_send_state_event branch May 10, 2022 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants