Skip to content

Commit

Permalink
Iterate
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Telatynski <[email protected]>
  • Loading branch information
t3chguy committed Jan 8, 2025
1 parent bde3142 commit 5ca8d74
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/components/views/dialogs/ForwardDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ const ForwardDialog: React.FC<IProps> = ({ matrixClient: cli, event, permalinkCr
room_id: event.getRoomId(),
origin_server_ts: event.getTs(),
});
mockEvent.sender = {
// @ts-ignore - private field access
mockEvent._sender = {
name: profileInfo.displayname || userId,
rawDisplayName: profileInfo.displayname,
userId,
Expand Down
3 changes: 2 additions & 1 deletion src/components/views/elements/EventTilePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ export default class EventTilePreview extends React.Component<IProps, IState> {
/* eslint-enable quote-props */

// Fake it more
event.sender = {
// @ts-ignore - private field access
event._sender = {
name: this.props.displayName || this.props.userId,
rawDisplayName: this.props.displayName,
userId: this.props.userId,
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/usePinnedEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ async function fetchPinnedEvent(room: Room, pinnedEventId: string, cli: MatrixCl
const senderUserId = event.getSender();
if (senderUserId && PinningUtils.isUnpinnable(event)) {
// Inject sender information
event.sender = room.getMember(senderUserId);
event.setMetadata(room.currentState, false);
// Also inject any edits we've found
if (edit) event.makeReplaced(edit);

Expand Down
3 changes: 2 additions & 1 deletion src/indexing/EventIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,8 @@ export default class EventIndex extends EventEmitter {
// We set this manually to avoid emitting RoomMember.membership and
// RoomMember.name events.
member.events.member = memberEvent;
matrixEvent.sender = member;
// @ts-ignore - private field access
matrixEvent._sender = member;

return matrixEvent;
});
Expand Down
7 changes: 1 addition & 6 deletions src/utils/exportUtils/Exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,7 @@ export default abstract class Exporter {
}

protected setEventMetadata(event: MatrixEvent): MatrixEvent {
const roomState = this.room.currentState;
const sender = event.getSender();
event.sender = (!!sender && roomState?.getSentinelMember(sender)) || null;
if (event.getType() === "m.room.member") {
event.target = roomState?.getSentinelMember(event.getStateKey()!) ?? null;
}
event.setMetadata(this.room.currentState, false);
return event;
}

Expand Down
3 changes: 2 additions & 1 deletion src/utils/exportUtils/HtmlExport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ export default class HTMLExporter extends Exporter {
}
const modifiedEvent = new MatrixEvent();
modifiedEvent.event = mxEv.event;
modifiedEvent.sender = mxEv.sender;
// @ts-ignore - private field access
modifiedEvent._sender = mxEv.sender;
modifiedEvent.event.type = "m.room.message";
modifiedEvent.event.content = modifiedContent;
return modifiedEvent;
Expand Down
6 changes: 4 additions & 2 deletions test/test-utils/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ export function mkEvent(opts: MakeEventProps): MatrixEvent {

const mxEvent = opts.event ? new MatrixEvent(event) : (event as unknown as MatrixEvent);
if (!mxEvent.sender && opts.user && opts.room) {
mxEvent.sender = {
// @ts-ignore - private field access
mxEvent._sender = {
userId: opts.user,
membership: KnownMembership.Join,
name: opts.user,
Expand Down Expand Up @@ -470,7 +471,8 @@ export function mkMembership(
}
const e = mkEvent(event);
if (opts.target) {
e.target = opts.target;
// @ts-ignore - private field access
e._target = opts.target;
}
return e;
}
Expand Down
3 changes: 2 additions & 1 deletion test/unit-tests/TextForEvent-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ describe("TextForEvent", () => {
},
},
});
mxEvent.sender = { name: userA.name } as RoomMember;
// @ts-ignore - private field access
mxEvent._sender = { name: userA.name } as RoomMember;
return mxEvent;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ describe("ReactionEventPreview", () => {
type: "m.reaction",
room: roomId,
});
event.sender = new RoomMember(roomId, userId);
event.sender.name = "Bob";
// @ts-ignore - private field access
event._sender = new RoomMember(roomId, userId);
event.sender!.name = "Bob";

expect(preview.getTextFor(event)).toMatchInlineSnapshot(`"Bob reacted 🪿 to duck duck goose"`);
});
Expand Down

0 comments on commit 5ca8d74

Please sign in to comment.