Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Command /hide to hide channels #10727

Merged
merged 8 commits into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
1 change: 1 addition & 0 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ rocketchat:slashcommands-archive
rocketchat:slashcommands-asciiarts
rocketchat:slashcommands-create
rocketchat:slashcommands-help
rocketchat:slashcommands-hide
rocketchat:slashcommands-invite
rocketchat:slashcommands-invite-all
rocketchat:slashcommands-join
Expand Down
1 change: 1 addition & 0 deletions .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@
"error-user-has-no-roles": "User has no roles",
"error-user-limit-exceeded": "The number of users you are trying to invite to #channel_name exceeds the limit set by the administrator",
"error-user-not-in-room": "User is not in this room",
"error-logged-user-not-in-room": "You are not in the room `%s`",
"error-user-registration-disabled": "User registration is disabled",
"error-user-registration-secret": "User registration is only allowed via Secret URL",
"error-you-are-last-owner": "You are the last owner. Please set new owner before leaving the room.",
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-i18n/i18n/pt-BR.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2348,4 +2348,4 @@
"your_message_optional": "sua mensagem (opcional)",
"Your_password_is_wrong": "Sua senha está errada!",
"Your_push_was_sent_to_s_devices": "Sua notificação foi enviada para %s dispositivos"
}
}
4 changes: 4 additions & 0 deletions packages/rocketchat-slashcommands-hide/client/hide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RocketChat.slashCommands.add('hide', undefined, {
description: 'Hide_room',
params: '#room'
});
16 changes: 16 additions & 0 deletions packages/rocketchat-slashcommands-hide/package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Package.describe({
name: 'rocketchat:slashcommands-hide',
version: '0.0.1',
summary: 'Message pre-processor that will translate /hide commands',
git: ''
});

Package.onUse(function(api) {
api.use([
'ecmascript',
'rocketchat:lib'
]);

api.addFiles('client/hide.js', 'client');
api.addFiles('server/hide.js', 'server');
});
61 changes: 61 additions & 0 deletions packages/rocketchat-slashcommands-hide/server/hide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

/*
* Hide is a named function that will replace /hide commands
* @param {Object} message - The message object
*/
function Hide(command, param, item) {
if (command !== 'hide' || !Match.test(param, String)) {
return;
}
const room = param.trim();
const user = Meteor.user();
// if there is not a param, hide the current room
let {rid} = item;
if (room !== '') {
const [strippedRoom] = room.replace(/#|@/, '').split(' ');
const [type] = room;

const roomObject = type === '#' ? RocketChat.models.Rooms.findOneByName(strippedRoom) : RocketChat.models.Rooms.findOne({
t: 'd',
usernames: { $all: [user.username, strippedRoom] }
});

if (!roomObject) {
return RocketChat.Notifications.notifyUser(user._id, 'message', {
_id: Random.id(),
rid: item.rid,
ts: new Date,
msg: TAPi18n.__('Channel_doesnt_exist', {
postProcess: 'sprintf',
sprintf: [room]
}, user.language)
});
}

if (!roomObject.usernames.includes(user.username)) {
return RocketChat.Notifications.notifyUser(user._id, 'message', {
_id: Random.id(),
rid: item.rid,
ts: new Date,
msg: TAPi18n.__('error-logged-user-not-in-room', {
postProcess: 'sprintf',
sprintf: [room]
}, user.language)
});
}
rid = roomObject._id;
}

Meteor.call('hideRoom', rid, error => {
if (error) {
return RocketChat.Notifications.notifyUser(user._id, 'message', {
_id: Random.id(),
rid: item.rid,
ts: new Date,
msg: TAPi18n.__(error, null, user.language)
});
}
});
}

RocketChat.slashCommands.add('hide', Hide, { description: 'Hide_room', params: '#room' });