FEATURE: go to inbox after archiving a message

This commit is contained in:
Sam 2016-01-12 15:49:05 +11:00
parent 06b5798fb9
commit 65e808b26d
3 changed files with 40 additions and 7 deletions

View File

@ -6,6 +6,7 @@ import Quote from 'discourse/lib/quote';
import { popupAjaxError } from 'discourse/lib/ajax-error';
import computed from 'ember-addons/ember-computed-decorators';
import Composer from 'discourse/models/composer';
import DiscourseURL from 'discourse/lib/url';
export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
needs: ['header', 'modal', 'composer', 'quote-button', 'topic-progress', 'application'],
@ -96,6 +97,14 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
return !isPrivateMessage && !containsMessages;
},
gotoInbox(name) {
var url = '/users/' + this.get('currentUser.username_lower') + '/messages';
if (name) {
url = url + '/group/' + name;
}
DiscourseURL.routeTo(url);
},
actions: {
showTopicAdminMenu() {
this.set('adminMenuVisible', true);
@ -109,12 +118,19 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
this.deleteTopic();
},
archiveMessage() {
this.get('model').archiveMessage();
const topic = this.get('model');
topic.archiveMessage().then(()=>{
this.gotoInbox(topic.get("inboxGroupName"));
});
},
moveToInbox() {
this.get('model').moveToInbox();
const topic = this.get('model');
topic.moveToInbox().then(()=>{
this.gotoInbox(topic.get("inboxGroupName"));
});
},
// Post related methods

View File

@ -424,8 +424,12 @@ const Topic = RestModel.extend({
this.set("archiving", true);
var promise = Discourse.ajax(`/t/${this.get('id')}/archive-message`, {type: 'PUT'});
promise.then(()=>this.set('message_archived', true))
.finally(()=>this.set('archiving', false));
promise.then((msg)=> {
this.set('message_archived', true);
if (msg && msg.group_name) {
this.set('inboxGroupName', msg.group_name);
}
}).finally(()=>this.set('archiving', false));
return promise;
},
@ -434,8 +438,12 @@ const Topic = RestModel.extend({
this.set("archiving", true);
var promise = Discourse.ajax(`/t/${this.get('id')}/move-to-inbox`, {type: 'PUT'});
promise.then(()=>this.set('message_archived', false))
.finally(()=>this.set('archiving', false));
promise.then((msg)=> {
this.set('message_archived', false);
if (msg && msg.group_name) {
this.set('inboxGroupName', msg.group_name);
}
}).finally(()=>this.set('archiving', false));
return promise;
}

View File

@ -281,6 +281,9 @@ class TopicsController < ApplicationController
def toggle_archive_message(archive)
topic = Topic.find(params[:id].to_i)
group_id = nil
group_ids = current_user.groups.pluck(:id)
if group_ids.present?
allowed_groups = topic.allowed_groups
@ -289,6 +292,7 @@ class TopicsController < ApplicationController
GroupArchivedMessage.where(group_id: id, topic_id: topic.id).destroy_all
if archive
group_id = id
GroupArchivedMessage.create!(group_id: id, topic_id: topic.id)
end
end
@ -302,7 +306,12 @@ class TopicsController < ApplicationController
end
end
render nothing: true
if group_id
name = Group.find_by(id: group_id).try(:name)
render_json_dump(group_name: name)
else
render nothing: true
end
end
def bookmark