Make replyAction into a promise. closes #100

This commit is contained in:
Toby Zerner 2015-06-01 10:29:01 +09:30
parent 8d7a6985ba
commit c3c2978fc1
3 changed files with 35 additions and 19 deletions

View File

@ -88,7 +88,7 @@ export default class DiscussionPage extends mixin(Component, evented) {
this.stream.on('positionChanged', this.positionChanged.bind(this)); this.stream.on('positionChanged', this.positionChanged.bind(this));
this.stream.goToNumber(m.route.param('near') || 1, true); this.stream.goToNumber(m.route.param('near') || 1, true);
this.trigger('loaded'); this.trigger('loaded', discussion);
} }
onload(element, isInitialized, context) { onload(element, isInitialized, context) {

View File

@ -60,7 +60,7 @@ export default class LoginModal extends FormModal {
app.session.login(email, password).then(() => { app.session.login(email, password).then(() => {
this.hide(); this.hide();
this.props.callback && this.props.callback(); this.props.onlogin && this.props.onlogin();
}, response => { }, response => {
this.loading(false); this.loading(false);
if (response && response.code === 'confirm_email') { if (response && response.code === 'confirm_email') {

View File

@ -8,12 +8,16 @@ import ItemList from 'flarum/utils/item-list';
export default function(app) { export default function(app) {
Discussion.prototype.replyAction = function(goToLast, forceRefresh) { Discussion.prototype.replyAction = function(goToLast, forceRefresh) {
if (app.session.user() && this.canReply()) { var deferred = m.deferred();
if (goToLast && app.current.discussion && app.current.discussion().id() === this.id()) {
var reply = () => {
if (this.canReply()) {
if (goToLast && app.viewingDiscussion(this)) {
app.current.stream.goToLast(); app.current.stream.goToLast();
} }
var component = app.composer.component; var component = app.composer.component;
if (!(component instanceof ReplyComposer) || component.props.discussion !== this || component.props.user !== app.session.user() || forceRefresh) { if (!app.composingReplyTo(this) || forceRefresh) {
component = new ReplyComposer({ component = new ReplyComposer({
user: app.session.user(), user: app.session.user(),
discussion: this discussion: this
@ -21,12 +25,24 @@ export default function(app) {
app.composer.load(component); app.composer.load(component);
} }
app.composer.show(goToLast); app.composer.show(goToLast);
return component;
} else if (!app.session.user()) { deferred.resolve(component);
app.modal.show(new LoginModal({ } else {
callback: () => app.current.one('loaded', this.replyAction.bind(this, goToLast, forceRefresh)) deferred.reject();
}));
} }
};
if (app.session.user()) {
reply();
} else {
app.modal.show(
new LoginModal({
onlogin: () => app.current.one('loaded', reply)
})
);
}
return deferred.promise;
} }
Discussion.prototype.deleteAction = function() { Discussion.prototype.deleteAction = function() {