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

Allow to unpin redacted event #98

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading