diff --git a/src/utils/PinningUtils.ts b/src/utils/PinningUtils.ts index 806e59b014..a06a7da06b 100644 --- a/src/utils/PinningUtils.ts +++ b/src/utils/PinningUtils.ts @@ -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); } /** @@ -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); } /** diff --git a/test/utils/PinningUtils-test.ts b/test/utils/PinningUtils-test.ts index 13a48eb6b8..ab65468a34 100644 --- a/test/utils/PinningUtils-test.ts +++ b/test/utils/PinningUtils-test.ts @@ -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); + }); }); });