findAdded masterstate childstate $ lastchildstate)
++ (map (pairToFunc ModifyContent) . Map.toList $ childPayloadChanges)
masterPayloadChanges =
- Map.union (findModified masterstate childstate childstate lastchildstate)
- (findModified masterstate childstate childstate masterstate)
+ Map.union
+ (findModified masterstate childstate childstate lastchildstate)
+ (findModified masterstate childstate reducedChildState masterstate)
+ where reducedChildState =
+ Map.difference childstate lastchildstate
-- The child's payload takes precedence, so we are going to
-- calculate the changes made on the master to apply to the client,
-- then subtract out any items in the master changes that have the
-- same key.
childPayloadChanges =
- Map.union (findModified childstate childstate masterstate lastchildstate)
- (findModified childstate childstate childstate lastchildstate)
+ Map.difference (findModified childstate masterstate masterstate lastchildstate)
+ (findModified masterstate childstate childstate lastchildstate)
{- | Compares two SyncCollections, and returns the commands that, when
applied to the first collection, would yield the second. -}
-> [SyncCommand k v]
diffCollection coll1 coll2 =
(map DeleteItem . findDeleted coll2 coll1 $ coll1) ++
- (map (pairToFunc CopyItem) . findAdded coll2 coll1 $ coll1)
+ (map (pairToFunc CopyItem) . findAdded coll2 coll1 $ coll1) ++
+ modifiedData
+ where modifiedData =
+ map (pairToFunc ModifyContent) .
+ Map.toList .
+ Map.mapMaybe id .
+ Map.intersectionWith compareFunc coll1 $ coll2
+ compareFunc v1 v2
+ | v1 /= v2 = Just v2
+ | otherwise = Nothing
+
+
{-
(map (pairToFunc ModifyContent) . Map.toList .
findModified coll1 coll2 $ coll1)
(Just basev, Just authv) ->
if (authv /= lastv) && (authv /= basev)
then Just authv
- else Nothing
+ else if compv /= basev && (authv /= basev)
+ then Just compv
+ else Nothing
{- | Apply the specified changes to the given SyncCollection. Returns
a new SyncCollection with the changes applied. If changes are specified