You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-05 00:42:10 +03:00
Revert "Revert "Don't rely on members to query if syncing user can post to room""
This commit is contained in:
27
CHANGELOG.md
27
CHANGELOG.md
@@ -1,3 +1,17 @@
|
|||||||
|
Changes in [0.11.0](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v0.11.0) (TDB)
|
||||||
|
==================================================================================================
|
||||||
|
[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v0.10.9...v0.11.0)
|
||||||
|
|
||||||
|
* Support for lazy loading members. This should improve performance for
|
||||||
|
users who joined big rooms a lot. Pass to `lazyLoadMembers = true` option when calling `startClient`.
|
||||||
|
|
||||||
|
BREAKING CHANGES
|
||||||
|
----------------
|
||||||
|
|
||||||
|
* `MatrixClient::startClient` now returns a Promise. No method should be called on the client before that promise resolves. Before this method didn't return anything.
|
||||||
|
* A new `CATCHUP` sync state, emitted by `MatrixClient#"sync"` and returned by `MatrixClient::getSyncState()`, when doing initial sync after the `ERROR` state. See `MatrixClient` documentation for details.
|
||||||
|
* `RoomState::maySendEvent('m.room.message', userId)` & `RoomState::maySendMessage(userId)` do not check the membership of the user anymore, only the power level. To check if the syncing user is allowed to write in a room, use `Room::maySendMessage()` as `RoomState` is not always aware of the syncing user's membership anymore, in case lazy loading of members is enabled.
|
||||||
|
|
||||||
Changes in [0.10.9](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v0.10.9) (2018-09-03)
|
Changes in [0.10.9](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v0.10.9) (2018-09-03)
|
||||||
==================================================================================================
|
==================================================================================================
|
||||||
[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v0.10.9-rc.2...v0.10.9)
|
[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v0.10.9-rc.2...v0.10.9)
|
||||||
@@ -36,19 +50,6 @@ Changes in [0.10.9-rc.1](https://github.com/matrix-org/matrix-js-sdk/releases/ta
|
|||||||
* Lazy loading of room members
|
* Lazy loading of room members
|
||||||
[\#691](https://github.com/matrix-org/matrix-js-sdk/pull/691)
|
[\#691](https://github.com/matrix-org/matrix-js-sdk/pull/691)
|
||||||
|
|
||||||
BREAKING CHANGE
|
|
||||||
---------------
|
|
||||||
|
|
||||||
* `MatrixClient::startClient` now returns a Promise. No method should be called on the client before that promise resolves. Before this method didn't return anything.
|
|
||||||
* A new `CATCHUP` sync state, emitted by `MatrixClient#"sync"` and returned by `MatrixClient::getSyncState()`, when doing initial sync after the `ERROR` state. See `MatrixClient` documentation for details.
|
|
||||||
|
|
||||||
Changes in [0.11.0](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v0.11.0) (TDB)
|
|
||||||
==================================================================================================
|
|
||||||
[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v0.10.6...v0.11.0)
|
|
||||||
|
|
||||||
* Support for lazy loading members. This should improve performance for
|
|
||||||
users who joined big rooms a lot. Pass to `lazyLoadMembers = true` option when calling `startClient`.
|
|
||||||
|
|
||||||
Changes in [0.10.8](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v0.10.8) (2018-08-20)
|
Changes in [0.10.8](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v0.10.8) (2018-08-20)
|
||||||
==================================================================================================
|
==================================================================================================
|
||||||
[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v0.10.8-rc.1...v0.10.8)
|
[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v0.10.8-rc.1...v0.10.8)
|
||||||
|
@@ -447,13 +447,6 @@ describe("RoomState", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("maySendStateEvent", function() {
|
describe("maySendStateEvent", function() {
|
||||||
it("should say non-joined members may not send state",
|
|
||||||
function() {
|
|
||||||
expect(state.maySendStateEvent(
|
|
||||||
'm.room.name', "@nobody:nowhere",
|
|
||||||
)).toEqual(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should say any member may send state with no power level event",
|
it("should say any member may send state with no power level event",
|
||||||
function() {
|
function() {
|
||||||
expect(state.maySendStateEvent('m.room.name', userA)).toEqual(true);
|
expect(state.maySendStateEvent('m.room.name', userA)).toEqual(true);
|
||||||
@@ -640,14 +633,6 @@ describe("RoomState", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("maySendEvent", function() {
|
describe("maySendEvent", function() {
|
||||||
it("should say non-joined members may not send events",
|
|
||||||
function() {
|
|
||||||
expect(state.maySendEvent(
|
|
||||||
'm.room.message', "@nobody:nowhere",
|
|
||||||
)).toEqual(false);
|
|
||||||
expect(state.maySendMessage("@nobody:nowhere")).toEqual(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should say any member may send events with no power level event",
|
it("should say any member may send events with no power level event",
|
||||||
function() {
|
function() {
|
||||||
expect(state.maySendEvent('m.room.message', userA)).toEqual(true);
|
expect(state.maySendEvent('m.room.message', userA)).toEqual(true);
|
||||||
|
@@ -1400,7 +1400,7 @@ describe("Room", function() {
|
|||||||
|
|
||||||
describe("getMyMembership", function() {
|
describe("getMyMembership", function() {
|
||||||
it("should return synced membership if membership isn't available yet",
|
it("should return synced membership if membership isn't available yet",
|
||||||
async function() {
|
function() {
|
||||||
const room = new Room(roomId, null, userA);
|
const room = new Room(roomId, null, userA);
|
||||||
room.setSyncedMembership("invite");
|
room.setSyncedMembership("invite");
|
||||||
expect(room.getMyMembership()).toEqual("invite");
|
expect(room.getMyMembership()).toEqual("invite");
|
||||||
@@ -1434,4 +1434,17 @@ describe("Room", function() {
|
|||||||
expect(room.guessDMUserId()).toEqual(userA);
|
expect(room.guessDMUserId()).toEqual(userA);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("maySendMessage", function() {
|
||||||
|
it("should return false if synced membership not join",
|
||||||
|
function() {
|
||||||
|
const room = new Room(roomId, null, userA);
|
||||||
|
room.setSyncedMembership("invite");
|
||||||
|
expect(room.maySendMessage()).toEqual(false);
|
||||||
|
room.setSyncedMembership("leave");
|
||||||
|
expect(room.maySendMessage()).toEqual(false);
|
||||||
|
room.setSyncedMembership("join");
|
||||||
|
expect(room.maySendMessage()).toEqual(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -667,11 +667,6 @@ RoomState.prototype.maySendStateEvent = function(stateEventType, userId) {
|
|||||||
* according to the room's state.
|
* according to the room's state.
|
||||||
*/
|
*/
|
||||||
RoomState.prototype._maySendEventOfType = function(eventType, userId, state) {
|
RoomState.prototype._maySendEventOfType = function(eventType, userId, state) {
|
||||||
const member = this.getMember(userId);
|
|
||||||
if (!member || member.membership == 'leave') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const power_levels_event = this.getStateEvents('m.room.power_levels', '');
|
const power_levels_event = this.getStateEvents('m.room.power_levels', '');
|
||||||
|
|
||||||
let power_levels;
|
let power_levels;
|
||||||
@@ -679,25 +674,34 @@ RoomState.prototype._maySendEventOfType = function(eventType, userId, state) {
|
|||||||
|
|
||||||
let state_default = 0;
|
let state_default = 0;
|
||||||
let events_default = 0;
|
let events_default = 0;
|
||||||
|
let powerLevel = 0;
|
||||||
if (power_levels_event) {
|
if (power_levels_event) {
|
||||||
power_levels = power_levels_event.getContent();
|
power_levels = power_levels_event.getContent();
|
||||||
events_levels = power_levels.events || {};
|
events_levels = power_levels.events || {};
|
||||||
|
|
||||||
if (utils.isNumber(power_levels.state_default)) {
|
if (Number.isFinite(power_levels.state_default)) {
|
||||||
state_default = power_levels.state_default;
|
state_default = power_levels.state_default;
|
||||||
} else {
|
} else {
|
||||||
state_default = 50;
|
state_default = 50;
|
||||||
}
|
}
|
||||||
if (utils.isNumber(power_levels.events_default)) {
|
|
||||||
|
const userPowerLevel = power_levels.users && power_levels.users[userId];
|
||||||
|
if (Number.isFinite(userPowerLevel)) {
|
||||||
|
powerLevel = userPowerLevel;
|
||||||
|
} else if(Number.isFinite(power_levels.users_default)) {
|
||||||
|
powerLevel = power_levels.users_default;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Number.isFinite(power_levels.events_default)) {
|
||||||
events_default = power_levels.events_default;
|
events_default = power_levels.events_default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let required_level = state ? state_default : events_default;
|
let required_level = state ? state_default : events_default;
|
||||||
if (utils.isNumber(events_levels[eventType])) {
|
if (Number.isFinite(events_levels[eventType])) {
|
||||||
required_level = events_levels[eventType];
|
required_level = events_levels[eventType];
|
||||||
}
|
}
|
||||||
return member.powerLevel >= required_level;
|
return powerLevel >= required_level;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1485,6 +1485,17 @@ Room.prototype.getAccountData = function(type) {
|
|||||||
return this.accountData[type];
|
return this.accountData[type];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns wheter the syncing user has permission to send a message in the room
|
||||||
|
* @return {boolean} true if the user should be permitted to send
|
||||||
|
* message events into the room.
|
||||||
|
*/
|
||||||
|
Room.prototype.maySendMessage = function() {
|
||||||
|
return this.getMyMembership() === 'join' &&
|
||||||
|
this.currentState.maySendEvent('m.room.message', this.myUserId);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is an internal method. Calculates the name of the room from the current
|
* This is an internal method. Calculates the name of the room from the current
|
||||||
* room state.
|
* room state.
|
||||||
|
Reference in New Issue
Block a user