Fix crash when displaying a discussion with no posts. closes #823

This commit is contained in:
Toby Zerner 2016-02-22 22:22:49 +10:30
parent 7b0c318dc9
commit 61a0523e12
4 changed files with 13 additions and 7 deletions

View File

@ -22244,9 +22244,11 @@ System.register('flarum/models/Discussion', ['flarum/Model', 'flarum/utils/mixin
* @public
*/
postIds: function postIds() {
return this.data.relationships.posts.data.map(function (link) {
var posts = this.data.relationships.posts;
return posts ? posts.data.map(function (link) {
return link.id;
});
}) : [];
}
});

View File

@ -21928,7 +21928,7 @@ System.register('flarum/components/DiscussionPage', ['flarum/components/Page', '
// the specific post that was routed to.
this.stream = new PostStream({ discussion: discussion, includedPosts: includedPosts });
this.stream.on('positionChanged', this.positionChanged.bind(this));
this.stream.goToNumber(m.route.param('near') || includedPosts[0].number(), true);
this.stream.goToNumber(m.route.param('near') || includedPosts[0] && includedPosts[0].number(), true);
}
/**
@ -31433,9 +31433,11 @@ System.register('flarum/models/Discussion', ['flarum/Model', 'flarum/utils/mixin
* @public
*/
postIds: function postIds() {
return this.data.relationships.posts.data.map(function (link) {
var posts = this.data.relationships.posts;
return posts ? posts.data.map(function (link) {
return link.id;
});
}) : [];
}
});

View File

@ -184,7 +184,7 @@ export default class DiscussionPage extends Page {
// the specific post that was routed to.
this.stream = new PostStream({discussion, includedPosts});
this.stream.on('positionChanged', this.positionChanged.bind(this));
this.stream.goToNumber(m.route.param('near') || includedPosts[0].number(), true);
this.stream.goToNumber(m.route.param('near') || (includedPosts[0] && includedPosts[0].number()), true);
}
/**

View File

@ -98,7 +98,9 @@ Object.assign(Discussion.prototype, {
* @public
*/
postIds() {
return this.data.relationships.posts.data.map(link => link.id);
const posts = this.data.relationships.posts;
return posts ? posts.data.map(link => link.id) : [];
}
});