Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Allow to unpin redacted event (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros authored Oct 2, 2024
1 parent 107ba59 commit c2c3168
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/utils/PinningUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,18 @@ export default class PinningUtils {
}

/**
* 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.
* 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.
* @param matrixClient
* @param mxEvent
* @private
*/
private static canPinOrUnpin(matrixClient: MatrixClient, mxEvent: MatrixEvent): boolean {
public static canPin(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.
* @param matrixClient
* @param mxEvent
*/
public static canPin(matrixClient: MatrixClient, mxEvent: MatrixEvent): boolean {
return PinningUtils.canPinOrUnpin(matrixClient, mxEvent) && PinningUtils.isPinnable(mxEvent);
return PinningUtils.userHasPinOrUnpinPermission(matrixClient, room) && PinningUtils.isPinnable(mxEvent);
}

/**
Expand All @@ -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);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions test/utils/PinningUtils-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

Expand Down

0 comments on commit c2c3168

Please sign in to comment.