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

Commit 0254328

Browse files
committed
Wire up UserProfilesStores in permalinks
1 parent dcb3893 commit 0254328

File tree

3 files changed

+73
-24
lines changed

3 files changed

+73
-24
lines changed

src/hooks/usePermalinkMember.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ const determineUserId = (
6464
return null;
6565
};
6666

67+
/**
68+
* Tries to determine a RoomMember.
69+
*
70+
* @param userId - User Id to get the member for
71+
* @param targetRoom - permalink target room
72+
* @returns RoomMember of the target room if it exists.
73+
* If sharing at least one room with the user, then the result will be the profile fetched via API.
74+
* null in all other cases.
75+
*/
6776
const determineMember = (userId: string, targetRoom: Room): RoomMember | null => {
6877
const targetRoomMember = targetRoom.getMember(userId);
6978

test/components/views/elements/Pill-test.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
import DMRoomMap from "../../../../src/utils/DMRoomMap";
3434
import { Action } from "../../../../src/dispatcher/actions";
3535
import { ButtonEvent } from "../../../../src/components/views/elements/AccessibleButton";
36+
import { SdkContextClass } from "../../../../src/contexts/SDKContext";
3637

3738
describe("<Pill>", () => {
3839
let client: Mocked<MatrixClient>;
@@ -47,6 +48,7 @@ describe("<Pill>", () => {
4748
let space1: Room;
4849
const user1Id = "@user1:example.com";
4950
const user2Id = "@user2:example.com";
51+
const user3Id = "@user3:example.com";
5052
let renderResult: RenderResult;
5153
let pillParentClickHandler: (e: ButtonEvent) => void;
5254

@@ -72,6 +74,7 @@ describe("<Pill>", () => {
7274

7375
beforeEach(() => {
7476
client = mocked(stubClient());
77+
SdkContextClass.instance.client = client;
7578
DMRoomMap.makeShared();
7679
room1 = new Room(room1Id, client, user1Id);
7780
room1.name = "Room 1";
@@ -93,12 +96,13 @@ describe("<Pill>", () => {
9396
room1.addLiveEvents([room1Message]);
9497

9598
room2 = new Room(room2Id, client, user1Id);
99+
room2.currentState.setStateEvents([mkRoomMemberJoinEvent(user2Id, room2Id)]);
96100
room2.name = "Room 2";
97101

98102
space1 = new Room(space1Id, client, client.getSafeUserId());
99103
space1.name = "Space 1";
100104

101-
client.getRooms.mockReturnValue([room1, space1]);
105+
client.getRooms.mockReturnValue([room1, room2, space1]);
102106
client.getRoom.mockImplementation((roomId: string) => {
103107
if (roomId === room1.roomId) return room1;
104108
if (roomId === room2.roomId) return room2;
@@ -204,7 +208,7 @@ describe("<Pill>", () => {
204208
});
205209
});
206210

207-
it("should render the expected pill for a user not in the room", async () => {
211+
it("should render the expected pill for a known user not in the room", async () => {
208212
renderPill({
209213
room: room1,
210214
url: permalinkPrefix + user2Id,
@@ -218,6 +222,20 @@ describe("<Pill>", () => {
218222
expect(renderResult.asFragment()).toMatchSnapshot();
219223
});
220224

225+
it("should render the expected pill for an uknown user not in the room", async () => {
226+
renderPill({
227+
room: room1,
228+
url: permalinkPrefix + user3Id,
229+
});
230+
231+
// wait for profile query via API
232+
await act(async () => {
233+
await flushPromises();
234+
});
235+
236+
expect(renderResult.asFragment()).toMatchSnapshot();
237+
});
238+
221239
it("should not render anything if the type cannot be detected", () => {
222240
renderPill({
223241
url: permalinkPrefix,

test/components/views/elements/__snapshots__/Pill-test.tsx.snap

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ exports[`<Pill> should render the expected pill for @room 1`] = `
6363
</DocumentFragment>
6464
`;
6565
66-
exports[`<Pill> should render the expected pill for a message in another room 1`] = `
66+
exports[`<Pill> should render the expected pill for a known user not in the room 1`] = `
6767
<DocumentFragment>
6868
<div>
6969
<bdi>
7070
<a
71-
class="mx_Pill mx_EventPill"
72-
href="https://matrix.to/#/!room1:example.com/$123-456"
71+
class="mx_Pill mx_UserPill"
72+
href="https://matrix.to/#/@user2:example.com"
7373
>
7474
<span
7575
aria-hidden="true"
@@ -81,7 +81,7 @@ exports[`<Pill> should render the expected pill for a message in another room 1`
8181
class="mx_BaseAvatar_initial"
8282
style="font-size: 10.4px; width: 16px; line-height: 16px;"
8383
>
84-
R
84+
U
8585
</span>
8686
<img
8787
alt=""
@@ -95,15 +95,15 @@ exports[`<Pill> should render the expected pill for a message in another room 1`
9595
<span
9696
class="mx_Pill_text"
9797
>
98-
Message in Room 1
98+
User 2
9999
</span>
100100
</a>
101101
</bdi>
102102
</div>
103103
</DocumentFragment>
104104
`;
105105
106-
exports[`<Pill> should render the expected pill for a message in the same room 1`] = `
106+
exports[`<Pill> should render the expected pill for a message in another room 1`] = `
107107
<DocumentFragment>
108108
<div>
109109
<bdi>
@@ -121,7 +121,7 @@ exports[`<Pill> should render the expected pill for a message in the same room 1
121121
class="mx_BaseAvatar_initial"
122122
style="font-size: 10.4px; width: 16px; line-height: 16px;"
123123
>
124-
U
124+
R
125125
</span>
126126
<img
127127
alt=""
@@ -135,21 +135,21 @@ exports[`<Pill> should render the expected pill for a message in the same room 1
135135
<span
136136
class="mx_Pill_text"
137137
>
138-
Message from User 1
138+
Message in Room 1
139139
</span>
140140
</a>
141141
</bdi>
142142
</div>
143143
</DocumentFragment>
144144
`;
145145
146-
exports[`<Pill> should render the expected pill for a room alias 1`] = `
146+
exports[`<Pill> should render the expected pill for a message in the same room 1`] = `
147147
<DocumentFragment>
148148
<div>
149149
<bdi>
150150
<a
151-
class="mx_Pill mx_RoomPill"
152-
href="https://matrix.to/#/#room1:example.com"
151+
class="mx_Pill mx_EventPill"
152+
href="https://matrix.to/#/!room1:example.com/$123-456"
153153
>
154154
<span
155155
aria-hidden="true"
@@ -161,7 +161,7 @@ exports[`<Pill> should render the expected pill for a room alias 1`] = `
161161
class="mx_BaseAvatar_initial"
162162
style="font-size: 10.4px; width: 16px; line-height: 16px;"
163163
>
164-
R
164+
U
165165
</span>
166166
<img
167167
alt=""
@@ -175,21 +175,21 @@ exports[`<Pill> should render the expected pill for a room alias 1`] = `
175175
<span
176176
class="mx_Pill_text"
177177
>
178-
Room 1
178+
Message from User 1
179179
</span>
180180
</a>
181181
</bdi>
182182
</div>
183183
</DocumentFragment>
184184
`;
185185
186-
exports[`<Pill> should render the expected pill for a space 1`] = `
186+
exports[`<Pill> should render the expected pill for a room alias 1`] = `
187187
<DocumentFragment>
188188
<div>
189189
<bdi>
190190
<a
191191
class="mx_Pill mx_RoomPill"
192-
href="https://matrix.to/#/!space1:example.com"
192+
href="https://matrix.to/#/#room1:example.com"
193193
>
194194
<span
195195
aria-hidden="true"
@@ -201,7 +201,7 @@ exports[`<Pill> should render the expected pill for a space 1`] = `
201201
class="mx_BaseAvatar_initial"
202202
style="font-size: 10.4px; width: 16px; line-height: 16px;"
203203
>
204-
S
204+
R
205205
</span>
206206
<img
207207
alt=""
@@ -215,21 +215,21 @@ exports[`<Pill> should render the expected pill for a space 1`] = `
215215
<span
216216
class="mx_Pill_text"
217217
>
218-
Space 1
218+
Room 1
219219
</span>
220220
</a>
221221
</bdi>
222222
</div>
223223
</DocumentFragment>
224224
`;
225225
226-
exports[`<Pill> should render the expected pill for a user not in the room 1`] = `
226+
exports[`<Pill> should render the expected pill for a space 1`] = `
227227
<DocumentFragment>
228228
<div>
229229
<bdi>
230230
<a
231-
class="mx_Pill mx_UserPill"
232-
href="https://matrix.to/#/@user2:example.com"
231+
class="mx_Pill mx_RoomPill"
232+
href="https://matrix.to/#/!space1:example.com"
233233
>
234234
<span
235235
aria-hidden="true"
@@ -241,7 +241,7 @@ exports[`<Pill> should render the expected pill for a user not in the room 1`] =
241241
class="mx_BaseAvatar_initial"
242242
style="font-size: 10.4px; width: 16px; line-height: 16px;"
243243
>
244-
U
244+
S
245245
</span>
246246
<img
247247
alt=""
@@ -255,7 +255,29 @@ exports[`<Pill> should render the expected pill for a user not in the room 1`] =
255255
<span
256256
class="mx_Pill_text"
257257
>
258-
User 2
258+
Space 1
259+
</span>
260+
</a>
261+
</bdi>
262+
</div>
263+
</DocumentFragment>
264+
`;
265+
266+
exports[`<Pill> should render the expected pill for an uknown user not in the room 1`] = `
267+
<DocumentFragment>
268+
<div>
269+
<bdi>
270+
<a
271+
class="mx_Pill mx_UserPill"
272+
href="https://matrix.to/#/@user3:example.com"
273+
>
274+
<div
275+
class="mx_Pill_UserIcon mx_BaseAvatar mx_BaseAvatar_image"
276+
/>
277+
<span
278+
class="mx_Pill_text"
279+
>
280+
@user3:example.com
259281
</span>
260282
</a>
261283
</bdi>

0 commit comments

Comments
 (0)