summaryrefslogtreecommitdiff
path: root/src/Message.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2019-11-25 22:15:05 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2019-11-26 22:16:35 +0100
commita70628457a5ceccd37d1ba2e1791d4493b5a0502 (patch)
tree1daddb314ae7284f7e5c0c1e6308c19c681aedd1 /src/Message.hs
parentdd4c6aeae1cf30035f3c7c3d52e58082f6b7aa36 (diff)
Load and announce identity updates
Diffstat (limited to 'src/Message.hs')
-rw-r--r--src/Message.hs19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/Message.hs b/src/Message.hs
index 8892edb..61d882c 100644
--- a/src/Message.hs
+++ b/src/Message.hs
@@ -11,56 +11,55 @@ import Data.Text (Text)
import Data.Time.LocalTime
import Identity
-import PubKey
import Storage
data DirectMessage = DirectMessage
- { msgFrom :: Stored (Signed IdentityData)
+ { msgFrom :: ComposedIdentity
, msgPrev :: [Stored DirectMessage]
, msgTime :: ZonedTime
, msgText :: Text
}
data DirectMessageThread = DirectMessageThread
- { msgPeer :: Stored (Signed IdentityData)
+ { msgPeer :: ComposedIdentity
, msgHead :: [Stored DirectMessage]
, msgSeen :: [Stored DirectMessage]
}
instance Storable DirectMessage where
store' msg = storeRec $ do
- storeRef "from" $ msgFrom msg
+ mapM_ (storeRef "from") $ idDataF $ msgFrom msg
mapM_ (storeRef "prev") $ msgPrev msg
storeDate "time" $ msgTime msg
storeText "text" $ msgText msg
load' = loadRec $ DirectMessage
- <$> loadRef "from"
+ <$> loadIdentity "from"
<*> loadRefs "prev"
<*> loadDate "time"
<*> loadText "text"
instance Storable DirectMessageThread where
store' msg = storeRec $ do
- storeRef "peer" $ msgPeer msg
+ mapM_ (storeRef "peer") $ idDataF $ msgPeer msg
mapM_ (storeRef "head") $ msgHead msg
mapM_ (storeRef "seen") $ msgSeen msg
load' = loadRec $ DirectMessageThread
- <$> loadRef "peer"
+ <$> loadIdentity "peer"
<*> loadRefs "head"
<*> loadRefs "seen"
-emptyDirectThread :: UnifiedIdentity -> DirectMessageThread
-emptyDirectThread peer = DirectMessageThread (idData peer) [] []
+emptyDirectThread :: ComposedIdentity -> DirectMessageThread
+emptyDirectThread peer = DirectMessageThread peer [] []
createDirectMessage :: UnifiedIdentity -> DirectMessageThread -> Text -> IO (Stored DirectMessage, Stored DirectMessageThread)
createDirectMessage self thread msg = do
let st = storedStorage $ idData self
time <- getZonedTime
smsg <- wrappedStore st DirectMessage
- { msgFrom = idData $ finalOwner self
+ { msgFrom = toComposedIdentity $ finalOwner self
, msgPrev = msgHead thread
, msgTime = time
, msgText = msg