diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2019-12-07 22:35:55 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2019-12-07 22:35:55 +0100 |
commit | 35347e4cfbd9070d1065b1ff9600013d648c5e6e (patch) | |
tree | 0f09520e841012b0a702ec4ea068b89983a0aa2a /src/Message.hs | |
parent | 51bc5cd6948985ab294ed3216345d046f4aefc85 (diff) |
Mergeable stored list
Diffstat (limited to 'src/Message.hs')
-rw-r--r-- | src/Message.hs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/Message.hs b/src/Message.hs index 61d882c..21f398c 100644 --- a/src/Message.hs +++ b/src/Message.hs @@ -12,6 +12,7 @@ import Data.Time.LocalTime import Identity import Storage +import Storage.Merge data DirectMessage = DirectMessage { msgFrom :: ComposedIdentity @@ -29,13 +30,13 @@ data DirectMessageThread = DirectMessageThread instance Storable DirectMessage where store' msg = storeRec $ do mapM_ (storeRef "from") $ idDataF $ msgFrom msg - mapM_ (storeRef "prev") $ msgPrev msg + mapM_ (storeRef "PREV") $ msgPrev msg storeDate "time" $ msgTime msg storeText "text" $ msgText msg load' = loadRec $ DirectMessage <$> loadIdentity "from" - <*> loadRefs "prev" + <*> loadRefs "PREV" <*> loadDate "time" <*> loadText "text" @@ -50,6 +51,13 @@ instance Storable DirectMessageThread where <*> loadRefs "head" <*> loadRefs "seen" +instance Mergeable DirectMessageThread where + mergeSorted ts = DirectMessageThread + { msgPeer = msgPeer $ fromStored $ head ts -- TODO: merge identity + , msgHead = filterAncestors $ msgHead . fromStored =<< ts + , msgSeen = filterAncestors $ msgSeen . fromStored =<< ts + } + emptyDirectThread :: ComposedIdentity -> DirectMessageThread emptyDirectThread peer = DirectMessageThread peer [] [] |