prevent re(d)action in left/kicked room

This commit is contained in:
Bruno Windels 2021-06-24 14:24:22 +02:00
parent 3fa0f234bb
commit 299294daff
3 changed files with 21 additions and 7 deletions

View file

@ -124,6 +124,10 @@ export class BaseMessageTile extends SimpleTile {
react(key, log = null) {
return this.logger.wrapOrRun(log, "react", async log => {
if (!this.canReact) {
log.set("powerlevel_lacking", true);
return;
}
if (this._entry.haveAnnotation(key)) {
log.set("already_reacted", true);
return;
@ -140,6 +144,10 @@ export class BaseMessageTile extends SimpleTile {
redactReaction(key, log = null) {
return this.logger.wrapOrRun(log, "redactReaction", async log => {
if (!this._powerLevels.canRedactFromSender(this._ownMember.userId)) {
log.set("powerlevel_lacking", true);
return;
}
if (!this._entry.haveAnnotation(key)) {
log.set("not_yet_reacted", true);
return;

View file

@ -15,14 +15,15 @@ limitations under the License.
*/
export class PowerLevels {
constructor({powerLevelEvent, createEvent, ownUserId}) {
constructor({powerLevelEvent, createEvent, ownUserId, membership}) {
this._plEvent = powerLevelEvent;
this._createEvent = createEvent;
this._ownUserId = ownUserId;
this._membership = membership;
}
canRedactFromSender(userId) {
if (userId === this._ownUserId) {
if (userId === this._ownUserId && this._membership === "join") {
return true;
} else {
return this.canRedact;
@ -38,6 +39,9 @@ export class PowerLevels {
}
get _myLevel() {
if (this._membership !== "join") {
return Number.MIN_SAFE_INTEGER;
}
return this._getUserLevel(this._ownUserId);
}

View file

@ -66,7 +66,7 @@ export class Timeline {
// as they should only populate once the view subscribes to it
// if they are populated already, the sender profile would be empty
this._powerLevels = await this._loadPowerLevels(txn);
this._powerLevels = await this._loadPowerLevels(membership, txn);
// 30 seems to be a good amount to fill the entire screen
const readerRequest = this._disposables.track(this._timelineReader.readFromEnd(30, txn, log));
try {
@ -78,23 +78,25 @@ export class Timeline {
// txn should be assumed to have finished here, as decryption will close it.
}
async _loadPowerLevels(txn) {
async _loadPowerLevels(membership, txn) {
// TODO: update power levels as state is updated
const powerLevelsState = await txn.roomState.get(this._roomId, "m.room.power_levels", "");
if (powerLevelsState) {
return new PowerLevels({
powerLevelEvent: powerLevelsState.event,
ownUserId: this._ownMember.userId
ownUserId: this._ownMember.userId,
membership
});
}
const createState = await txn.roomState.get(this._roomId, "m.room.create", "");
if (createState) {
return new PowerLevels({
createEvent: createState.event,
ownUserId: this._ownMember.userId
ownUserId: this._ownMember.userId,
membership
});
} else {
return new PowerLevels({ownUserId: this._ownMember.userId});
return new PowerLevels({ownUserId: this._ownMember.userId, membership});
}
}