summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2026-06-05 21:18:15 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2026-06-05 21:18:15 +0200
commit717fbbe7720f64b305668a9d28b1007fd8d0595e (patch)
treec2837619435517714e6919447ff9693ad896491c
parent28e1cb53983f31b89f0f2add0a103616d4f11e28 (diff)
Conversation history with change since earlier stateHEADmaster
-rw-r--r--src/Erebos/Conversation.hs9
1 files changed, 9 insertions, 0 deletions
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