@@ -94,12 +94,27 @@ const resolvers: Resolvers = {
9494 const currentUser = await injector . get ( Auth ) . currentUser ( ) ;
9595
9696 if ( ! currentUser ) return null ;
97- const participant = await injector . get ( Chats ) . firstRecipient ( {
98- chatId : chat . id ,
99- userId : currentUser . id
100- } ) ;
97+ const participants = await injector . get ( Chats ) . participants ( chat . id )
98+
99+ const participantsWithoutCurrentUser = participants . filter ( ( participant ) => {
100+ return participant . id !== currentUser . id
101+ } )
101102
102- return participant ? participant . name : null ;
103+
104+ if ( participantsWithoutCurrentUser . length === 1 ) {
105+ const otherParticipant = participantsWithoutCurrentUser [ 0 ]
106+ return otherParticipant . name || otherParticipant . username || ""
107+ }
108+
109+ const names = participantsWithoutCurrentUser . reduce ( ( prev , participant ) => {
110+ const name = participant . name || participant . username || ""
111+ if ( prev === "" ) {
112+ return name
113+ }
114+ return `${ prev } , ${ name } `
115+ } , "" )
116+
117+ return names
103118 } ,
104119
105120 // pulling details of participant of chat that is not the current user but belongs to current user chat room
@@ -108,14 +123,19 @@ const resolvers: Resolvers = {
108123
109124 if ( ! currentUser ) return null ;
110125
111- const participant = await injector . get ( Chats ) . firstRecipient ( {
112- chatId : chat . id ,
113- userId : currentUser . id
114- } ) ;
126+ const participants = await injector . get ( Chats ) . participants ( chat . id )
127+
128+ const participantsWithoutCurrentUser = participants . filter ( ( participant ) => {
129+ return participant . id !== currentUser . id
130+ } )
115131
116- return participant && participant . picture
132+ if ( participantsWithoutCurrentUser . length === 1 ) {
133+ const participant = participantsWithoutCurrentUser [ 0 ]
134+ return participant && participant . picture
117135 ? participant . picture
118136 : injector . get ( UnsplashApi ) . getRandomPhoto ( ) ;
137+ }
138+ return injector . get ( UnsplashApi ) . getRandomPhoto ( ) ;
119139 } ,
120140
121141 // pulling all messages for X chat room
0 commit comments