conversations: fix recipient pagination caching

fixes CNVS-11199

test plan:
  * open conversations as a user who can message
      more than twenty other users
  * open compose dialog
  * open recipients browser
  * open context with many users and scroll down
  * verify that all users load
  * close and re-open recipients browser
  * verify that all users are still present

Change-Id: Ibeefddc92f49cc52195336eee50d7213e8717d12
Reviewed-on: https://gerrit.instructure.com/36381
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Joel Hough <joel@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Braden Anderson <braden@instructure.com>
This commit is contained in:
Braden Anderson 2014-06-12 17:33:02 -06:00 committed by Braden Anderson
parent b995981ccc
commit 5bd46c8f39
3 changed files with 27 additions and 18 deletions

View File

@ -97,11 +97,19 @@ define [
# @api private
attachCollection: ->
@collection.on 'reset', @renderOnReset
@collection.on 'add', @renderOnAdd
@collection.on 'remove', @removeItem
@listenTo @collection, 'reset', @renderOnReset
@listenTo @collection, 'add', @renderOnAdd
@listenTo @collection, 'remove', @removeItem
@empty = not @collection.length
detachCollection: ->
@stopListening @collection
switchCollection: (collection) ->
@detachCollection()
@collection = collection
@attachCollection()
##
# Ensures item views are removed properly
#

View File

@ -62,13 +62,13 @@ define [
attachCollection: ->
super
@collection.on 'reset', @attachScroll
@collection.on 'fetched:last', @detachScroll
@collection.on 'beforeFetch', @showLoadingIndicator
@listenTo @collection, 'reset', @attachScroll
@listenTo @collection, 'fetched:last', @detachScroll
@listenTo @collection, 'beforeFetch', @showLoadingIndicator
if @autoFetch
@collection.on 'fetch', => setTimeout @checkScroll # next tick so events don't stomp on each other
@listenTo @collection, 'fetch', => setTimeout @checkScroll # next tick so events don't stomp on each other
else
@collection.on 'fetch', @hideLoadingIndicator
@listenTo @collection, 'fetch', @hideLoadingIndicator
##
# Sets instance properties regarding the scrollContainer

View File

@ -112,12 +112,11 @@ define [
@$span = @_initializeWidthSpan()
setTimeout((=> @_disable() if @options.disabled), 0)
@_fetchResults = _.debounce(@__fetchResults, 250)
@resultCollection = new PaginatedCollection([], model: ConversationSearchResult)
@resultView = new PaginatedCollectionView
el: @$resultContents
scrollContainer: @$resultContainer
buffer: 50
collection: @resultCollection
collection: new Backbone.Collection()
template: null
itemView: Backbone.View.extend
template: resultTemplate
@ -135,14 +134,14 @@ define [
id: "result-#{$.guid++}" # for aria-activedescendant
attributes['aria-haspopup'] = @model.get('isContext')
attributes
@_attachCollection()
# Internal: Manage events on the results collection.
#
# Returns nothing.
_attachCollection: ->
@resultCollection.off('reset', @resultView.renderOnReset)
@resultCollection.off('remove', @resultView.removeItem)
@resultView.switchCollection(@resultCollection)
@resultView.stopListening(@resultCollection, 'reset', @resultView.renderOnReset)
@resultView.stopListening(@resultCollection, 'remove', @resultView.removeItem)
# Public: Toggle visibility of result list.
#
@ -270,7 +269,6 @@ define [
#
# Returns nothing.
_onSearchResultLoad: =>
@cache[@currentUrl] = @resultCollection.toJSON()
_.extend(@permissions, @_getPermissions())
@_addEveryoneResult(@resultCollection) unless @excludeAll or !@_canSendToAll()
@resultCollection.each @_addToModelCache
@ -359,13 +357,16 @@ define [
return unless url
@currentUrl = url
if @cache[url]
@resultCollection.reset(@cache[url])
@resultCollection = @cache[url]
@_attachCollection()
@toggleResultList(true)
@_onSearchResultLoad()
else
@currentRequest = @resultCollection.fetch
url: @url(@$input.val())
success: @_onSearchResultLoad
@resultCollection = new PaginatedCollection([], model: ConversationSearchResult)
@resultCollection.url = url
@cache[url] = @resultCollection
@_attachCollection()
@currentRequest = @resultCollection.fetch().done(@_onSearchResultLoad)
@toggleResultList(true)
# Internal: Get URL for the current request, caching it as