diff --git a/app/assets/javascripts/discourse/components/group-activity-filter.js.es6 b/app/assets/javascripts/discourse/components/group-activity-filter.js.es6
new file mode 100644
index 00000000000..d100e27e252
--- /dev/null
+++ b/app/assets/javascripts/discourse/components/group-activity-filter.js.es6
@@ -0,0 +1,3 @@
+export default Ember.Component.extend({
+ tagName: 'li'
+});
diff --git a/app/assets/javascripts/discourse/controllers/group-activity-posts.js.es6 b/app/assets/javascripts/discourse/controllers/group-activity-posts.js.es6
index c2434c83c61..991ce0b0143 100644
--- a/app/assets/javascripts/discourse/controllers/group-activity-posts.js.es6
+++ b/app/assets/javascripts/discourse/controllers/group-activity-posts.js.es6
@@ -2,6 +2,7 @@ import { fmt } from 'discourse/lib/computed';
export default Ember.Controller.extend({
group: Ember.inject.controller(),
+ groupActivity: Ember.inject.controller(),
loading: false,
emptyText: fmt('type', 'groups.empty.%@'),
@@ -14,7 +15,9 @@ export default Ember.Controller.extend({
const beforePostId = posts[posts.length-1].get('id');
const group = this.get('group.model');
- const opts = { beforePostId, type: this.get('type') };
+ let categoryId = this.get('groupActivity.category_id');
+ const opts = { beforePostId, type: this.get('type'), categoryId };
+
group.findPosts(opts).then(newPosts => {
posts.addObjects(newPosts);
this.set('loading', false);
diff --git a/app/assets/javascripts/discourse/controllers/group-activity.js.es6 b/app/assets/javascripts/discourse/controllers/group-activity.js.es6
index 955822ffcf5..de4bda4dcdd 100644
--- a/app/assets/javascripts/discourse/controllers/group-activity.js.es6
+++ b/app/assets/javascripts/discourse/controllers/group-activity.js.es6
@@ -2,6 +2,7 @@ import computed from 'ember-addons/ember-computed-decorators';
export default Ember.Controller.extend({
application: Ember.inject.controller(),
+ queryParams: ['category_id'],
@computed('model.is_group_user')
showGroupMessages(isGroupUser) {
diff --git a/app/assets/javascripts/discourse/models/group.js.es6 b/app/assets/javascripts/discourse/models/group.js.es6
index c7e5eed6b1f..c26544e7c55 100644
--- a/app/assets/javascripts/discourse/models/group.js.es6
+++ b/app/assets/javascripts/discourse/models/group.js.es6
@@ -203,12 +203,13 @@ const Group = RestModel.extend({
findPosts(opts) {
opts = opts || {};
- const type = opts['type'] || 'posts';
+ const type = opts.type || 'posts';
var data = {};
if (opts.beforePostId) { data.before_post_id = opts.beforePostId; }
+ if (opts.categoryId) { data.category_id = parseInt(opts.categoryId); }
- return ajax(`/groups/${this.get('name')}/${type}.json`, { data: data }).then(posts => {
+ return ajax(`/groups/${this.get('name')}/${type}.json`, { data }).then(posts => {
return posts.map(p => {
p.user = User.create(p.user);
p.topic = Topic.create(p.topic);
diff --git a/app/assets/javascripts/discourse/routes/group-activity-posts.js.es6 b/app/assets/javascripts/discourse/routes/group-activity-posts.js.es6
index 03cd7ec1147..1127d36f97f 100644
--- a/app/assets/javascripts/discourse/routes/group-activity-posts.js.es6
+++ b/app/assets/javascripts/discourse/routes/group-activity-posts.js.es6
@@ -6,8 +6,9 @@ export function buildGroupPage(type) {
return I18n.t(`groups.${type}`);
},
- model() {
- return this.modelFor("group").findPosts({ type });
+ model(params, transition) {
+ let categoryId = Ember.get(transition, 'queryParams.category_id');
+ return this.modelFor("group").findPosts({ type, categoryId });
},
setupController(controller, model) {
diff --git a/app/assets/javascripts/discourse/templates/components/group-activity-filter.hbs b/app/assets/javascripts/discourse/templates/components/group-activity-filter.hbs
new file mode 100644
index 00000000000..68623d09c8a
--- /dev/null
+++ b/app/assets/javascripts/discourse/templates/components/group-activity-filter.hbs
@@ -0,0 +1,3 @@
+{{#link-to (concat 'group.activity.' filter) (query-params category_id=categoryId)}}
+ {{i18n (concat 'groups.' filter)}}
+{{/link-to}}
diff --git a/app/assets/javascripts/discourse/templates/group/activity.hbs b/app/assets/javascripts/discourse/templates/group/activity.hbs
index d03a14e84f1..dcc8386bce8 100644
--- a/app/assets/javascripts/discourse/templates/group/activity.hbs
+++ b/app/assets/javascripts/discourse/templates/group/activity.hbs
@@ -1,21 +1,10 @@
{{#mobile-nav class='group-activity-nav' desktopClass="pull-left nav nav-stacked" currentPath=application.currentPath}}
-
- {{#link-to 'group.activity.posts'}}{{i18n 'groups.posts'}}{{/link-to}}
-
-
-
- {{#link-to 'group.activity.topics'}}{{i18n 'groups.topics'}}{{/link-to}}
-
-
-
- {{#link-to 'group.activity.mentions'}}{{i18n 'groups.mentions'}}{{/link-to}}
-
-
+ {{group-activity-filter filter="posts" categoryId=category_id}}
+ {{group-activity-filter filter="topics" categoryId=category_id}}
+ {{group-activity-filter filter="mentions" categoryId=category_id}}
{{#if showGroupMessages}}
-
- {{#link-to 'group.activity.messages'}}{{i18n 'groups.messages'}}{{/link-to}}
-
+ {{group-activity-filter filter="messages"}}
{{/if}}
{{/mobile-nav}}
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb
index 2785e69312c..bd9f0795473 100644
--- a/app/controllers/groups_controller.rb
+++ b/app/controllers/groups_controller.rb
@@ -69,13 +69,19 @@ class GroupsController < ApplicationController
def posts
group = find_group(:group_id)
- posts = group.posts_for(guardian, params[:before_post_id]).limit(20)
+ posts = group.posts_for(
+ guardian,
+ params.permit(:before_post_id, :category_id)
+ ).limit(20)
render_serialized posts.to_a, GroupPostSerializer
end
def posts_feed
group = find_group(:group_id)
- @posts = group.posts_for(guardian).limit(50)
+ @posts = group.posts_for(
+ guardian,
+ params.permit(:before_post_id, :category_id)
+ ).limit(50)
@title = "#{SiteSetting.title} - #{I18n.t("rss_description.group_posts", group_name: group.name)}"
@link = Discourse.base_url
@description = I18n.t("rss_description.group_posts", group_name: group.name)
@@ -84,19 +90,28 @@ class GroupsController < ApplicationController
def topics
group = find_group(:group_id)
- posts = group.posts_for(guardian, params[:before_post_id]).where(post_number: 1).limit(20)
+ posts = group.posts_for(
+ guardian,
+ params.permit(:before_post_id, :category_id)
+ ).where(post_number: 1).limit(20)
render_serialized posts.to_a, GroupPostSerializer
end
def mentions
group = find_group(:group_id)
- posts = group.mentioned_posts_for(guardian, params[:before_post_id]).limit(20)
+ posts = group.mentioned_posts_for(
+ guardian,
+ params.permit(:before_post_id, :category_id)
+ ).limit(20)
render_serialized posts.to_a, GroupPostSerializer
end
def mentions_feed
group = find_group(:group_id)
- @posts = group.mentioned_posts_for(guardian).limit(50)
+ @posts = group.mentioned_posts_for(
+ guardian,
+ params.permit(:before_post_id, :category_id)
+ ).limit(50)
@title = "#{SiteSetting.title} - #{I18n.t("rss_description.group_mentions", group_name: group.name)}"
@link = Discourse.base_url
@description = I18n.t("rss_description.group_mentions", group_name: group.name)
@@ -106,7 +121,10 @@ class GroupsController < ApplicationController
def messages
group = find_group(:group_id)
posts = if guardian.can_see_group_messages?(group)
- group.messages_for(guardian, params[:before_post_id]).where(post_number: 1).limit(20).to_a
+ group.messages_for(
+ guardian,
+ params.permit(:before_post_id, :category_id)
+ ).where(post_number: 1).limit(20).to_a
else
[]
end
diff --git a/app/models/group.rb b/app/models/group.rb
index 40833468544..bf2c2147b6d 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -185,7 +185,8 @@ class Group < ActiveRecord::Base
end
end
- def posts_for(guardian, before_post_id = nil)
+ def posts_for(guardian, opts = nil)
+ opts ||= {}
user_ids = group_users.map { |gu| gu.user_id }
result = Post.includes(:user, :topic, topic: :category)
.references(:posts, :topics, :category)
@@ -193,24 +194,35 @@ class Group < ActiveRecord::Base
.where('topics.archetype <> ?', Archetype.private_message)
.where(post_type: Post.types[:regular])
+ if opts[:category_id].present?
+ result = result.where('topics.category_id = ?', opts[:category_id].to_i)
+ end
+
result = guardian.filter_allowed_categories(result)
- result = result.where('posts.id < ?', before_post_id) if before_post_id
+ result = result.where('posts.id < ?', opts[:before_post_id].to_i) if opts[:before_post_id]
result.order('posts.created_at desc')
end
- def messages_for(guardian, before_post_id = nil)
+ def messages_for(guardian, opts = nil)
+ opts ||= {}
+
result = Post.includes(:user, :topic, topic: :category)
.references(:posts, :topics, :category)
.where('topics.archetype = ?', Archetype.private_message)
.where(post_type: Post.types[:regular])
.where('topics.id IN (SELECT topic_id FROM topic_allowed_groups WHERE group_id = ?)', self.id)
+ if opts[:category_id].present?
+ result = result.where('topics.category_id = ?', opts[:category_id].to_i)
+ end
+
result = guardian.filter_allowed_categories(result)
- result = result.where('posts.id < ?', before_post_id) if before_post_id
+ result = result.where('posts.id < ?', opts[:before_post_id].to_i) if opts[:before_post_id]
result.order('posts.created_at desc')
end
- def mentioned_posts_for(guardian, before_post_id = nil)
+ def mentioned_posts_for(guardian, opts = nil)
+ opts ||= {}
result = Post.joins(:group_mentions)
.includes(:user, :topic, topic: :category)
.references(:posts, :topics, :category)
@@ -218,8 +230,12 @@ class Group < ActiveRecord::Base
.where(post_type: Post.types[:regular])
.where('group_mentions.group_id = ?', self.id)
+ if opts[:category_id].present?
+ result = result.where('topics.category_id = ?', opts[:category_id].to_i)
+ end
+
result = guardian.filter_allowed_categories(result)
- result = result.where('posts.id < ?', before_post_id) if before_post_id
+ result = result.where('posts.id < ?', opts[:before_post_id].to_i) if opts[:before_post_id]
result.order('posts.created_at desc')
end