@@ -18,7 +18,7 @@ use tonic::{Request, Response, Status};
1818use uuid:: Uuid ;
1919
2020use crate :: persistence:: DeviceKind ;
21- use crate :: proto:: { Group , KeyType , MeeSign , MeeSignServer , ProtocolType } ;
21+ use crate :: proto:: { KeyType , MeeSign , MeeSignServer , ProtocolType } ;
2222use crate :: state:: State ;
2323use crate :: { proto as msg, utils, CA_CERT , CA_KEY } ;
2424
@@ -275,21 +275,52 @@ impl MeeSign for MeeSignService {
275275 debug ! ( "GroupsRequest device_id={}" , device_str) ;
276276
277277 let state = self . state . lock ( ) . await ;
278- // TODO: refactor, consider storing device IDS in the group model directly
279278 let groups = if let Some ( device_id) = device_id {
280279 state. activate_device ( & device_id) ;
281280 state
282281 . get_device_groups ( & device_id)
283282 . await ?
284283 . into_iter ( )
285- . map ( Group :: from_model)
284+ . map ( |group_model| {
285+ msg:: Group {
286+ identifier : group_model. id . clone ( ) ,
287+ name : group_model. name . clone ( ) ,
288+ threshold : group_model. threshold as u32 ,
289+ device_ids : group_model
290+ . participant_ids_shares
291+ . iter ( )
292+ . flat_map ( |( device_id, shares) | {
293+ std:: iter:: repeat ( device_id. clone ( ) ) . take ( * shares as usize )
294+ } )
295+ . collect ( ) ,
296+ protocol : group_model. protocol as i32 ,
297+ key_type : group_model. key_type as i32 ,
298+ note : group_model. note . clone ( ) ,
299+ }
300+ } )
286301 . collect ( )
287302 } else {
288303 state
289304 . get_groups ( )
290305 . await ?
291306 . into_iter ( )
292- . map ( Group :: from_model)
307+ . map ( |group_model| {
308+ msg:: Group {
309+ identifier : group_model. id . clone ( ) ,
310+ name : group_model. name . clone ( ) ,
311+ threshold : group_model. threshold as u32 ,
312+ device_ids : group_model
313+ . participant_ids_shares
314+ . iter ( )
315+ . flat_map ( |( device_id, shares) | {
316+ std:: iter:: repeat ( device_id. clone ( ) ) . take ( * shares as usize )
317+ } )
318+ . collect ( ) ,
319+ protocol : group_model. protocol as i32 ,
320+ key_type : group_model. key_type as i32 ,
321+ note : group_model. note . clone ( ) ,
322+ }
323+ } )
293324 . collect ( )
294325 } ;
295326
0 commit comments