Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Commit fe3693c

Browse files
committed
Merge branch 'master' of github.com:discourse/discourse
2 parents e8ef55c + def4f15 commit fe3693c

20 files changed

+77
-57
lines changed

app/assets/javascripts/discourse.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -229,21 +229,3 @@ Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
229229

230230
Discourse.Router = Discourse.Router.reopen({ location: 'discourse_location' });
231231

232-
Discourse.initializer({
233-
name: 'currentUser',
234-
235-
initialize: function(container) {
236-
container.register('user:current', Discourse.User.current(), { instantiate: false });
237-
}
238-
});
239-
240-
Discourse.initializer({
241-
name: 'injectCurrentUser',
242-
243-
initialize: function(container) {
244-
if (container.lookup('user:current')) {
245-
container.injection('controller', 'currentUser', 'user:current');
246-
container.injection('route', 'currentUser', 'user:current');
247-
}
248-
}
249-
});

app/assets/javascripts/discourse/controllers/composer_controller.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Discourse.ComposerController = Discourse.Controller.extend({
103103
opts = opts || {};
104104
composerController.close();
105105

106-
var currentUser = this.get('currentUser');
106+
var currentUser = Discourse.User.current();
107107
if (composer.get('creatingTopic')) {
108108
currentUser.set('topic_count', currentUser.get('topic_count') + 1);
109109
} else {
@@ -198,6 +198,9 @@ Discourse.ComposerController = Discourse.Controller.extend({
198198
open: function(opts) {
199199
if (!opts) opts = {};
200200

201+
var composerMessages = this.get('controllers.composerMessages');
202+
composerMessages.reset();
203+
201204
var promise = opts.promise || Ember.Deferred.create();
202205
opts.promise = promise;
203206
this.set('typedReply', false);

app/assets/javascripts/discourse/controllers/composer_messages_controller.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ Discourse.ComposerMessagesController = Ember.ArrayController.extend({
2626

2727
closeMessage: function(message) {
2828
this.removeObject(message);
29+
},
30+
31+
reset: function() {
32+
this.clear();
33+
this.set('messagesByTemplate', {});
2934
}
3035

3136
});

app/assets/javascripts/discourse/controllers/controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
@uses Discourse.Presence
88
@module Discourse
99
**/
10-
Discourse.Controller = Ember.Controller.extend(Discourse.Presence);
10+
Discourse.Controller = Ember.Controller.extend(Discourse.Presence, Discourse.HasCurrentUser);

app/assets/javascripts/discourse/controllers/header_controller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ Discourse.HeaderController = Discourse.Controller.extend({
2121
}.property(),
2222

2323
showFavoriteButton: function() {
24-
return this.get('currentUser') && !this.get('topic.isPrivateMessage');
25-
}.property('currentUser', 'topic.isPrivateMessage'),
24+
return Discourse.User.current() && !this.get('topic.isPrivateMessage');
25+
}.property('topic.isPrivateMessage'),
2626

2727
mobileDevice: function() {
2828
return Discourse.Mobile.isMobileDevice;

app/assets/javascripts/discourse/controllers/list_controller.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Discourse.ListController = Discourse.Controller.extend({
1313
needs: ['composer', 'modal', 'listTopics'],
1414

1515
availableNavItems: function() {
16-
var loggedOn = !!this.get('currentUser');
16+
var loggedOn = !!Discourse.User.current();
1717

1818
return Discourse.SiteSettings.top_menu.split("|").map(function(i) {
1919
return Discourse.NavItem.fromText(i, {
@@ -22,7 +22,7 @@ Discourse.ListController = Discourse.Controller.extend({
2222
}).filter(function(i) {
2323
return i !== null;
2424
});
25-
}.property('currentUser'),
25+
}.property(),
2626

2727
createTopicText: function() {
2828
if (this.get('category.name')) {
@@ -125,12 +125,12 @@ Discourse.ListController = Discourse.Controller.extend({
125125

126126
canEditCategory: function() {
127127
if( this.present('category') ) {
128-
var u = this.get('currentUser');
128+
var u = Discourse.User.current();
129129
return u && u.staff;
130130
} else {
131131
return false;
132132
}
133-
}.property('currentUser', 'category')
133+
}.property('category')
134134

135135
});
136136

app/assets/javascripts/discourse/controllers/object_controller.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
@uses Discourse.Presence
88
@module Discourse
99
**/
10-
Discourse.ObjectController = Ember.ObjectController.extend(Discourse.Presence);
10+
Discourse.ObjectController = Ember.ObjectController.extend(Discourse.Presence, Discourse.HasCurrentUser);
11+
12+

app/assets/javascripts/discourse/controllers/quote_button_controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Discourse.QuoteButtonController = Discourse.Controller.extend({
3131
**/
3232
selectText: function(postId) {
3333
// anonymous users cannot "quote-reply"
34-
if (!this.get('currentUser')) return;
34+
if (!Discourse.User.current()) return;
3535

3636
// don't display the "quote-reply" button if we can't create a post
3737
if (!this.get('controllers.topic.model.details.can_create_post')) return;

app/assets/javascripts/discourse/controllers/topic_controller.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,16 +260,16 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
260260
},
261261

262262
showFavoriteButton: function() {
263-
return this.get('currentUser') && !this.get('isPrivateMessage');
264-
}.property('currentUser', 'isPrivateMessage'),
263+
return Discourse.User.current() && !this.get('isPrivateMessage');
264+
}.property('isPrivateMessage'),
265265

266266
recoverTopic: function() {
267267
this.get('content').recover();
268268
},
269269

270270
deleteTopic: function() {
271271
this.unsubscribe();
272-
this.get('content').destroy(this.get('currentUser'));
272+
this.get('content').destroy(Discourse.User.current());
273273
},
274274

275275
resetRead: function() {
@@ -417,7 +417,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
417417
},
418418

419419
toggleBookmark: function(post) {
420-
if (!this.get('currentUser')) {
420+
if (!Discourse.User.current()) {
421421
alert(I18n.t("bookmarks.not_bookmarked"));
422422
return;
423423
}
@@ -439,7 +439,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
439439
},
440440

441441
deletePost: function(post) {
442-
var user = this.get('currentUser'),
442+
var user = Discourse.User.current(),
443443
replyCount = post.get('reply_count'),
444444
self = this;
445445

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
This mixin provides a `currentUser` property that can be used to retrieve information
3+
about the currently logged in user. It is mostly useful to controllers so it can be
4+
exposted to templates.
5+
6+
Outside of templates, code should probably use `Discourse.User.current()` instead of
7+
this property.
8+
9+
@class Discourse.HasCurrentUser
10+
@extends Ember.Mixin
11+
@namespace Discourse
12+
@module HasCurrentUser
13+
**/
14+
Discourse.HasCurrentUser = Em.Mixin.create({
15+
16+
/**
17+
Returns a reference to the currently logged in user.
18+
19+
@method currentUser
20+
@return {Discourse.User} the currently logged in user if present.
21+
*/
22+
currentUser: function() {
23+
return Discourse.User.current();
24+
}.property().volatile()
25+
26+
});
27+
28+
29+
30+
31+

app/assets/javascripts/discourse/routes/user_routes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Discourse.UserRoute = Discourse.Route.extend({
1212

1313
// If we're viewing the currently logged in user, return that object
1414
// instead.
15-
var currentUser = this.get('currentUser');
15+
var currentUser = Discourse.User.current();
1616
if (currentUser && (params.username.toLowerCase() === currentUser.get('username_lower'))) {
1717
return currentUser;
1818
}
@@ -95,7 +95,7 @@ Discourse.UserActivityRoute = Discourse.Route.extend({
9595

9696
var composerController = this.controllerFor('composer');
9797
controller.set('model', user);
98-
if (this.get('currentUser')) {
98+
if (Discourse.User.current()) {
9999
Discourse.Draft.get('new_private_message').then(function(data) {
100100
if (data.draft) {
101101
composerController.open({

app/assets/javascripts/discourse/templates/topic.js.handlebars

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@
125125
</div>
126126

127127
{{render share}}
128-
{{render quoteButton}}
128+
{{#if currentUser.enable_quoting}}
129+
{{render quoteButton}}
130+
{{/if}}
129131

130132
{{#if currentUser.staff}}
131133
{{render topicAdminMenu content}}

app/assets/javascripts/discourse/views/quote_button_view.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ Discourse.QuoteButtonView = Discourse.View.extend({
4747
.on("mousedown.quote-button", function(e) {
4848
view.set('isMouseDown', true);
4949
if ($(e.target).hasClass('quote-button') || $(e.target).hasClass('create')) return;
50-
// do *not* deselect when quoting has been disabled by the user
51-
if (!Discourse.User.currentProp('enable_quoting')) return;
5250
// deselects only when the user left click
5351
// (allows anyone to `extend` their selection using shift+click)
5452
if (e.which === 1 && !e.shiftKey) controller.deselectText();

app/assets/stylesheets/mobile/compose.css.scss

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,8 @@ div.ac-wrap {
381381
}
382382
}
383383
.wmd-controls {
384-
left: 30px;
385-
right: 30px;
384+
left: 10px;
385+
right: 10px;
386386
position: absolute;
387387
top: 60px;
388388
bottom: 54px;
@@ -455,8 +455,7 @@ div.ac-wrap {
455455
}
456456

457457
.control-row.reply-area {
458-
padding-left: 20px;
459-
padding-right: 20px;
458+
460459
}
461460

462461
@media screen and (min-width: 1550px) {

app/assets/stylesheets/mobile/discourse.css.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ body {
8383
height: 100%;
8484
@include border-radius-all(5px);
8585
.contents {
86-
padding: 10px 20px 10px 20px;
86+
padding: 10px 10px 10px 10px;
8787
}
8888
&.white {
8989
background-color: $white;

app/assets/stylesheets/mobile/header.css.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
// --------------------------------------------------
77

88
.d-header {
9-
padding-left: 20px !important;
10-
padding-right: 40px;
9+
padding-left: 10px !important;
10+
padding-right: 10px !important;
1111
min-width: 100%;
1212
position: absolute;
1313
top: 0;
@@ -43,7 +43,7 @@ box-shadow: 0 0 3px #aaa;
4343
.panel {
4444
float: right;
4545
position: relative;
46-
margin-right: 30px;
46+
margin-right: 20px;
4747
}
4848
.current-username {
4949
float: left;

app/assets/stylesheets/mobile/topic-post.css.scss

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ button {
9999
}
100100

101101
.post-actions {
102-
margin-left: 20px;
102+
margin-left: 10px;
103103
margin-top: 2px;
104104
}
105105

@@ -133,7 +133,7 @@ a.star {
133133
}
134134

135135
border-radius: 5px;
136-
margin: 15px 20px 20px 20px;
136+
margin: 15px 10px 20px 10px;
137137
border: 1px solid #ddd;
138138

139139
h3 {
@@ -246,16 +246,16 @@ a.star {
246246

247247
#topic-footer-buttons {
248248
border-top: 1px solid #ddd;
249-
padding: 20px 20px 0 20px;
249+
padding: 20px 10px 0 10px;
250250
}
251251

252252
#suggested-topics {
253253
float: left;
254254
clear: left;
255255
margin-top: 10px;
256-
padding: 0 20px 0 20px;
256+
padding: 0 10px 0 10px;
257257

258-
th.views, td.views, td.activity, th.activity {
258+
th.views, td.views, td.activity, th.activity, th.likes, td.likes {
259259
display: none;
260260
}
261261

@@ -289,7 +289,7 @@ span.post-count {
289289
z-index: 1000;
290290
background: #eee;
291291
margin: 0 0 0 0 !important;
292-
padding: 15px 20px 15px 20px;
292+
padding: 15px 10px 15px 10px;
293293
}
294294

295295
.topic-post article.boxed img {

app/controllers/draft_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ def show
99

1010
def update
1111
Draft.set(current_user, params[:draft_key], params[:sequence].to_i, params[:data])
12-
render text: 'ok'
12+
render json: success_json
1313
end
1414

1515
def destroy
1616
Draft.clear(current_user, params[:draft_key], params[:sequence].to_i)
17-
render text: 'ok'
17+
render json: success_json
1818
end
1919

2020
end

app/controllers/topics_controller.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,6 @@ def render_topic_changes(dest_topic)
329329
end
330330
end
331331

332-
private
333-
334332
def move_posts_to_destination(topic)
335333
args = {}
336334
args[:title] = params[:title] if params[:title].present?

app/serializers/post_action_user_serializer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def avatar_template
1414
end
1515

1616
def post_url
17-
object.related_post.url if object.related_post.id
17+
object.related_post.url if object.related_post_id && object.related_post
1818
end
1919

2020
end

0 commit comments

Comments
 (0)