Skip to content

Commit

Permalink
[NEW] SlashCommand /hide (#10727)
Browse files Browse the repository at this point in the history
* [NEW] Command /hide to hide channels

* Move /hide command server side and add #room param
  • Loading branch information
mikaelmello authored and ggazzo committed Jun 11, 2018
1 parent 8cb876f commit acc671e
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 1 deletion.
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:slashcommands-archive@0.0.1
rocketchat:slashcommands-asciiarts@0.0.1
rocketchat:slashcommands-create@0.0.1
rocketchat:slashcommands-help@0.0.1
rocketchat:slashcommands-hide@0.0.1
rocketchat:slashcommands-invite@0.0.1
rocketchat:slashcommands-invite-all@0.0.1
rocketchat:slashcommands-join@0.0.1
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 @@ -1065,6 +1065,7 @@
"error-user-is-not-activated": "User is not activated",
"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 @@ -2692,7 +2692,7 @@
"your_message": "sua mensagem",
"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",
"Your_push_was_sent_to_s_devices": "Sua notificação foi enviada para %s dispositivos"
"Your_server_link": "O link do seu servidor",
"Your_workspace_is_ready": "O seu espaço de trabalho está pronto a usar 🎉"
}
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' });

0 comments on commit acc671e

Please sign in to comment.