FEATURE: split up group PMS on user page
This commit is contained in:
parent
fe8c74d0b6
commit
8cf4d52cb6
|
@ -67,7 +67,19 @@ export default Ember.Controller.extend(CanCheckEmails, {
|
|||
privateMessagesActive: Em.computed.equal('pmView', 'index'),
|
||||
privateMessagesMineActive: Em.computed.equal('pmView', 'mine'),
|
||||
privateMessagesUnreadActive: Em.computed.equal('pmView', 'unread'),
|
||||
privateMessagesGroupsActive: Em.computed.equal('pmView', 'groups'),
|
||||
|
||||
@computed('model.private_messages_stats.groups', 'groupFilter', 'pmView')
|
||||
groupPMStats(stats,filter,pmView) {
|
||||
if (stats) {
|
||||
return stats.map(g => {
|
||||
return {
|
||||
name: g.name,
|
||||
count: g.count,
|
||||
active: (g.name === filter && pmView === 'groups')
|
||||
};
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
expandProfile() {
|
||||
|
|
|
@ -16,7 +16,6 @@ const User = RestModel.extend({
|
|||
hasPMs: Em.computed.gt("private_messages_stats.all", 0),
|
||||
hasStartedPMs: Em.computed.gt("private_messages_stats.mine", 0),
|
||||
hasUnreadPMs: Em.computed.gt("private_messages_stats.unread", 0),
|
||||
hasGroupsPMs: Em.computed.gt("private_messages_stats.groups", 0),
|
||||
hasPosted: Em.computed.gt("post_count", 0),
|
||||
hasNotPosted: Em.computed.not("hasPosted"),
|
||||
canBeDeleted: Em.computed.and("can_be_deleted", "hasNotPosted"),
|
||||
|
|
|
@ -71,7 +71,7 @@ export default function() {
|
|||
this.resource('userPrivateMessages', { path: '/messages' }, function() {
|
||||
this.route('mine');
|
||||
this.route('unread');
|
||||
this.route('groups');
|
||||
this.route('group', { path: 'group/:name'});
|
||||
});
|
||||
|
||||
this.resource('preferences', function() {
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
import createPMRoute from "discourse/routes/build-user-topic-list-route";
|
||||
|
||||
export default createPMRoute('groups', 'private-messages-groups').extend({
|
||||
model(params) {
|
||||
return this.store.findFiltered("topicList", { filter: "topics/private-messages-group/" + this.modelFor("user").get("username_lower") + "/" + params.name });
|
||||
},
|
||||
|
||||
setupController(controller,model) {
|
||||
this._super.apply(this, arguments);
|
||||
const filter = _.last(model.get("filter").split('/'));
|
||||
this.controllerFor("user").set("groupFilter", filter);
|
||||
}
|
||||
});
|
|
@ -1,3 +0,0 @@
|
|||
import createPMRoute from "discourse/routes/build-user-topic-list-route";
|
||||
|
||||
export default createPMRoute('groups', 'private-messages-groups');
|
|
@ -197,12 +197,15 @@
|
|||
{{#if model.hasUnreadPMs}}<span class='badge-notification unread-private-messages'>{{model.private_messages_stats.unread}}</span>{{/if}}
|
||||
{{/link-to}}
|
||||
</li>
|
||||
<li {{bind-attr class=":noGlyph privateMessagesGroupsActive:active"}}>
|
||||
{{#link-to 'userPrivateMessages.groups' model}}
|
||||
{{i18n 'user.messages.groups'}}
|
||||
{{#if model.hasGroupsPMs}}<span class='count'>({{model.private_messages_stats.groups}})</span>{{/if}}
|
||||
{{#each groupPMStats as |group|}}
|
||||
<li class="{{if group.active "active"}}">
|
||||
{{#link-to 'userPrivateMessages.group' group.name}}
|
||||
<i class='glyph fa fa-group'></i>
|
||||
{{group.name}}
|
||||
<span class='count'>({{group.count}})</span>
|
||||
{{/link-to}}
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
{{/if}}
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ class ListController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
[:topics_by, :private_messages, :private_messages_sent, :private_messages_unread, :private_messages_groups].each do |action|
|
||||
[:topics_by, :private_messages, :private_messages_sent, :private_messages_unread, :private_messages_group].each do |action|
|
||||
define_method("#{action}") do
|
||||
list_opts = build_topic_list_options
|
||||
target_user = fetch_user_from_params(include_inactive: current_user.try(:staff?))
|
||||
|
@ -252,7 +252,8 @@ class ListController < ApplicationController
|
|||
filter: params[:filter],
|
||||
state: params[:state],
|
||||
search: params[:search],
|
||||
q: params[:q]
|
||||
q: params[:q],
|
||||
group_name: params[:group_name]
|
||||
}
|
||||
options[:no_subcategories] = true if params[:no_subcategories] == 'true'
|
||||
options[:slow_platform] = true if slow_platform?
|
||||
|
|
|
@ -34,6 +34,7 @@ class UserActionsController < ApplicationController
|
|||
|
||||
def private_messages
|
||||
# DO NOT REMOVE
|
||||
# TODO should preload messages to avoid extra http req
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -95,16 +95,24 @@ SQL
|
|||
all, mine, unread = exec_sql(sql, user_id: user_id).values[0].map(&:to_i)
|
||||
|
||||
sql = <<-SQL
|
||||
SELECT COUNT(*) "groups"
|
||||
FROM topics
|
||||
SELECT g.name, COUNT(*) "count"
|
||||
FROM topics t
|
||||
JOIN topic_allowed_groups tg ON topic_id = t.id
|
||||
JOIN group_users gu ON gu.user_id = :user_id AND gu.group_id = tg.group_id
|
||||
JOIN groups g ON g.id = gu.group_id
|
||||
WHERE deleted_at IS NULL
|
||||
AND archetype = 'private_message'
|
||||
AND id IN (SELECT topic_id FROM topic_allowed_groups WHERE group_id IN (SELECT group_id FROM group_users WHERE user_id = :user_id))
|
||||
GROUP BY g.name
|
||||
SQL
|
||||
|
||||
groups = exec_sql(sql, user_id: user_id).values[0][0].to_i
|
||||
result = { all: all, mine: mine, unread: unread}
|
||||
|
||||
exec_sql(sql, user_id: user_id).each do |row|
|
||||
(result[:groups] ||= []) << {name: row["name"], count: row["count"].to_i}
|
||||
end
|
||||
|
||||
result
|
||||
|
||||
{ all: all, mine: mine, unread: unread, groups: groups }
|
||||
end
|
||||
|
||||
def self.stream_item(action_id, guardian)
|
||||
|
|
|
@ -278,6 +278,7 @@ Discourse::Application.routes.draw do
|
|||
get "users/:username/private-messages/:filter" => "user_actions#private_messages", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||
get "users/:username/messages" => "user_actions#private_messages", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||
get "users/:username/messages/:filter" => "user_actions#private_messages", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||
get "users/:username/messages/group/:group_name" => "user_actions#private_messages", constraints: {username: USERNAME_ROUTE_FORMAT, group_name: USERNAME_ROUTE_FORMAT}
|
||||
get "users/:username.json" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT}, defaults: {format: :json}
|
||||
get "users/:username" => "users#show", as: 'user', constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||
put "users/:username" => "users#update", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||
|
@ -466,7 +467,10 @@ Discourse::Application.routes.draw do
|
|||
get "topics/private-messages/:username" => "list#private_messages", as: "topics_private_messages", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||
get "topics/private-messages-sent/:username" => "list#private_messages_sent", as: "topics_private_messages_sent", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||
get "topics/private-messages-unread/:username" => "list#private_messages_unread", as: "topics_private_messages_unread", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||
get "topics/private-messages-groups/:username" => "list#private_messages_groups", as: "topics_private_messages_groups", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||
get "topics/private-messages-group/:username/:group_name.json" => "list#private_messages_group", as: "topics_private_messages_group", constraints: {
|
||||
username: USERNAME_ROUTE_FORMAT,
|
||||
group_name: USERNAME_ROUTE_FORMAT
|
||||
}
|
||||
|
||||
get 'embed/comments' => 'embed#comments'
|
||||
get 'embed/count' => 'embed#count'
|
||||
|
|
|
@ -28,6 +28,7 @@ class TopicQuery
|
|||
search
|
||||
slow_platform
|
||||
filter
|
||||
group_name
|
||||
q)
|
||||
|
||||
# Maps `order` to a columns in `topics`
|
||||
|
@ -130,7 +131,7 @@ class TopicQuery
|
|||
create_list(:private_messages, {}, list)
|
||||
end
|
||||
|
||||
def list_private_messages_groups(user)
|
||||
def list_private_messages_group(user)
|
||||
list = private_messages_for(user, :group)
|
||||
create_list(:private_messages, {}, list)
|
||||
end
|
||||
|
@ -240,7 +241,11 @@ class TopicQuery
|
|||
|
||||
if type == :group
|
||||
result = result.includes(:allowed_groups)
|
||||
result = result.where("topics.id IN (SELECT topic_id FROM topic_allowed_groups WHERE group_id IN (SELECT group_id FROM group_users WHERE user_id = #{user.id.to_i}))")
|
||||
result = result.where("topics.id IN (SELECT topic_id FROM topic_allowed_groups
|
||||
WHERE group_id IN (
|
||||
SELECT group_id FROM group_users WHERE user_id = #{user.id.to_i}) AND
|
||||
group_id IN (SELECT id FROM groups WHERE name ilike ?)
|
||||
)", @options[:group_name])
|
||||
elsif type == :user
|
||||
result = result.includes(:allowed_users)
|
||||
result = result.where("topics.id IN (SELECT topic_id FROM topic_allowed_users WHERE user_id = #{user.id.to_i})")
|
||||
|
|
Loading…
Reference in New Issue