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

Commit c2c3168

Browse files
authored
Allow to unpin redacted event (#98)
1 parent 107ba59 commit c2c3168

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

src/utils/PinningUtils.ts

+8-16
Original file line numberDiff line numberDiff line change
@@ -62,29 +62,18 @@ export default class PinningUtils {
6262
}
6363

6464
/**
65-
* Determines if the given event may be pinned or unpinned by the current user
66-
* It doesn't check if the event is pinnable or unpinnable.
65+
* Determines if the given event may be pinned by the current user.
66+
* This checks if the user has the necessary permissions to pin or unpin the event, and if the event is pinnable.
6767
* @param matrixClient
6868
* @param mxEvent
69-
* @private
7069
*/
71-
private static canPinOrUnpin(matrixClient: MatrixClient, mxEvent: MatrixEvent): boolean {
70+
public static canPin(matrixClient: MatrixClient, mxEvent: MatrixEvent): boolean {
7271
if (!isContentActionable(mxEvent)) return false;
7372

7473
const room = matrixClient.getRoom(mxEvent.getRoomId());
7574
if (!room) return false;
7675

77-
return PinningUtils.userHasPinOrUnpinPermission(matrixClient, room);
78-
}
79-
80-
/**
81-
* Determines if the given event may be pinned by the current user.
82-
* This checks if the user has the necessary permissions to pin or unpin the event, and if the event is pinnable.
83-
* @param matrixClient
84-
* @param mxEvent
85-
*/
86-
public static canPin(matrixClient: MatrixClient, mxEvent: MatrixEvent): boolean {
87-
return PinningUtils.canPinOrUnpin(matrixClient, mxEvent) && PinningUtils.isPinnable(mxEvent);
76+
return PinningUtils.userHasPinOrUnpinPermission(matrixClient, room) && PinningUtils.isPinnable(mxEvent);
8877
}
8978

9079
/**
@@ -94,7 +83,10 @@ export default class PinningUtils {
9483
* @param mxEvent
9584
*/
9685
public static canUnpin(matrixClient: MatrixClient, mxEvent: MatrixEvent): boolean {
97-
return PinningUtils.canPinOrUnpin(matrixClient, mxEvent) && PinningUtils.isUnpinnable(mxEvent);
86+
const room = matrixClient.getRoom(mxEvent.getRoomId());
87+
if (!room) return false;
88+
89+
return PinningUtils.userHasPinOrUnpinPermission(matrixClient, room) && PinningUtils.isUnpinnable(mxEvent);
9890
}
9991

10092
/**

test/utils/PinningUtils-test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ describe("PinningUtils", () => {
190190

191191
expect(PinningUtils.canUnpin(matrixClient, event)).toBe(true);
192192
});
193+
194+
test("should return true if the event is redacted", () => {
195+
const event = makePinEvent({ unsigned: { redacted_because: "because" as unknown as IEvent } });
196+
197+
expect(PinningUtils.canUnpin(matrixClient, event)).toBe(true);
198+
});
193199
});
194200
});
195201

0 commit comments

Comments
 (0)