@@ -16,12 +16,14 @@ import Control.Monad.Reader (runReaderT)
16import Data.Argonaut (class DecodeJson)
16import Data.Argonaut (class DecodeJson)
17import Data.Array as Array
17import Data.Array as Array
18import Data.Clipboard as Clipboard
18import Data.Clipboard as Clipboard
19+import Data.DateTime (DateTime)
19import Data.Either (Either(..))
20import Data.Either (Either(..))
20import Data.JNullable (fromJNullable, jnull, nullify)
21import Data.JNullable (fromJNullable, jnull, nullify)
21import Data.JNullable as JNullable
22import Data.JNullable as JNullable
22import Data.JOpt (fromJOpt)
23import Data.JOpt (fromJOpt)
23import Data.Maybe (Maybe(..))
24import Data.Maybe (Maybe(..))
24import Data.OpenURL (openURL)
25import Data.OpenURL (openURL)
26+import Data.Ord.Down (Down(..))
25import Data.SymmetricCryptoKey (SymmetricCryptoKey)
27import Data.SymmetricCryptoKey (SymmetricCryptoKey)
26import Data.Timestamp as Timestamp
28import Data.Timestamp as Timestamp
27import Data.Traversable (traverse)
29import Data.Traversable (traverse)
@@ -93,8 +95,8 @@ main = do
93 Bridge.NeedCiphersList -> run do
95 Bridge.NeedCiphersList -> run do
94 sync <- getOrReset storage SyncKey
96 sync <- getOrReset storage SyncKey
95 ciphers <- traverse processCipher sync.ciphers
97 ciphers <- traverse processCipher sync.ciphers
98+ let sortedCiphers = Array.sortWith (_.date >>> Down) ciphers
96− liftEffect $ Elm.send app $ Bridge.LoadCiphers $ Bridge.Sub_LoadCiphers_List ciphers
99+ liftEffect $ Elm.send app $ Bridge.LoadCiphers $ Bridge.Sub_LoadCiphers_List $ map _.cipher sortedCiphers
98 liftEffect $ Storage.store storage SyncKey sync
100 liftEffect $ Storage.store storage SyncKey sync
99 pure unit
101 pure unit
100 Bridge.NeedsReset -> do
102 Bridge.NeedsReset -> do
@@ -243,7 +245,7 @@ processCipher ::
243 forall r.
245 forall r.
244 HasL "crypto" CryptoService r =>
246 HasL "crypto" CryptoService r =>
245 HasL "key" SymmetricCryptoKey r =>
247 HasL "key" SymmetricCryptoKey r =>
246− CipherResponse -> Al r Bridge.Sub_LoadCiphers
248+ CipherResponse -> Al r {cipher :: Bridge.Sub_LoadCiphers, date :: DateTime}
247processCipher cipher = do
249processCipher cipher = do
248 name <- decrypt cipher.name
250 name <- decrypt cipher.name
249 cipherType <- case cipher.type of
251 cipherType <- case cipher.type of
@@ -252,13 +254,16 @@ processCipher cipher = do
252 n | n == cipherTypeCard -> pure Bridge.CardType
254 n | n == cipherTypeCard -> pure Bridge.CardType
253 n | n == cipherTypeIdentity -> pure Bridge.IdentityType
255 n | n == cipherTypeIdentity -> pure Bridge.IdentityType
254 n -> throwError $ error $ "Unsupported cipher type: " <> show n
256 n -> throwError $ error $ "Unsupported cipher type: " <> show n
257+ date <- liftEffect $ Timestamp.toDateTime cipher.revisionDate
256− $ Bridge.Sub_LoadCiphers
259+ $ {cipher: Bridge.Sub_LoadCiphers
257 { name: name
260 { name: name
258 , date: Timestamp.toLocalDateTimeString cipher.revisionDate
261 , date: Timestamp.toLocalDateTimeString cipher.revisionDate
259 , id: cipher.id
262 , id: cipher.id
260 , cipherType
263 , cipherType
263runElmAff :: FFI.Elm -> Aff Unit -> Effect Unit
268runElmAff :: FFI.Elm -> Aff Unit -> Effect Unit
264runElmAff app =
269runElmAff app =