FEATURE: Send notification when member was accepted to group. (#7503)

This commit is contained in:
Bianca Nenciu 2019-05-27 17:28:41 +03:00 committed by GitHub
parent 6bd082feab
commit 42c82d544e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 40 additions and 14 deletions

View File

@ -35,7 +35,8 @@ const REPLACEMENTS = {
"notification.topic_reminder": "far-clock", "notification.topic_reminder": "far-clock",
"notification.watching_first_post": "far-dot-circle", "notification.watching_first_post": "far-dot-circle",
"notification.group_message_summary": "group", "notification.group_message_summary": "group",
"notification.post_approved": "check" "notification.post_approved": "check",
"notification.group_invite": "user-plus"
}; };
// TODO: use lib/svg_sprite/fa4-renames.json here // TODO: use lib/svg_sprite/fa4-renames.json here

View File

@ -0,0 +1,3 @@
<% Notification.types.each do |key, value| %>
export const <%= key.upcase %>_TYPE = <%= value %>;
<% end %>

View File

@ -10,13 +10,15 @@ import {
formatUsername formatUsername
} from "discourse/lib/utilities"; } from "discourse/lib/utilities";
import { setTransientHeader } from "discourse/lib/ajax"; import { setTransientHeader } from "discourse/lib/ajax";
import { userPath } from "discourse/lib/url"; import { groupPath, userPath } from "discourse/lib/url";
import { iconNode } from "discourse-common/lib/icon-library"; import { iconNode } from "discourse-common/lib/icon-library";
import {
const LIKED_TYPE = 5; LIKED_TYPE,
const INVITED_TYPE = 8; INVITED_TYPE,
const GROUP_SUMMARY_TYPE = 16; GROUP_SUMMARY_TYPE,
export const LIKED_CONSOLIDATED_TYPE = 19; LIKED_CONSOLIDATED_TYPE,
GROUP_INVITE_TYPE
} from "discourse/components/concerns/notification-types";
createWidget("notification-item", { createWidget("notification-item", {
tagName: "li", tagName: "li",
@ -72,6 +74,10 @@ createWidget("notification-item", {
); );
} }
if (attrs.notification_type === GROUP_INVITE_TYPE) {
return groupPath(data.group_name);
}
if (data.group_id) { if (data.group_id) {
return userPath(data.username + "/messages/group/" + data.group_name); return userPath(data.username + "/messages/group/" + data.group_name);
} }
@ -114,8 +120,11 @@ createWidget("notification-item", {
if (notificationType === GROUP_SUMMARY_TYPE) { if (notificationType === GROUP_SUMMARY_TYPE) {
const count = data.inbox_count; const count = data.inbox_count;
const group_name = data.group_name; const groupName = data.group_name;
return I18n.t(scope, { count, group_name }); return I18n.t(scope, { count, group_name: groupName });
} else if (notificationType === GROUP_INVITE_TYPE) {
const groupName = data.group_name;
return I18n.t(scope, { group_name: groupName });
} }
const username = formatUsername(data.display_username); const username = formatUsername(data.display_username);

View File

@ -341,7 +341,7 @@ class GroupsController < ApplicationController
raise Discourse::InvalidParameters.new(:user_id) if user.blank? raise Discourse::InvalidParameters.new(:user_id) if user.blank?
if params[:accept] if params[:accept]
group.add(user) group.add(user, notify: true)
GroupActionLogger.new(current_user, group).log_add_user_to_group(user) GroupActionLogger.new(current_user, group).log_add_user_to_group(user)
end end

View File

@ -506,9 +506,20 @@ class Group < ActiveRecord::Base
PUBLISH_CATEGORIES_LIMIT = 10 PUBLISH_CATEGORIES_LIMIT = 10
def add(user) def add(user, notify: false)
self.users.push(user) unless self.users.include?(user) self.users.push(user) unless self.users.include?(user)
if notify
Notification.create!(
notification_type: Notification.types[:group_invite],
user_id: user.id,
data: {
group_id: id,
group_name: name
}.to_json
)
end
if self.categories.count < PUBLISH_CATEGORIES_LIMIT if self.categories.count < PUBLISH_CATEGORIES_LIMIT
MessageBus.publish('/categories', { MessageBus.publish('/categories', {
categories: ActiveModel::ArraySerializer.new(self.categories).as_json categories: ActiveModel::ArraySerializer.new(self.categories).as_json

View File

@ -63,7 +63,8 @@ class Notification < ActiveRecord::Base
watching_first_post: 17, watching_first_post: 17,
topic_reminder: 18, topic_reminder: 18,
liked_consolidated: 19, liked_consolidated: 19,
post_approved: 20 post_approved: 20,
group_invite: 21
) )
end end

View File

@ -1689,6 +1689,7 @@ en:
granted_badge: "Earned '{{description}}'" granted_badge: "Earned '{{description}}'"
topic_reminder: "<span>{{username}}</span> {{description}}" topic_reminder: "<span>{{username}}</span> {{description}}"
watching_first_post: "<span>New Topic</span> {{description}}" watching_first_post: "<span>New Topic</span> {{description}}"
group_invite: "Invited to '{{group_name}}'"
group_message_summary: group_message_summary:
one: "{{count}} message in your {{group_name}} inbox" one: "{{count}} message in your {{group_name}} inbox"

View File

@ -1,5 +1,5 @@
/*jshint maxlen:10000000 */ /*jshint maxlen:10000000 */
import { LIKED_CONSOLIDATED_TYPE } from "discourse/widgets/notification-item"; import { LIKED_CONSOLIDATED_TYPE } from "discourse/components/concerns/notification-types";
export default { export default {
"/notifications": { "/notifications": {

View File

@ -1,4 +1,4 @@
import { LIKED_CONSOLIDATED_TYPE } from "discourse/widgets/notification-item"; import { LIKED_CONSOLIDATED_TYPE } from "discourse/components/concerns/notification-types";
export default { export default {
"site.json": { "site.json": {