summaryrefslogtreecommitdiff
path: root/src/Message.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Message.hs')
-rw-r--r--src/Message.hs12
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 [] []