Commit fe0250ca authored by Nick Stenning's avatar Nick Stenning

Fix standalone reply pages

This commit is a partial revert of 4628b26, affecting standalone
annotation pages only.

That commit changed the AnnotationViewerController (the component
responsible for standalone annotation pages) to make a single request to
the search API to load an annotation and all its replies, rather than
two requests -- for the annotation and then for its replies.

This works just fine so long as the top-level annotation is not itself a
reply. In that case, however, the search endpoint returns nothing, as
the (temporary) `_separate_replies` parameter ensures that only
top-level annotations are matched.

This commit switches back to making two requests to populate the
client-side data structures for the standalone annotation page:

1. To fetch the annotation referenced in the URL (which may itself be a
   reply).
2. To fetch any replies to the annotation referenced in the URL.

Fixes #2775.
parent 84a34b21
......@@ -19,14 +19,13 @@ module.exports = class AnnotationViewerController
$scope.search.update = (query) ->
$location.path('/stream').search('q', query)
search_params = {
_id: id,
_separate_replies: true
}
store.SearchResource.get(search_params, ({rows, replies}) ->
annotationMapper.loadAnnotations(rows, replies)
store.AnnotationResource.get({id: id}, (annotation) ->
annotationMapper.loadAnnotations([annotation])
$scope.threadRoot = {children: [threading.idTable[id]]}
)
store.SearchResource.get({references: id}, ({rows}) ->
annotationMapper.loadAnnotations(rows)
)
streamFilter
.setMatchPolicyIncludeAny()
......
......@@ -33,7 +33,9 @@ describe "AnnotationViewerController", ->
}
streamer: streamer or {setConfig: ->}
store: store or {
SearchResource: {get: sinon.spy()}}
AnnotationResource: {get: sinon.spy()}
SearchResource: {get: sinon.spy()}
}
streamFilter: streamFilter or {
setMatchPolicyIncludeAny: -> {addClause: -> {addClause: ->}}
getFilter: ->
......@@ -45,31 +47,29 @@ describe "AnnotationViewerController", ->
"AnnotationViewerController", locals)
return locals
it "calls the search API to get the annotation and its replies", ->
it "fetches the top-level annotation", ->
{store} = createAnnotationViewerController({})
assert.calledOnce(store.AnnotationResource.get)
assert.calledWith(store.AnnotationResource.get, {id: "test_annotation_id"})
it "fetches any replies referencing the top-level annotation", ->
{store} = createAnnotationViewerController({})
assert store.SearchResource.get.calledOnce
assert store.SearchResource.get.calledWith(
{_id: "test_annotation_id", _separate_replies: true})
assert.calledOnce(store.SearchResource.get)
assert.calledWith(store.SearchResource.get, {references: "test_annotation_id"})
it "loads the top-level annotation and replies into annotationMapper", ->
{annotationMapper} = createAnnotationViewerController({})
it "passes the annotations and replies from search into loadAnnotations", ->
getAnnotation = sinon.stub().callsArgWith(1, {id: 'foo'})
getReferences = sinon.stub().callsArgWith(1, {rows: [{id: 'bar'}, {id: 'baz'}]})
{annotationMapper} = createAnnotationViewerController({
store: {
SearchResource: {
# SearchResource.get(id, func) takes an annotation id and a function
# that it should call with the search result. Our mock .get() here
# just immediately calls the function with some fake results.
get: (id, func) ->
func(
{
# In production these would be annotation objects, not strings.
rows: ['annotation_1', 'annotation_2']
replies: ['reply_1', 'reply_2', 'reply_3']
}
)
}
AnnotationResource: {get: getAnnotation}
SearchResource: {get: getReferences}
}
})
assert annotationMapper.loadAnnotations.calledWith(
['annotation_1', 'annotation_2'], ['reply_1', 'reply_2', 'reply_3']
), "It should pass all the annotations and replies to loadAnnotations()"
assert.calledWith(annotationMapper.loadAnnotations, [{id: 'foo'}])
assert.calledWith(annotationMapper.loadAnnotations, [{id: 'bar'}, {id: 'baz'}])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment