Skip to content

fix(api): show correct profile in conversation list #864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class GetConversationListHandler
const currentOrganizationId =
await this.currentOrganizationService.fetchCurrentOrganizationId();

const matchingConversations = await this.conversations.find({
const _matchingConversations = await this.conversations.find({
order: {
messages: {
created: "DESC",
Expand All @@ -44,13 +44,23 @@ export class GetConversationListHandler
photo: true,
},
where: {
members: {
profileId: currentProfileId,
},
organizationId: currentOrganizationId,
},
});

// TODO: Clean this up
// Using `member.profileId: currentProfileId` in `where` clause will only include
// the member matching that condition
const matchingConversations = _matchingConversations.filter(
(conversation) => {
const profileIds = conversation.members.map(
(member) => member.profileId,
);

return profileIds.includes(currentProfileId);
},
);

const profileIdSet = new Set<number>();

for (const conversation of matchingConversations) {
Expand Down Expand Up @@ -81,6 +91,10 @@ export class GetConversationListHandler
ChatConversationDetails,
matchingConversations,
(conversation) => {
const members = conversation.members.filter(
(member) => member.profileId !== currentProfileId,
);

const lastMesage = conversation.messages[0];

let imageUrl: string | undefined;
Expand All @@ -92,8 +106,8 @@ export class GetConversationListHandler
);
}

if (conversation.members.length === 1) {
const profile = profileLookup[conversation.members[0].profileId];
if (members.length === 1) {
const profile = profileLookup[members[0].profileId];
imageUrl =
profile.profilePhoto &&
this.photoService.getUrl(profile.profilePhoto, "profile-photo");
Expand All @@ -106,9 +120,7 @@ export class GetConversationListHandler
lastMessageSent: lastMesage ? lastMesage.created : undefined,
name:
conversation.name ||
conversation.members
.map((x) => profileLookup[x.profileId].name)
.join(", "),
members.map((x) => profileLookup[x.profileId].name).join(", "),
};
},
);
Expand Down
Loading