diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2019-05-27 21:47:51 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2019-05-27 21:47:51 +0200 |
commit | 61595dec8bfd7d74e7cd2f3500eec86c08eff436 (patch) | |
tree | ea1cb7dab9eb7782c9fd2b76f354d5ce1e278276 /src/Message.hs | |
parent | aed5e1e63b353835b6ea96ec0ff6c86f63bc5a35 (diff) |
Finalize messsage thread listing
Diffstat (limited to 'src/Message.hs')
-rw-r--r-- | src/Message.hs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/Message.hs b/src/Message.hs index 8eaf7f1..0b633ae 100644 --- a/src/Message.hs +++ b/src/Message.hs @@ -6,6 +6,7 @@ module Message ( import Data.List import Data.Ord +import qualified Data.Set as S import Data.Text (Text) import Data.Time.LocalTime @@ -70,8 +71,9 @@ createDirectMessage self thread msg = do return (smsg, sthread) threadToList :: DirectMessageThread -> [DirectMessage] -threadToList thread = helper $ msgHead thread - where helper msgs | msg : msgs' <- sortBy (comparing cmpView) msgs = - fromStored msg : helper (dropWhile (== msg) msgs') - | otherwise = [] +threadToList thread = helper S.empty $ msgHead thread + where helper seen msgs + | msg : msgs' <- filter (`S.notMember` seen) $ reverse $ sortBy (comparing cmpView) msgs = + fromStored msg : helper (S.insert msg seen) (msgs' ++ msgPrev (fromStored msg)) + | otherwise = [] cmpView msg = (zonedTimeToUTC $ msgTime $ fromStored msg, storedRef msg) |