blob: afb45e68f1d588a14669f6fb47bdd1d134c9829b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
module Sync (
SyncService(..),
) where
import Control.Monad
import Data.List
import Service
import State
import Storage
import Storage.Merge
data SyncService = SyncPacket (Stored SharedState)
instance Service SyncService where
serviceID _ = mkServiceID "a4f538d0-4e50-4082-8e10-7e3ec2af175d"
serviceHandler packet = do
let SyncPacket added = fromStored packet
ls <- svcGetLocal
let st = storedStorage ls
current = sort $ lsShared $ fromStored ls
updated = filterAncestors (added : current)
when (current /= updated) $ do
svcSetLocal =<< wrappedStore st (fromStored ls) { lsShared = updated }
instance Storable SyncService where
store' (SyncPacket smsg) = store' smsg
load' = SyncPacket <$> load'
|