@@ -32,7 +32,7 @@ export class GetConversationListHandler
32
32
const currentOrganizationId =
33
33
await this . currentOrganizationService . fetchCurrentOrganizationId ( ) ;
34
34
35
- const matchingConversations = await this . conversations . find ( {
35
+ const _matchingConversations = await this . conversations . find ( {
36
36
order : {
37
37
messages : {
38
38
created : "DESC" ,
@@ -44,13 +44,23 @@ export class GetConversationListHandler
44
44
photo : true ,
45
45
} ,
46
46
where : {
47
- members : {
48
- profileId : currentProfileId ,
49
- } ,
50
47
organizationId : currentOrganizationId ,
51
48
} ,
52
49
} ) ;
53
50
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
+
54
64
const profileIdSet = new Set < number > ( ) ;
55
65
56
66
for ( const conversation of matchingConversations ) {
@@ -81,6 +91,10 @@ export class GetConversationListHandler
81
91
ChatConversationDetails ,
82
92
matchingConversations ,
83
93
( conversation ) => {
94
+ const members = conversation . members . filter (
95
+ ( member ) => member . profileId !== currentProfileId ,
96
+ ) ;
97
+
84
98
const lastMesage = conversation . messages [ 0 ] ;
85
99
86
100
let imageUrl : string | undefined ;
@@ -92,8 +106,8 @@ export class GetConversationListHandler
92
106
) ;
93
107
}
94
108
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 ] ;
97
111
imageUrl =
98
112
profile . profilePhoto &&
99
113
this . photoService . getUrl ( profile . profilePhoto , "profile-photo" ) ;
@@ -106,9 +120,7 @@ export class GetConversationListHandler
106
120
lastMessageSent : lastMesage ? lastMesage . created : undefined ,
107
121
name :
108
122
conversation . name ||
109
- conversation . members
110
- . map ( ( x ) => profileLookup [ x . profileId ] . name )
111
- . join ( ", " ) ,
123
+ members . map ( ( x ) => profileLookup [ x . profileId ] . name ) . join ( ", " ) ,
112
124
} ;
113
125
} ,
114
126
) ;
0 commit comments