mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 19:45:05 +01:00
prevent re(d)action in left/kicked room
This commit is contained in:
parent
3fa0f234bb
commit
299294daff
@ -124,6 +124,10 @@ export class BaseMessageTile extends SimpleTile {
|
|||||||
|
|
||||||
react(key, log = null) {
|
react(key, log = null) {
|
||||||
return this.logger.wrapOrRun(log, "react", async log => {
|
return this.logger.wrapOrRun(log, "react", async log => {
|
||||||
|
if (!this.canReact) {
|
||||||
|
log.set("powerlevel_lacking", true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (this._entry.haveAnnotation(key)) {
|
if (this._entry.haveAnnotation(key)) {
|
||||||
log.set("already_reacted", true);
|
log.set("already_reacted", true);
|
||||||
return;
|
return;
|
||||||
@ -140,6 +144,10 @@ export class BaseMessageTile extends SimpleTile {
|
|||||||
|
|
||||||
redactReaction(key, log = null) {
|
redactReaction(key, log = null) {
|
||||||
return this.logger.wrapOrRun(log, "redactReaction", async log => {
|
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)) {
|
if (!this._entry.haveAnnotation(key)) {
|
||||||
log.set("not_yet_reacted", true);
|
log.set("not_yet_reacted", true);
|
||||||
return;
|
return;
|
||||||
|
@ -15,14 +15,15 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export class PowerLevels {
|
export class PowerLevels {
|
||||||
constructor({powerLevelEvent, createEvent, ownUserId}) {
|
constructor({powerLevelEvent, createEvent, ownUserId, membership}) {
|
||||||
this._plEvent = powerLevelEvent;
|
this._plEvent = powerLevelEvent;
|
||||||
this._createEvent = createEvent;
|
this._createEvent = createEvent;
|
||||||
this._ownUserId = ownUserId;
|
this._ownUserId = ownUserId;
|
||||||
|
this._membership = membership;
|
||||||
}
|
}
|
||||||
|
|
||||||
canRedactFromSender(userId) {
|
canRedactFromSender(userId) {
|
||||||
if (userId === this._ownUserId) {
|
if (userId === this._ownUserId && this._membership === "join") {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return this.canRedact;
|
return this.canRedact;
|
||||||
@ -38,6 +39,9 @@ export class PowerLevels {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get _myLevel() {
|
get _myLevel() {
|
||||||
|
if (this._membership !== "join") {
|
||||||
|
return Number.MIN_SAFE_INTEGER;
|
||||||
|
}
|
||||||
return this._getUserLevel(this._ownUserId);
|
return this._getUserLevel(this._ownUserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ export class Timeline {
|
|||||||
// as they should only populate once the view subscribes to it
|
// as they should only populate once the view subscribes to it
|
||||||
// if they are populated already, the sender profile would be empty
|
// 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
|
// 30 seems to be a good amount to fill the entire screen
|
||||||
const readerRequest = this._disposables.track(this._timelineReader.readFromEnd(30, txn, log));
|
const readerRequest = this._disposables.track(this._timelineReader.readFromEnd(30, txn, log));
|
||||||
try {
|
try {
|
||||||
@ -78,23 +78,25 @@ export class Timeline {
|
|||||||
// txn should be assumed to have finished here, as decryption will close it.
|
// 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
|
// TODO: update power levels as state is updated
|
||||||
const powerLevelsState = await txn.roomState.get(this._roomId, "m.room.power_levels", "");
|
const powerLevelsState = await txn.roomState.get(this._roomId, "m.room.power_levels", "");
|
||||||
if (powerLevelsState) {
|
if (powerLevelsState) {
|
||||||
return new PowerLevels({
|
return new PowerLevels({
|
||||||
powerLevelEvent: powerLevelsState.event,
|
powerLevelEvent: powerLevelsState.event,
|
||||||
ownUserId: this._ownMember.userId
|
ownUserId: this._ownMember.userId,
|
||||||
|
membership
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const createState = await txn.roomState.get(this._roomId, "m.room.create", "");
|
const createState = await txn.roomState.get(this._roomId, "m.room.create", "");
|
||||||
if (createState) {
|
if (createState) {
|
||||||
return new PowerLevels({
|
return new PowerLevels({
|
||||||
createEvent: createState.event,
|
createEvent: createState.event,
|
||||||
ownUserId: this._ownMember.userId
|
ownUserId: this._ownMember.userId,
|
||||||
|
membership
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return new PowerLevels({ownUserId: this._ownMember.userId});
|
return new PowerLevels({ownUserId: this._ownMember.userId, membership});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user