@@ -143,55 +143,29 @@ public async Task<IEnumerable<ChatResponseModel>> GetDialogs([FromRoute] string
143143 {
144144 var service = _services . GetRequiredService < IConversationService > ( ) ;
145145 var userService = _services . GetRequiredService < IUserService > ( ) ;
146+ var settings = _services . GetRequiredService < PluginSettings > ( ) ;
147+
146148 var ( isAdmin , user ) = await userService . IsAdminUser ( _user . Id ) ;
147- if ( user == null )
148- {
149- return null ;
150- }
151149
152150 var filter = new ConversationFilter
153151 {
154152 Id = conversationId ,
155- UserId = ! isAdmin ? user . Id : null ,
153+ UserId = ! isAdmin ? user ? . Id : null ,
156154 IsLoadLatestStates = isLoadStates
157155 } ;
158- var conversations = await service . GetConversations ( filter ) ;
159- if ( conversations . Items . IsNullOrEmpty ( ) )
160- {
161- return null ;
162- }
163156
164- var result = ConversationViewModel . FromSession ( conversations . Items . First ( ) ) ;
165- var state = _services . GetRequiredService < IConversationStateService > ( ) ;
166- user = await userService . GetUser ( result . User . Id ) ;
167- result . User = UserViewModel . FromUser ( user ) ;
168-
169- return result ;
170- }
171-
172- [ HttpPost ( "/conversation/summary" ) ]
173- public async Task < string > GetConversationSummary ( [ FromBody ] ConversationSummaryModel input )
174- {
175- var service = _services . GetRequiredService < IConversationService > ( ) ;
176- return await service . GetConversationSummary ( input . ConversationIds ) ;
177- }
157+ var conversations = await service . GetConversations ( filter ) ;
158+ var conv = ! conversations . Items . IsNullOrEmpty ( )
159+ ? ConversationViewModel . FromSession ( conversations . Items . First ( ) )
160+ : new ( ) ;
178161
179- [ HttpGet ( "/conversation/{conversationId}/user" ) ]
180- public async Task < UserViewModel > GetConversationUser ( [ FromRoute ] string conversationId )
181- {
182- var service = _services . GetRequiredService < IConversationService > ( ) ;
183- var conversations = await service . GetConversations ( new ConversationFilter
184- {
185- Id = conversationId
186- } ) ;
162+ user = ! string . IsNullOrEmpty ( conv ? . User ? . Id )
163+ ? await userService . GetUser ( conv . User . Id )
164+ : null ;
187165
188- var userService = _services . GetRequiredService < IUserService > ( ) ;
189- var conversation = conversations ? . Items ? . FirstOrDefault ( ) ;
190- var userId = conversation == null ? _user . Id : conversation . UserId ;
191- var user = await userService . GetUser ( userId ) ;
192166 if ( user == null )
193167 {
194- return new UserViewModel
168+ user = new User
195169 {
196170 Id = _user . Id ,
197171 UserName = _user . UserName ,
@@ -202,7 +176,16 @@ public async Task<UserViewModel> GetConversationUser([FromRoute] string conversa
202176 } ;
203177 }
204178
205- return UserViewModel . FromUser ( user ) ;
179+ conv . User = UserViewModel . FromUser ( user ) ;
180+ conv . IsRealtimeEnabled = settings ? . Assemblies ? . Contains ( "BotSharp.Core.Realtime" ) ?? false ;
181+ return conv ;
182+ }
183+
184+ [ HttpPost ( "/conversation/summary" ) ]
185+ public async Task < string > GetConversationSummary ( [ FromBody ] ConversationSummaryModel input )
186+ {
187+ var service = _services . GetRequiredService < IConversationService > ( ) ;
188+ return await service . GetConversationSummary ( input . ConversationIds ) ;
206189 }
207190
208191 [ HttpPut ( "/conversation/{conversationId}/update-title" ) ]
0 commit comments