if chat errors don't keep trying to get more chat messages

causes loop which is why we have so many sentury errors
This commit is contained in:
Henry Oswald 2015-01-26 15:36:34 +00:00
parent 90bb12db40
commit b06c9f509e
2 changed files with 10 additions and 6 deletions

View file

@ -4,7 +4,7 @@ aside.chat(
)
.messages(
infinite-scroll="loadMoreMessages()"
infinite-scroll-disabled="chat.loading || chat.atEnd"
infinite-scroll-disabled="chat.loading || chat.atEnd || chat.errored"
infinite-scroll-initialize="ui.chatOpen"
infinite-scroll-upwards="true"
update-scroll-bottom-on="updateScrollPosition"

View file

@ -11,6 +11,7 @@ define [
messages: []
loading: false
atEnd: false
errored:false
nextBeforeTimestamp: null
newMessage: null
}
@ -38,11 +39,10 @@ define [
chat.loadMoreMessages = () ->
return if chat.state.atEnd
return if chat.state.errored
url = MESSAGES_URL + "?limit=#{MESSAGE_LIMIT}"
if chat.state.nextBeforeTimestamp?
url += "&before=#{chat.state.nextBeforeTimestamp}"
chat.state.loading = true
return $http
.get(url)
@ -52,9 +52,13 @@ define [
chat.state.atEnd = true
if !messages.reverse?
Raven?.captureException(new Error("messages has no reverse property #{JSON.stringify(messages)}"))
messages.reverse()
prependMessages(messages)
chat.state.nextBeforeTimestamp = chat.state.messages[0]?.timestamp
if typeof messages.reverse isnt 'function'
Raven?.captureException(new Error("messages.reverse not a function #{typeof(messages.reverse)} #{JSON.stringify(messages)}"))
chat.state.errored = true
else
messages.reverse()
prependMessages(messages)
chat.state.nextBeforeTimestamp = chat.state.messages[0]?.timestamp
TIMESTAMP_GROUP_SIZE = 5 * 60 * 1000 # 5 minutes