Allow to unpin redacted event (#98)
This commit is contained in:
parent
107ba592c8
commit
c2c316831a
2 changed files with 16 additions and 18 deletions
|
@ -61,22 +61,6 @@ export default class PinningUtils {
|
|||
return content.pinned && Array.isArray(content.pinned) && content.pinned.includes(mxEvent.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the given event may be pinned or unpinned by the current user
|
||||
* It doesn't check if the event is pinnable or unpinnable.
|
||||
* @param matrixClient
|
||||
* @param mxEvent
|
||||
* @private
|
||||
*/
|
||||
private static canPinOrUnpin(matrixClient: MatrixClient, mxEvent: MatrixEvent): boolean {
|
||||
if (!isContentActionable(mxEvent)) return false;
|
||||
|
||||
const room = matrixClient.getRoom(mxEvent.getRoomId());
|
||||
if (!room) return false;
|
||||
|
||||
return PinningUtils.userHasPinOrUnpinPermission(matrixClient, room);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the given event may be pinned by the current user.
|
||||
* This checks if the user has the necessary permissions to pin or unpin the event, and if the event is pinnable.
|
||||
|
@ -84,7 +68,12 @@ export default class PinningUtils {
|
|||
* @param mxEvent
|
||||
*/
|
||||
public static canPin(matrixClient: MatrixClient, mxEvent: MatrixEvent): boolean {
|
||||
return PinningUtils.canPinOrUnpin(matrixClient, mxEvent) && PinningUtils.isPinnable(mxEvent);
|
||||
if (!isContentActionable(mxEvent)) return false;
|
||||
|
||||
const room = matrixClient.getRoom(mxEvent.getRoomId());
|
||||
if (!room) return false;
|
||||
|
||||
return PinningUtils.userHasPinOrUnpinPermission(matrixClient, room) && PinningUtils.isPinnable(mxEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -94,7 +83,10 @@ export default class PinningUtils {
|
|||
* @param mxEvent
|
||||
*/
|
||||
public static canUnpin(matrixClient: MatrixClient, mxEvent: MatrixEvent): boolean {
|
||||
return PinningUtils.canPinOrUnpin(matrixClient, mxEvent) && PinningUtils.isUnpinnable(mxEvent);
|
||||
const room = matrixClient.getRoom(mxEvent.getRoomId());
|
||||
if (!room) return false;
|
||||
|
||||
return PinningUtils.userHasPinOrUnpinPermission(matrixClient, room) && PinningUtils.isUnpinnable(mxEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -190,6 +190,12 @@ describe("PinningUtils", () => {
|
|||
|
||||
expect(PinningUtils.canUnpin(matrixClient, event)).toBe(true);
|
||||
});
|
||||
|
||||
test("should return true if the event is redacted", () => {
|
||||
const event = makePinEvent({ unsigned: { redacted_because: "because" as unknown as IEvent } });
|
||||
|
||||
expect(PinningUtils.canUnpin(matrixClient, event)).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue