Skip to content

Commit

Permalink
State.Messages: factor out API page size constant of scrollback to fe…
Browse files Browse the repository at this point in the history
…tch and increase it considerably
  • Loading branch information
jtdaugherty committed Jul 9, 2024
1 parent 669ab49 commit eea2578
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/Matterhorn/Constants.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Matterhorn.Constants
( pageAmount
, messageFetchPageSize
, userTypingExpiryInterval
, numScrollbackPosts
, previewMaxHeight
Expand Down Expand Up @@ -31,6 +32,10 @@ channelListMaxAutoWidth = 44
pageAmount :: Int
pageAmount = 15

-- | The "page size" to use with the message-fetching API
messageFetchPageSize :: Int
messageFetchPageSize = 200

-- | The expiry interval in seconds for user typing notifications.
userTypingExpiryInterval :: NominalDiffTime
userTypingExpiryInterval = 5
Expand Down
12 changes: 6 additions & 6 deletions src/Matterhorn/State/Messages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -936,20 +936,20 @@ asyncFetchMoreMessages =
withCurrentTeam $ \tId ->
withCurrentChannel tId $ \cId chan -> do
let offset = max 0 $ length (chan^.ccMessageInterface.miMessages) - 2
page = offset `div` pageAmount
page = offset `div` messageFetchPageSize
usefulMsgs = getTwoContiguousPosts Nothing (chan^.ccMessageInterface.miMessages.to reverseMessages)
sndOldestId = (messagePostId . snd) =<< usefulMsgs
query = MM.defaultPostQuery
{ MM.postQueryPage = maybe (Just page) (const Nothing) sndOldestId
, MM.postQueryPerPage = Just pageAmount
, MM.postQueryPerPage = Just messageFetchPageSize
, MM.postQueryBefore = sndOldestId
}
addTrailingGap = MM.postQueryBefore query == Nothing &&
MM.postQueryPage query == Just 0
doAsyncChannelMM Preempt cId
(\s c -> MM.mmGetPostsForChannel c query s)
(\c p -> Just $ do
pp <- addObtainedMessages c (-pageAmount) addTrailingGap p
pp <- addObtainedMessages c (-messageFetchPageSize) addTrailingGap p
postProcessMessageAdd pp)

-- | Given a starting point and a direction to move from that point,
Expand All @@ -975,7 +975,7 @@ asyncFetchMessagesForGap cId gapMessage =
when (isGap gapMessage) $
withChannel cId $ \chan ->
let offset = max 0 $ length (chan^.ccMessageInterface.miMessages) - 2
page = offset `div` pageAmount
page = offset `div` messageFetchPageSize
chanMsgs = chan^.ccMessageInterface.miMessages
fromMsg = Just gapMessage
fetchNewer = case gapMessage^.mType of
Expand All @@ -990,7 +990,7 @@ asyncFetchMessagesForGap cId gapMessage =
_ -> error "fetch gap messages: unknown gap message type"
query = MM.defaultPostQuery
{ MM.postQueryPage = maybe (Just page) (const Nothing) baseId
, MM.postQueryPerPage = Just pageAmount
, MM.postQueryPerPage = Just messageFetchPageSize
, MM.postQueryBefore = if fetchNewer then Nothing else baseId
, MM.postQueryAfter = if fetchNewer then baseId else Nothing
}
Expand All @@ -999,7 +999,7 @@ asyncFetchMessagesForGap cId gapMessage =
in doAsyncChannelMM Preempt cId
(\s c -> MM.mmGetPostsForChannel c query s)
(\c p -> Just $ do
void $ addObtainedMessages c (-pageAmount) addTrailingGap p)
void $ addObtainedMessages c (-messageFetchPageSize) addTrailingGap p)

-- | Given a particular message ID, this fetches n messages before and
-- after immediately before and after the specified message in order
Expand Down

0 comments on commit eea2578

Please sign in to comment.