From 717fbbe7720f64b305668a9d28b1007fd8d0595e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Fri, 5 Jun 2026 21:18:15 +0200 Subject: Conversation history with change since earlier state --- src/Erebos/Conversation.hs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Erebos/Conversation.hs b/src/Erebos/Conversation.hs index 472195c..c9a3b59 100644 --- a/src/Erebos/Conversation.hs +++ b/src/Erebos/Conversation.hs @@ -23,6 +23,7 @@ module Erebos.Conversation ( conversationName, conversationPeer, conversationHistory, + conversationHistoryChange, sendMessage, deleteConversation, @@ -85,6 +86,11 @@ withConversation :: (forall conv msg. ConversationType conv msg => conv -> a) -> withConversation f (DirectMessageConversation conv) = f conv withConversation f (ChatroomConversation conv) = f conv +withConversations :: (forall conv msg. ConversationType conv msg => Maybe conv -> conv -> a) -> Conversation -> Conversation -> a +withConversations f (DirectMessageConversation conv) (DirectMessageConversation conv') = f (Just conv) conv' +withConversations f (ChatroomConversation conv) (ChatroomConversation conv') = f (Just conv) conv' +withConversations f _ conv = withConversation (f Nothing) conv + isSameConversation :: Conversation -> Conversation -> Bool isSameConversation (DirectMessageConversation t) (DirectMessageConversation t') = sameIdentity (msgPeer t) (msgPeer t') @@ -134,6 +140,9 @@ conversationPeer (ChatroomConversation _) = Nothing conversationHistory :: Conversation -> [ Message ] conversationHistory = withConversation $ map (uncurry Message) . snd . convMessageListSince Nothing +conversationHistoryChange :: Conversation -> Conversation -> ( Int, [ Message ] ) +conversationHistoryChange = withConversations $ \since -> fmap (map (uncurry Message)) . convMessageListSince since + sendMessage :: (MonadHead LocalState m, MonadError e m, FromErebosError e) => Conversation -> Text -> m () sendMessage (DirectMessageConversation thread) text = sendDirectMessage (msgPeer thread) text -- cgit v1.2.3