FEATURE: when PMing a user from the topic page, insert a link to the current post

This commit is contained in:
Régis Hanol 2015-02-18 12:17:54 +01:00
parent 3614038a5d
commit 206d3233c9
6 changed files with 20 additions and 19 deletions

View File

@ -371,7 +371,6 @@ export default DiscourseController.extend({
// If it's the same draft, just open it up again. // If it's the same draft, just open it up again.
if (composerModel.get('composeState') === Discourse.Composer.DRAFT && if (composerModel.get('composeState') === Discourse.Composer.DRAFT &&
composerModel.get('draftKey') === opts.draftKey) { composerModel.get('draftKey') === opts.draftKey) {
composerModel.set('composeState', Discourse.Composer.OPEN); composerModel.set('composeState', Discourse.Composer.OPEN);
return resolve(); return resolve();
} }

View File

@ -9,6 +9,7 @@ export default ObjectController.extend({
avatar: null, avatar: null,
userLoading: null, userLoading: null,
cardTarget: null, cardTarget: null,
post: null,
postStream: Em.computed.alias('controllers.topic.postStream'), postStream: Em.computed.alias('controllers.topic.postStream'),
enoughPostsForFiltering: Em.computed.gte('participant.post_count', 2), enoughPostsForFiltering: Em.computed.gte('participant.post_count', 2),
@ -31,7 +32,7 @@ export default ObjectController.extend({
return img && img.indexOf('fa-') !== 0; return img && img.indexOf('fa-') !== 0;
}.property('user.card_badge.image'), }.property('user.card_badge.image'),
show: function(username, target) { show: function(username, postId, target) {
// XSS protection (should be encapsulated) // XSS protection (should be encapsulated)
username = username.toString().replace(/[^A-Za-z0-9_]/g, ""); username = username.toString().replace(/[^A-Za-z0-9_]/g, "");
var url = "/users/" + username; var url = "/users/" + username;
@ -43,14 +44,14 @@ export default ObjectController.extend({
} }
var currentUsername = this.get('username'), var currentUsername = this.get('username'),
wasVisible = this.get('visible'); wasVisible = this.get('visible'),
post = this.get('viewingTopic') && postId ? this.get('controllers.topic.postStream').findLoadedPost(postId) : null;
this.set('avatar', null); this.setProperties({ avatar: null, post: post, username: username });
this.set('username', username);
// If we click the avatar again, close it (unless its diff element on the screen). // If we click the avatar again, close it (unless its diff element on the screen).
if (target === this.get('cardTarget') && wasVisible) { if (target === this.get('cardTarget') && wasVisible) {
this.setProperties({ visible: false, username: null, avatar: null, cardTarget: null }); this.setProperties({ visible: false, username: null, cardTarget: null });
return; return;
} }
@ -67,11 +68,9 @@ export default ObjectController.extend({
this.set('participant', participants.findBy('username', username)); this.set('participant', participants.findBy('username', username));
} }
var self = this; this.setProperties({ user: null, userLoading: username, cardTarget: target });
self.set('user', null);
self.set('userLoading', username);
self.set('cardTarget', target);
var self = this;
Discourse.User.findByUsername(username).then(function (user) { Discourse.User.findByUsername(username).then(function (user) {
user = Discourse.User.create(user); user = Discourse.User.create(user);
self.setProperties({ user: user, avatar: user, visible: true}); self.setProperties({ user: user, avatar: user, visible: true});
@ -82,8 +81,7 @@ export default ObjectController.extend({
}, },
close: function() { close: function() {
this.set('visible', false); this.setProperties({ visible: false, cardTarget: null });
this.set('cardTarget', null);
}, },
actions: { actions: {

View File

@ -25,10 +25,10 @@ const ApplicationRoute = Discourse.Route.extend({
this.controllerFor('topic-entrance').send('show', data); this.controllerFor('topic-entrance').send('show', data);
}, },
composePrivateMessage(user) { composePrivateMessage(user, post) {
const self = this; const self = this;
this.transitionTo('userActivity', user).then(function () { this.transitionTo('userActivity', user).then(function () {
self.controllerFor('user-activity').send('composePrivateMessage', user); self.controllerFor('user-activity').send('composePrivateMessage', user, post);
}); });
}, },

View File

@ -15,13 +15,16 @@ export default Discourse.Route.extend({
Discourse.logout(); Discourse.logout();
}, },
composePrivateMessage: function(user) { composePrivateMessage: function(user, post) {
var recipient = user ? user.get('username') : ''; var recipient = user ? user.get('username') : '',
reply = post ? window.location.protocol + "//" + window.location.host + post.get("url") : null
return this.controllerFor('composer').open({ return this.controllerFor('composer').open({
action: Discourse.Composer.PRIVATE_MESSAGE, action: Discourse.Composer.PRIVATE_MESSAGE,
usernames: recipient, usernames: recipient,
archetypeId: 'private_message', archetypeId: 'private_message',
draftKey: 'new_private_message' draftKey: 'new_private_message',
reply: reply
}); });
}, },

View File

@ -24,7 +24,7 @@
<ul class="usercard-controls"> <ul class="usercard-controls">
{{#if user.can_send_private_message_to_user}} {{#if user.can_send_private_message_to_user}}
<li><a class='btn btn-primary' {{action "composePrivateMessage" user}}>{{fa-icon "envelope"}}{{i18n 'user.private_message'}}</a></li> <li><a class='btn btn-primary' {{action "composePrivateMessage" user post}}>{{fa-icon "envelope"}}{{i18n 'user.private_message'}}</a></li>
{{/if}} {{/if}}
{{#if showFilter}} {{#if showFilter}}

View File

@ -43,8 +43,9 @@ export default Discourse.View.extend(CleansUp, {
}); });
var expand = function(username, $target){ var expand = function(username, $target){
var postId = $target.parents('article').data('post-id');
self._willShow($target); self._willShow($target);
self.get('controller').show(username, $target[0]); self.get('controller').show(username, postId, $target[0]);
return false; return false;
}; };