Skip to content

Commit 75b5f85

Browse files
Johan BookJohan Book
Johan Book
authored and
Johan Book
committed
fix(api): show correct profile in conversation list
1 parent 784114b commit 75b5f85

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

services/api/src/features/chat/application/handlers/query-handlers/get-conversation-list.handler.ts

+21-9
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class GetConversationListHandler
3232
const currentOrganizationId =
3333
await this.currentOrganizationService.fetchCurrentOrganizationId();
3434

35-
const matchingConversations = await this.conversations.find({
35+
const _matchingConversations = await this.conversations.find({
3636
order: {
3737
messages: {
3838
created: "DESC",
@@ -44,13 +44,23 @@ export class GetConversationListHandler
4444
photo: true,
4545
},
4646
where: {
47-
members: {
48-
profileId: currentProfileId,
49-
},
5047
organizationId: currentOrganizationId,
5148
},
5249
});
5350

51+
// TODO: Clean this up
52+
// Using `member.profileId: currentProfileId` in `where` clause will only include
53+
// the member matching that condition
54+
const matchingConversations = _matchingConversations.filter(
55+
(conversation) => {
56+
const profileIds = conversation.members.map(
57+
(member) => member.profileId,
58+
);
59+
60+
return profileIds.includes(currentProfileId);
61+
},
62+
);
63+
5464
const profileIdSet = new Set<number>();
5565

5666
for (const conversation of matchingConversations) {
@@ -81,6 +91,10 @@ export class GetConversationListHandler
8191
ChatConversationDetails,
8292
matchingConversations,
8393
(conversation) => {
94+
const members = conversation.members.filter(
95+
(member) => member.profileId !== currentProfileId,
96+
);
97+
8498
const lastMesage = conversation.messages[0];
8599

86100
let imageUrl: string | undefined;
@@ -92,8 +106,8 @@ export class GetConversationListHandler
92106
);
93107
}
94108

95-
if (conversation.members.length === 1) {
96-
const profile = profileLookup[conversation.members[0].profileId];
109+
if (members.length === 1) {
110+
const profile = profileLookup[members[0].profileId];
97111
imageUrl =
98112
profile.profilePhoto &&
99113
this.photoService.getUrl(profile.profilePhoto, "profile-photo");
@@ -106,9 +120,7 @@ export class GetConversationListHandler
106120
lastMessageSent: lastMesage ? lastMesage.created : undefined,
107121
name:
108122
conversation.name ||
109-
conversation.members
110-
.map((x) => profileLookup[x.profileId].name)
111-
.join(", "),
123+
members.map((x) => profileLookup[x.profileId].name).join(", "),
112124
};
113125
},
114126
);

0 commit comments

Comments
 (0)