Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
db30bd7
added ignored flag on messages
ggazzo Apr 19, 2018
b7c3588
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
gdelavald Apr 19, 2018
7fcbfe7
Revert change to map that breaks subscriptions
gdelavald Apr 19, 2018
65b1b73
Adds toggling to show ignored message
gdelavald Apr 19, 2018
7385581
Add new icon, ignore message and css for sequential messages
gdelavald Apr 19, 2018
2080f32
ignore user on message action
ggazzo Apr 19, 2018
45d7c46
Merge remote-tracking branch 'origin/ignore0user' into ignore0user
ggazzo Apr 19, 2018
05f4336
Add i18n for ignored message
gdelavald Apr 19, 2018
5046b14
Merge branch 'ignore0user' of https://github.com/RocketChat/Rocket.Ch…
gdelavald Apr 19, 2018
4758873
Adds translations and fixes access to undefined subscriptions
gdelavald Apr 19, 2018
b8ab420
removed file
ggazzo Apr 19, 2018
143b0e7
Merge remote-tracking branch 'origin/ignore0user' into ignore0user
ggazzo Apr 19, 2018
09fbfce
ignored title i18n and fix popover on member list
ggazzo Apr 19, 2018
26f31e5
Merge branch 'develop' into ignore0user
ggazzo Apr 19, 2018
fd18b2b
i18n
ggazzo Apr 19, 2018
31c70cf
Merge remote-tracking branch 'origin/ignore0user' into ignore0user
ggazzo Apr 19, 2018
bfcf0ff
do not allow ignore user on DM
ggazzo Apr 19, 2018
e592bf5
ignore user rest method
ggazzo Apr 20, 2018
a2c630d
Remove mixed tabs and spaces
gdelavald Apr 20, 2018
11feb13
Remove trailing space
gdelavald Apr 20, 2018
c3d9162
Merge branch 'develop' into ignore0user
gdelavald Apr 20, 2018
b5ad5ad
fix review
ggazzo Apr 20, 2018
c84cc28
fix review
ggazzo Apr 20, 2018
14927de
fix css identation
karlprieb Apr 20, 2018
2ab6f5e
fix more css identation
karlprieb Apr 20, 2018
b564b20
check if ignore param is a boolean
ggazzo Apr 20, 2018
782fc6b
Merge remote-tracking branch 'origin/ignore0user' into ignore0user
ggazzo Apr 20, 2018
2867de7
remove file metor.id
ggazzo Apr 20, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/rocketchat-api/server/v1/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,24 @@ RocketChat.API.v1.addRoute('chat.reportMessage', { authRequired: true }, {
return RocketChat.API.v1.success();
}
});

RocketChat.API.v1.addRoute('chat.ignoreUser', { authRequired: true }, {
get() {
const { rid, userId } = this.queryParams;
let { ignore = true } = this.queryParams;

ignore = typeof ignore === 'string' ? /true|1/.test(ignore) : ignore;

if (!rid || !rid.trim()) {
throw new Meteor.Error('error-room-id-param-not-provided', 'The required "rid" param is missing.');
}

if (!userId || !userId.trim()) {
throw new Meteor.Error('error-user-id-param-not-provided', 'The required "userId" param is missing.');
}

Meteor.runAsUser(this.userId, () => Meteor.call('ignoreUser', { rid, userId, ignore }));

return RocketChat.API.v1.success();
}
});
6 changes: 6 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,8 @@
"Iframe_Integration_send_enable_Description": "Send events to parent window",
"Iframe_Integration_send_target_origin": "Send Target Origin",
"Iframe_Integration_send_target_origin_Description": "Origin with protocol prefix, which commands are sent to e.g. 'https://localhost', or * to allow sending to anywhere.",
"Ignore": "Ignore",
"Ignored": "Ignored",
"IMAP_intercepter_already_running": "IMAP intercepter already running",
"IMAP_intercepter_Not_running": "IMAP intercepter Not running",
"Impersonate_next_agent_from_queue": "Impersonate next agent from queue",
Expand Down Expand Up @@ -1317,6 +1319,7 @@
"Message_HideType_ru": "Hide \"User Removed\" messages",
"Message_HideType_uj": "Hide \"User Join\" messages",
"Message_HideType_ul": "Hide \"User Leave\" messages",
"Message_Ignored": "This message was ignored",
"Message_info": "Message info",
"Message_KeepHistory": "Keep Per Message Editing History",
"Message_MaxAll": "Maximum Channel Size for ALL Message",
Expand Down Expand Up @@ -2035,6 +2038,7 @@
"unarchive-room_description": "Permission to unarchive channels",
"Unblock_User": "Unblock User",
"Uninstall": "Uninstall",
"Unignore": "Unignore",
"Unmute_someone_in_room": "Unmute someone in the room",
"Unmute_user": "Unmute user",
"Unnamed": "Unnamed",
Expand Down Expand Up @@ -2086,8 +2090,10 @@
"User_has_been_activated": "User has been activated",
"User_has_been_deactivated": "User has been deactivated",
"User_has_been_deleted": "User has been deleted",
"User_has_been_ignored": "User has been ignored",
"User_has_been_muted_in_s": "User has been muted in %s",
"User_has_been_removed_from_s": "User has been removed from %s",
"User_has_been_unignored": "User is no longer ignored",
"User_Info": "User Info",
"User_Interface": "User Interface",
"User_is_blocked": "User is blocked",
Expand Down
52 changes: 52 additions & 0 deletions packages/rocketchat-lib/client/MessageAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ import _ from 'underscore';
import moment from 'moment';
import toastr from 'toastr';

