Slice timelines to 100 entries max. (#90)

This commit is contained in:
Nicolas Perriault 2017-04-28 20:09:19 +02:00 committed by GitHub
parent cfe0937a01
commit d32f12bf20

View File

@ -14,6 +14,12 @@ import Task
import Dom.Scroll import Dom.Scroll
maxBuffer : Int
maxBuffer =
-- Max number of entries to keep in columns
100
type alias Flags = type alias Flags =
{ client : Maybe Mastodon.Model.Client { client : Maybe Mastodon.Model.Client
, registration : Maybe Mastodon.Model.AppRegistration , registration : Maybe Mastodon.Model.AppRegistration
@ -276,6 +282,11 @@ preferredTimeline model =
LocalTimelineView LocalTimelineView
truncate : List a -> List a
truncate entries =
List.take maxBuffer entries
accountMentioned : Mastodon.Model.Account -> Mastodon.Model.Mention -> Bool accountMentioned : Mastodon.Model.Account -> Mastodon.Model.Mention -> Bool
accountMentioned { acct, username } mention = accountMentioned { acct, username } mention =
acct == mention.acct && username == mention.username acct == mention.acct && username == mention.username
@ -581,7 +592,7 @@ processWebSocketMsg msg model =
Mastodon.WebSocket.StatusUpdateEvent result -> Mastodon.WebSocket.StatusUpdateEvent result ->
case result of case result of
Ok status -> Ok status ->
{ model | userTimeline = status :: model.userTimeline } ! [] { model | userTimeline = truncate (status :: model.userTimeline) } ! []
Err error -> Err error ->
{ model | errors = error :: model.errors } ! [] { model | errors = error :: model.errors } ! []
@ -603,7 +614,7 @@ processWebSocketMsg msg model =
notification notification
model.notifications model.notifications
in in
{ model | notifications = notifications } ! [] { model | notifications = truncate notifications } ! []
Err error -> Err error ->
{ model | errors = error :: model.errors } ! [] { model | errors = error :: model.errors } ! []
@ -616,7 +627,7 @@ processWebSocketMsg msg model =
Mastodon.WebSocket.StatusUpdateEvent result -> Mastodon.WebSocket.StatusUpdateEvent result ->
case result of case result of
Ok status -> Ok status ->
{ model | localTimeline = status :: model.localTimeline } ! [] { model | localTimeline = truncate (status :: model.localTimeline) } ! []
Err error -> Err error ->
{ model | errors = error :: model.errors } ! [] { model | errors = error :: model.errors } ! []
@ -640,7 +651,7 @@ processWebSocketMsg msg model =
Mastodon.WebSocket.StatusUpdateEvent result -> Mastodon.WebSocket.StatusUpdateEvent result ->
case result of case result of
Ok status -> Ok status ->
{ model | globalTimeline = status :: model.globalTimeline } ! [] { model | globalTimeline = truncate (status :: model.globalTimeline) } ! []
Err error -> Err error ->
{ model | errors = error :: model.errors } ! [] { model | errors = error :: model.errors } ! []