Fix sending localEvent id to redact and reply (#231)

Signed-off-by: ajbura <ajbura@gmail.com>
This commit is contained in:
ajbura 2022-02-05 17:53:02 +05:30
parent bb99167433
commit 101abaeda1

View file

@ -114,22 +114,31 @@ const MessageReplyWrapper = React.memo(({ roomTimeline, eventId }) => {
const mx = initMatrix.matrixClient; const mx = initMatrix.matrixClient;
const timelineSet = roomTimeline.getUnfilteredTimelineSet(); const timelineSet = roomTimeline.getUnfilteredTimelineSet();
const loadReply = async () => { const loadReply = async () => {
const eTimeline = await mx.getEventTimeline(timelineSet, eventId); try {
await roomTimeline.decryptAllEventsOfTimeline(eTimeline); const eTimeline = await mx.getEventTimeline(timelineSet, eventId);
await roomTimeline.decryptAllEventsOfTimeline(eTimeline);
const mEvent = eTimeline.getTimelineSet().findEventById(eventId); const mEvent = eTimeline.getTimelineSet().findEventById(eventId);
const rawBody = mEvent.getContent().body; const rawBody = mEvent.getContent().body;
const username = getUsernameOfRoomMember(mEvent.sender); const username = getUsernameOfRoomMember(mEvent.sender);
if (isMountedRef.current === false) return; if (isMountedRef.current === false) return;
const fallbackBody = mEvent.isRedacted() ? '*** This message has been deleted ***' : '*** Unable to load reply content ***'; const fallbackBody = mEvent.isRedacted() ? '*** This message has been deleted ***' : '*** Unable to load reply ***';
setReply({ setReply({
to: username, to: username,
color: colorMXID(mEvent.getSender()), color: colorMXID(mEvent.getSender()),
body: parseReply(rawBody)?.body ?? rawBody ?? fallbackBody, body: parseReply(rawBody)?.body ?? rawBody ?? fallbackBody,
event: mEvent, event: mEvent,
}); });
} catch {
setReply({
to: '** Unknown user **',
color: 'var(--tc-danger-normal)',
body: '*** Unable to load reply ***',
event: null,
});
}
}; };
loadReply(); loadReply();
@ -139,6 +148,7 @@ const MessageReplyWrapper = React.memo(({ roomTimeline, eventId }) => {
}, []); }, []);
const focusReply = () => { const focusReply = () => {
if (reply?.event === null) return;
if (reply?.event.isRedacted()) return; if (reply?.event.isRedacted()) return;
roomTimeline.loadEventTimeline(eventId); roomTimeline.loadEventTimeline(eventId);
}; };
@ -357,13 +367,12 @@ MessageReaction.propTypes = {
function MessageReactionGroup({ roomTimeline, mEvent }) { function MessageReactionGroup({ roomTimeline, mEvent }) {
const { roomId, room, reactionTimeline } = roomTimeline; const { roomId, room, reactionTimeline } = roomTimeline;
const eventId = mEvent.getId();
const mx = initMatrix.matrixClient; const mx = initMatrix.matrixClient;
const reactions = {}; const reactions = {};
const shortcodeToEmoji = getShortcodeToCustomEmoji(room); const shortcodeToEmoji = getShortcodeToCustomEmoji(room);
const canSendReaction = room.currentState.maySendEvent('m.reaction', mx.getUserId()); const canSendReaction = room.currentState.maySendEvent('m.reaction', mx.getUserId());
const eventReactions = reactionTimeline.get(eventId); const eventReactions = reactionTimeline.get(mEvent.getId());
const addReaction = (key, count, senderId, isActive) => { const addReaction = (key, count, senderId, isActive) => {
let reaction = reactions[key]; let reaction = reactions[key];
if (reaction === undefined) { if (reaction === undefined) {
@ -414,7 +423,7 @@ function MessageReactionGroup({ roomTimeline, mEvent }) {
users={reactions[key].users} users={reactions[key].users}
isActive={reactions[key].isActive} isActive={reactions[key].isActive}
onClick={() => { onClick={() => {
toggleEmoji(roomId, eventId, key, roomTimeline); toggleEmoji(roomId, mEvent.getId(), key, roomTimeline);
}} }}
/> />
)) ))
@ -422,7 +431,7 @@ function MessageReactionGroup({ roomTimeline, mEvent }) {
{canSendReaction && ( {canSendReaction && (
<IconButton <IconButton
onClick={(e) => { onClick={(e) => {
pickEmoji(e, roomId, eventId, roomTimeline); pickEmoji(e, roomId, mEvent.getId(), roomTimeline);
}} }}
src={EmojiAddIC} src={EmojiAddIC}
size="extra-small" size="extra-small"
@ -452,7 +461,6 @@ const MessageOptions = React.memo(({
}) => { }) => {
const { roomId, room } = roomTimeline; const { roomId, room } = roomTimeline;
const mx = initMatrix.matrixClient; const mx = initMatrix.matrixClient;
const eventId = mEvent.getId();
const senderId = mEvent.getSender(); const senderId = mEvent.getSender();
const myPowerlevel = room.getMember(mx.getUserId())?.powerLevel; const myPowerlevel = room.getMember(mx.getUserId())?.powerLevel;
@ -463,7 +471,7 @@ const MessageOptions = React.memo(({
<div className="message__options"> <div className="message__options">
{canSendReaction && ( {canSendReaction && (
<IconButton <IconButton
onClick={(e) => pickEmoji(e, roomId, eventId, roomTimeline)} onClick={(e) => pickEmoji(e, roomId, mEvent.getId(), roomTimeline)}
src={EmojiAddIC} src={EmojiAddIC}
size="extra-small" size="extra-small"
tooltip="Add reaction" tooltip="Add reaction"
@ -501,7 +509,7 @@ const MessageOptions = React.memo(({
iconSrc={BinIC} iconSrc={BinIC}
onClick={() => { onClick={() => {
if (window.confirm('Are you sure you want to delete this event')) { if (window.confirm('Are you sure you want to delete this event')) {
redactEvent(roomId, eventId); redactEvent(roomId, mEvent.getId());
} }
}} }}
> >
@ -631,7 +639,7 @@ function Message({
setIsEditing(true); setIsEditing(true);
}, []); }, []);
const reply = useCallback(() => { const reply = useCallback(() => {
replyTo(senderId, eventId, body); replyTo(senderId, mEvent.getId(), body);
}, [body]); }, [body]);
if (body === undefined) return null; if (body === undefined) return null;