FEATURE: when PMing a user from the topic page, insert a link to the current post
This commit is contained in:
parent
3614038a5d
commit
206d3233c9
|
@ -371,7 +371,6 @@ export default DiscourseController.extend({
|
|||
// If it's the same draft, just open it up again.
|
||||
if (composerModel.get('composeState') === Discourse.Composer.DRAFT &&
|
||||
composerModel.get('draftKey') === opts.draftKey) {
|
||||
|
||||
composerModel.set('composeState', Discourse.Composer.OPEN);
|
||||
return resolve();
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ export default ObjectController.extend({
|
|||
avatar: null,
|
||||
userLoading: null,
|
||||
cardTarget: null,
|
||||
post: null,
|
||||
|
||||
postStream: Em.computed.alias('controllers.topic.postStream'),
|
||||
enoughPostsForFiltering: Em.computed.gte('participant.post_count', 2),
|
||||
|
@ -31,7 +32,7 @@ export default ObjectController.extend({
|
|||
return img && img.indexOf('fa-') !== 0;
|
||||
}.property('user.card_badge.image'),
|
||||
|
||||
show: function(username, target) {
|
||||
show: function(username, postId, target) {
|
||||
// XSS protection (should be encapsulated)
|
||||
username = username.toString().replace(/[^A-Za-z0-9_]/g, "");
|
||||
var url = "/users/" + username;
|
||||
|
@ -43,14 +44,14 @@ export default ObjectController.extend({
|
|||
}
|
||||
|
||||
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.set('username', username);
|
||||
this.setProperties({ avatar: null, post: post, username: username });
|
||||
|
||||
// If we click the avatar again, close it (unless its diff element on the screen).
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -67,11 +68,9 @@ export default ObjectController.extend({
|
|||
this.set('participant', participants.findBy('username', username));
|
||||
}
|
||||
|
||||
var self = this;
|
||||
self.set('user', null);
|
||||
self.set('userLoading', username);
|
||||
self.set('cardTarget', target);
|
||||
this.setProperties({ user: null, userLoading: username, cardTarget: target });
|
||||
|
||||
var self = this;
|
||||
Discourse.User.findByUsername(username).then(function (user) {
|
||||
user = Discourse.User.create(user);
|
||||
self.setProperties({ user: user, avatar: user, visible: true});
|
||||
|
@ -82,8 +81,7 @@ export default ObjectController.extend({
|
|||
},
|
||||
|
||||
close: function() {
|
||||
this.set('visible', false);
|
||||
this.set('cardTarget', null);
|
||||
this.setProperties({ visible: false, cardTarget: null });
|
||||
},
|
||||
|
||||
actions: {
|
||||
|
|
|
@ -25,10 +25,10 @@ const ApplicationRoute = Discourse.Route.extend({
|
|||
this.controllerFor('topic-entrance').send('show', data);
|
||||
},
|
||||
|
||||
composePrivateMessage(user) {
|
||||
composePrivateMessage(user, post) {
|
||||
const self = this;
|
||||
this.transitionTo('userActivity', user).then(function () {
|
||||
self.controllerFor('user-activity').send('composePrivateMessage', user);
|
||||
self.controllerFor('user-activity').send('composePrivateMessage', user, post);
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -15,13 +15,16 @@ export default Discourse.Route.extend({
|
|||
Discourse.logout();
|
||||
},
|
||||
|
||||
composePrivateMessage: function(user) {
|
||||
var recipient = user ? user.get('username') : '';
|
||||
composePrivateMessage: function(user, post) {
|
||||
var recipient = user ? user.get('username') : '',
|
||||
reply = post ? window.location.protocol + "//" + window.location.host + post.get("url") : null
|
||||
|
||||
return this.controllerFor('composer').open({
|
||||
action: Discourse.Composer.PRIVATE_MESSAGE,
|
||||
usernames: recipient,
|
||||
archetypeId: 'private_message',
|
||||
draftKey: 'new_private_message'
|
||||
draftKey: 'new_private_message',
|
||||
reply: reply
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
<ul class="usercard-controls">
|
||||
{{#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 showFilter}}
|
||||
|
|
|
@ -43,8 +43,9 @@ export default Discourse.View.extend(CleansUp, {
|
|||
});
|
||||
|
||||
var expand = function(username, $target){
|
||||
var postId = $target.parents('article').data('post-id');
|
||||
self._willShow($target);
|
||||
self.get('controller').show(username, $target[0]);
|
||||
self.get('controller').show(username, postId, $target[0]);
|
||||
return false;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue