@@ -54,6 +54,17 @@ import Wire.API.MLS.LeafNode
5454import Wire.API.MLS.SubConversation
5555import Wire.StoredConversation
5656
57+ mkGroupMember ::
58+ Maybe Domain ->
59+ Maybe UserId ->
60+ Maybe ClientId ->
61+ Maybe HistoryClientId ->
62+ Maybe GroupMember
63+ mkGroupMember (Just dom) (Just uid) (Just cid) Nothing =
64+ Just (RegularClient (ClientIdentity dom uid cid))
65+ mkGroupMember Nothing Nothing Nothing (Just hid) = Just (HistoryClient hid)
66+ mkGroupMember _ _ _ _ = Nothing
67+
5768-- | A map of leaf index to members.
5869--
5970-- This is used to reconstruct client
@@ -63,31 +74,40 @@ import Wire.StoredConversation
6374-- Note that clients that are in the process of being removed from a group
6475-- (i.e. there is a pending remove proposals for them) are included in this
6576-- mapping.
66- newtype IndexMap = IndexMap { unIndexMap :: IntMap ClientIdentity }
77+ newtype IndexMap = IndexMap { unIndexMap :: IntMap GroupMember }
6778 deriving (Eq , Show )
6879 deriving newtype (Semigroup , Monoid )
6980
70- mkIndexMap :: [(Domain , UserId , ClientId , Int32 , Bool )] -> IndexMap
71- mkIndexMap = IndexMap . foldr addEntry mempty
81+ mkIndexMapFromParts ::
82+ [(Domain , UserId , ClientId , Int32 , Bool )] ->
83+ [(HistoryClientId , Int32 , Bool )] ->
84+ IndexMap
85+ mkIndexMapFromParts rows1 rows2 =
86+ IndexMap
87+ . flip (foldr addHistoryClient) rows2
88+ . flip (foldr addRegularClient) rows1
89+ $ mempty
7290 where
73- addEntry (dom, usr, c, leafidx, _pending_removal) =
74- IntMap. insert (fromIntegral leafidx) (ClientIdentity dom usr c)
91+ addHistoryClient (h, leafidx, _) =
92+ IntMap. insert (fromIntegral leafidx) (HistoryClient h)
93+ addRegularClient (dom, usr, c, leafidx, _) =
94+ IntMap. insert (fromIntegral leafidx) (RegularClient (ClientIdentity dom usr c))
7595
76- imLookup :: IndexMap -> LeafIndex -> Maybe ClientIdentity
96+ imLookup :: IndexMap -> LeafIndex -> Maybe GroupMember
7797imLookup m i = IntMap. lookup (fromIntegral i) (unIndexMap m)
7898
79- imFromList :: [(LeafIndex , ClientIdentity )] -> IndexMap
99+ imFromList :: [(LeafIndex , GroupMember )] -> IndexMap
80100imFromList = IndexMap . IntMap. fromList . map (first fromIntegral )
81101
82102imNextIndex :: IndexMap -> LeafIndex
83103imNextIndex im =
84104 fromIntegral . fromJust $
85105 find (\ n -> not $ IntMap. member n (unIndexMap im)) [0 .. ]
86106
87- imAddClient :: IndexMap -> ClientIdentity -> (LeafIndex , IndexMap )
107+ imAddClient :: IndexMap -> GroupMember -> (LeafIndex , IndexMap )
88108imAddClient im cid = let idx = imNextIndex im in (idx, IndexMap $ IntMap. insert (fromIntegral idx) cid $ unIndexMap im)
89109
90- imRemoveClient :: IndexMap -> LeafIndex -> Maybe (ClientIdentity , IndexMap )
110+ imRemoveClient :: IndexMap -> LeafIndex -> Maybe (GroupMember , IndexMap )
91111imRemoveClient im idx = do
92112 cid <- imLookup im idx
93113 pure (cid, IndexMap . IntMap. delete (fromIntegral idx) $ unIndexMap im)
@@ -98,7 +118,7 @@ imRemoveIndices keys =
98118 . flip IntMap. withoutKeys (IntSet. fromList (map fromIntegral keys))
99119 . unIndexMap
100120
101- imAssocs :: IndexMap -> [(Int , ClientIdentity )]
121+ imAssocs :: IndexMap -> [(Int , GroupMember )]
102122imAssocs = IntMap. assocs . unIndexMap
103123
104124-- | A two-level map of users to clients to leaf indices.
@@ -111,6 +131,7 @@ imAssocs = IntMap.assocs . unIndexMap
111131-- this mapping.
112132newtype ClientMap a = ClientMap
113133 { unClientMap :: Map (Qualified UserId ) (Map ClientId a )
134+ -- TODO: add historyClients
114135 }
115136 deriving (Show , Eq , Functor )
116137
0 commit comments