const success = function success(fn) {
return function(error, result) {
if (error) {
return handleError(error);
}
if (result) {
fn.call(this, result);
}
};
};

RocketChat.MessageAction = new class {
/*
config expects the following keys (only id is mandatory):
Expand Down Expand Up @@ -279,4 +290,45 @@ Meteor.startup(function() {
order: 6,
group: 'menu'
});



RocketChat.MessageAction.addButton({
id: 'ignore-user',
icon: 'ban',
label: t('Ignore'),
context: ['message', 'message-mobile'],
action() {
const [, {rid, u: {_id}}] = this._arguments;
Meteor.call('ignoreUser', { rid, userId:_id, ignore: true}, success(() => toastr.success(t('User_has_been_ignored'))));
},
condition(message) {
const subscription = RocketChat.models.Subscriptions.findOne({rid: message.rid});

return Meteor.userId() !== message.u._id && !(subscription.ignored && subscription.ignored.indexOf(message.u._id) > -1);
},
order: 20,
group: 'menu'
});

RocketChat.MessageAction.addButton({
id: 'unignore-user',
icon: 'ban',
label: t('Unignore'),
context: ['message', 'message-mobile'],
action() {
const [, {rid, u: {_id}}] = this._arguments;
Meteor.call('ignoreUser', { rid, userId:_id, ignore: false}, success(() => toastr.success(t('User_has_been_unignored'))));

},
condition(message) {
const subscription = RocketChat.models.Subscriptions.findOne({rid: message.rid});
return Meteor.userId() !== message.u._id && subscription.ignored && subscription.ignored.indexOf(message.u._id) > -1;
},
order: 20,
group: 'menu'
});



});
11 changes: 7 additions & 4 deletions packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,11 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room, userId) {
// Don't fetch all users if room exceeds max members
const maxMembersForNotification = RocketChat.settings.get('Notifications_Max_Room_Members');
const disableAllMessageNotifications = room.usernames.length > maxMembersForNotification && maxMembersForNotification !== 0;
const subscriptions = RocketChat.models.Subscriptions.findNotificationPreferencesByRoom(room._id, disableAllMessageNotifications);
const subscriptions = RocketChat.models.Subscriptions.findNotificationPreferencesByRoom(room._id, disableAllMessageNotifications) || [];
const userIds = [];
subscriptions.forEach((s) => {
userIds.push(s.u._id);
});
subscriptions.forEach(s => userIds.push(s.u._id));
const users = {};

RocketChat.models.Users.findUsersByIds(userIds, { fields: { 'settings.preferences': 1 } }).forEach((user) => {
users[user._id] = user;
});
Expand All @@ -223,6 +222,10 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room, userId) {
return;
}

if (Array.isArray(subscription.ignored) && subscription.ignored.find(message.u._id)) {
return;
}

const {
audioNotifications = RocketChat.getUserPreference(users[subscription.u._id], 'audioNotifications'),
desktopNotifications = RocketChat.getUserPreference(users[subscription.u._id], 'desktopNotifications'),
Expand Down
15 changes: 15 additions & 0 deletions packages/rocketchat-lib/server/models/Subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,21 @@ class ModelSubscriptions extends RocketChat.models._Base {
return this.update(query, update, { multi: true });
}

ignoreUser({_id, ignoredUser : ignored, ignore = true}) {
const query = {
_id
};
const update = {
};
if (ignore) {
update.$addToSet = { ignored };
} else {
update.$pull = { ignored };
}

return this.update(query, update);
}

setAlertForRoomIdExcludingUserId(roomId, userId) {
const query = {
rid: roomId,
Expand Down
17 changes: 17 additions & 0 deletions packages/rocketchat-theme/client/imports/components/messages.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@
}

.message {

& .toggle-hidden {
display: none;
}

&--ignored {
& .body {
display: none;
}
& .toggle-hidden {
display: block;
}
& + .message--ignored.sequential {
display: none;
}
}

&.active {
& .message-actions__label {
color: var(--rc-color-button-primary);
Expand Down
5 changes: 5 additions & 0 deletions packages/rocketchat-theme/client/imports/general/base_old.css
Original file line number Diff line number Diff line change
Expand Up @@ -5384,6 +5384,11 @@ body:not(.is-cordova) {
cursor: pointer;
}

.toggle-hidden {
cursor: pointer;
font-style: italic;
}

/* kinda hacky, needed in oembedFrageWidget.html */

.rc-old br.only-after-a {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
{{> avatar username=user.username}}
<div class="rc-member-list__username">
<div class="rc-member-list__status rc-member-list__status--{{status}}"></div>
{{displayName}} {{utcOffset}}
{{ignored}} {{displayName}} {{utcOffset}}
</div>
{{> icon user=. block="rc-member-list__menu js-action" icon="menu" }}
</li>
Expand Down
23 changes: 19 additions & 4 deletions packages/rocketchat-ui-flextab/client/tabs/membersList.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
/* globals WebRTC popover */
/* globals WebRTC popover isRtl */
import _ from 'underscore';
import {getActions} from './userActions';

Template.membersList.helpers({
ignored() {
const {user} = this;
const sub = RocketChat.models.Subscriptions.findOne({rid: Session.get('openedRoom')});
return sub && sub.ignored && sub.ignored.indexOf(user._id) > -1 ? `(${ t('Ignored') })` : '';
},
tAddUsers() {
return t('Add_users');
},
Expand Down Expand Up @@ -63,7 +68,7 @@ Template.membersList.helpers({

return {
user,
status: (onlineUsers[user.username] != null ? onlineUsers[user.username].status : undefined),
status: (onlineUsers[user.username] != null ? onlineUsers[user.username].status : 'offline'),
muted: Array.from(roomMuted).includes(user.username),
utcOffset
};
Expand All @@ -76,7 +81,7 @@ Template.membersList.helpers({
}
// show online users first.
// sortBy is stable, so we can do this
users = _.sortBy(users, u => u.status == null);
users = _.sortBy(users, u => u.status === 'offline');

let hasMore = undefined;
const usersLimit = Template.instance().usersLimit.get();
Expand Down Expand Up @@ -216,11 +221,21 @@ Template.membersList.events({
e.preventDefault();
const config = {
columns,
mousePosition: () => ({
x: e.currentTarget.getBoundingClientRect().right + 10,
y: e.currentTarget.getBoundingClientRect().bottom + 100
}),
customCSSProperties: () => ({
top: `${ e.currentTarget.getBoundingClientRect().bottom + 10 }px`,
left: isRtl() ? `${ e.currentTarget.getBoundingClientRect().left - 10 }px` : undefined
}),
data: {
rid: this._id,
username: instance.data.username,
instance
},
offsetHorizontal: 15,
activeElement: e.currentTarget,
currentTarget: e.currentTarget,
onDestroyed:() => {
e.currentTarget.parentElement.classList.remove('active');
Expand Down Expand Up @@ -256,6 +271,7 @@ Template.membersList.onCreated(function() {
this.showDetail = new ReactiveVar(false);
this.filter = new ReactiveVar('');


this.users = new ReactiveVar([]);
this.total = new ReactiveVar;
this.loading = new ReactiveVar(true);
Expand All @@ -264,7 +280,6 @@ Template.membersList.onCreated(function() {

Tracker.autorun(() => {
if (this.data.rid == null) { return; }

this.loading.set(true);
return Meteor.call('getUsersOfRoom', this.data.rid, this.showAllUsers.get(), (error, users) => {
this.users.set(users.records);
Expand Down
23 changes: 22 additions & 1 deletion packages/rocketchat-ui-flextab/client/tabs/userActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import toastr from 'toastr';
export const getActions = function({ user, directActions, hideAdminControls }) {

const hasPermission = RocketChat.authz.hasAllPermission;

const isIgnored = () => {
const sub = RocketChat.models.Subscriptions.findOne({rid : Session.get('openedRoom')});
return sub && sub.ignored && sub.ignored.indexOf(user._id) > -1;
};
const canSetLeader= () => {
return RocketChat.authz.hasAllPermission('set-leader', Session.get('openedRoom'));
};
Expand Down Expand Up @@ -302,6 +305,24 @@ export const getActions = function({ user, directActions, hideAdminControls }) {
}));
})
};
}, () => {
if (!directActions || user._id === Meteor.userId()) {
return;
}
if (isIgnored()) {
return {
group: 'channel',
icon : 'ban',
name: t('Unignore'),
action: prevent(getUser, ({_id}) => Meteor.call('ignoreUser', { rid: Session.get('openedRoom'), userId:_id, ignore: false}, success(() => toastr.success(t('User_has_been_unignored')))))
};
}
return {
group: 'channel',
icon : 'ban',
name: t('Ignore'),
action: prevent(getUser, ({_id}) => Meteor.call('ignoreUser', { rid: Session.get('openedRoom'), userId:_id, ignore: true}, success(() => toastr.success(t('User_has_been_ignored')))))
};
}, () => {
if (!directActions || !canMuteUser()) {
return;
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-ui-master/public/icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion packages/rocketchat-ui-message/client/message.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template name="message">
<li id="{{_id}}" data-context={{actionContext}} class="message background-transparent-dark-hover {{isSequential}} {{system}} {{t}} {{own}} {{isTemp}} {{chatops}} {{customClass}}" data-username="{{u.username}}" data-groupable="{{isGroupable}}" data-date="{{date}}" data-timestamp="{{timestamp}}">
<li id="{{_id}}" data-context={{actionContext}} class="message background-transparent-dark-hover {{ignoredClass}} {{sequentialClass}} {{system}} {{t}} {{own}} {{isTemp}} {{chatops}} {{customClass}}" data-username="{{u.username}}" data-groupable="{{isGroupable}}" data-date="{{date}}" data-timestamp="{{timestamp}}">
{{#if avatar}}
{{#if avatarFromUsername}}
<button class="thumb user-card-message" data-username="{{u.username}}" tabindex="1">{{> avatar username=avatarFromUsername}}</button>
Expand Down Expand Up @@ -55,6 +55,9 @@
{{>icon icon=roomIcon}}{{channelName}}
</span>
{{/if}}
{{#if isIgnored}}
<span class="toggle-hidden icon-right-dir" data-message="{{_id}}"> {{_ "Message_Ignored"}} </span>
{{/if}}
<div class="body color-primary-font-color {{system true}}" dir="auto" data-unread-text="{{_ "Unread_Messages"}}">
{{#if isSnippet}}
<div class="snippet-name">{{_ "Snippet_name"}}: {{snippetName}}</div>
Expand Down
9 changes: 9 additions & 0 deletions packages/rocketchat-ui-message/client/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Template.message.helpers({
encodeURI(text) {
return encodeURI(text);
},
isIgnored() {
return this.ignored;
},
ignoredClass() {
return this.ignored ? 'message--ignored' : '';
},
isBot() {
if (this.bot != null) {
return 'bot';
Expand Down Expand Up @@ -47,6 +53,9 @@ Template.message.helpers({
}
},
isSequential() {
return this.groupable !== false;
},
sequentialClass() {
if (this.groupable !== false) {
return 'sequential';
}
Expand Down
Loading