-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [NEW] Command /hide to hide channels * Move /hide command server side and add #room param
- Loading branch information
1 parent
8cb876f
commit acc671e
Showing
7 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
RocketChat.slashCommands.add('hide', undefined, { | ||
description: 'Hide_room', | ||
params: '#room' | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }); |