collect and send message history

This commit is contained in:
spaced4ndy
2023-12-13 21:44:29 +04:00
parent a55bb679c8
commit e714f4037a
6 changed files with 129 additions and 21 deletions
+20 -1
View File
@@ -31,6 +31,7 @@ import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (c2w, w2c)
import qualified Data.ByteString.Lazy.Char8 as LB
import Data.Maybe (fromMaybe)
import Data.Set (Set)
import Data.String
import Data.Text (Text)
import qualified Data.Text as T
@@ -149,7 +150,7 @@ instance StrEncoding AppMessageBinary where
pure AppMessageBinary {tag, msgId, body}
newtype SharedMsgId = SharedMsgId ByteString
deriving (Eq, Show)
deriving (Eq, Ord, Show)
instance FromField SharedMsgId where fromField f = SharedMsgId <$> fromField f
@@ -289,6 +290,24 @@ forwardedGroupMsg msg@ChatMessage {chatMsgEvent} = case encoding @e of
SJson | isForwardedGroupMsg chatMsgEvent -> Just msg
_ -> Nothing
msgIncludedInHistory :: forall e. MsgEncodingI e => ChatMessage e -> Set SharedMsgId -> Maybe (ChatMessage 'Json)
msgIncludedInHistory msg@ChatMessage {chatMsgEvent} accMsgIds = case encoding @e of
SJson -> case chatMsgEvent of
XMsgNew mc -> case mcExtMsgContent mc of
ExtMsgContent {file = Just FileInvitation {fileInline = Just _}} -> Nothing
_ -> Just msg
XMsgFileDescr msgId _ -> refIncluded msgId
XMsgUpdate {msgId} -> refIncluded msgId
XMsgDel msgId _ -> refIncluded msgId
XMsgReact {msgId} -> refIncluded msgId
XFileCancel msgId -> refIncluded msgId
_ -> Nothing
where
refIncluded msgId
| msgId `elem` accMsgIds = Just msg
| otherwise = Nothing
_ -> Nothing
data MsgReaction = MREmoji {emoji :: MREmojiChar} | MRUnknown {tag :: Text, json :: J.Object}
deriving (Eq, Show)