import initMatrix from '../../../client/initMatrix';
import cons from '../../../client/state/cons';
+import { redact } from '../../../client/action/room';
import { getUsername, doesRoomHaveUnread } from '../../../util/matrixUtil';
import colorMXID from '../../../util/colorMXID';
import { diffMinutes, isNotInSameDay } from '../../../util/common';
&& prevMEvent.getSender() === mEvent.getSender()
);
+ const myPowerlevel = roomTimeline.room.getMember(mx.getUserId()).powerLevel;
+ const canIRedact = roomTimeline.room.currentState.hasSufficientPowerLevelFor('redact', myPowerlevel);
+
let content = mEvent.getContent().body;
if (typeof content === 'undefined') return null;
let reply = null;
});
}
- const userMXIDColor = colorMXID(mEvent.sender.userId);
+ const senderMXIDColor = colorMXID(mEvent.sender.userId);
const userAvatar = isContentOnly ? null : (
<Avatar
imageSrc={mEvent.sender.getAvatarUrl(initMatrix.matrixClient.baseUrl, 36, 36, 'crop')}
text={getUsername(mEvent.sender.userId).slice(0, 1)}
- bgColor={userMXIDColor}
+ bgColor={senderMXIDColor}
size="small"
/>
);
<MessageHeader
userId={mEvent.sender.userId}
name={getUsername(mEvent.sender.userId)}
- color={userMXIDColor}
+ color={senderMXIDColor}
time={`${dateFormat(mEvent.getDate(), 'hh:MM TT')}`}
/>
);
size="extra-small"
tooltip="Reply"
/>
- <IconButton src={BinIC} size="extra-small" tooltip="Delete" />
+ {(canIRedact || mEvent.getSender() === mx.getUserId()) && (
+ <IconButton
+ onClick={() => {
+ if (window.confirm('Are you sure you want to delete this event')) {
+ redact(roomId, mEvent.getId());
+ }
+ }}
+ src={BinIC}
+ size="extra-small"
+ tooltip="Delete"
+ />
+ )}
</MessageOptions>
);
}
}
+async function redact(roomId, eventId, reason) {
+ const mx = initMatrix.matrixClient;
+
+ try {
+ await mx.redactEvent(roomId, eventId, undefined, typeof reason === 'undefined' ? undefined : { reason });
+ return true;
+ } catch (e) {
+ throw new Error(e);
+ }
+}
+
export {
- join, leave, create, invite,
+ join, leave,
+ create, invite,
+ redact,
};
this.emit(cons.events.roomTimeline.EVENT);
};
+ this._listenRedaction = (event, room) => {
+ if (room.roomId !== this.roomId) return;
+ this.emit(cons.events.roomTimeline.EVENT);
+ };
+
this._listenDecryptEvent = (event) => {
if (event.getRoomId() !== this.roomId) return;
};
this.matrixClient.on('Room.timeline', this._listenRoomTimeline);
+ this.matrixClient.on('Room.redaction', this._listenRedaction);
this.matrixClient.on('Event.decrypted', this._listenDecryptEvent);
this.matrixClient.on('RoomMember.typing', this._listenTypingEvent);
this.matrixClient.on('Room.receipt', this._listenReciptEvent);
removeInternalListeners() {
this.matrixClient.removeListener('Room.timeline', this._listenRoomTimeline);
+ this.matrixClient.removeListener('Room.redaction', this._listenRedaction);
this.matrixClient.removeListener('Event.decrypted', this._listenDecryptEvent);
this.matrixClient.removeListener('RoomMember.typing', this._listenTypingEvent);
this.matrixClient.removeListener('Room.receipt', this._listenReciptEvent);