parent
91210aca7b
commit
7fbc50e8d5
@ -0,0 +1,3 @@ |
||||
RocketChat.slashCommands.add 'mute', null, |
||||
description: TAPi18n.__ 'Mute_someone_in_room' |
||||
params: '@username' |
||||
@ -0,0 +1,3 @@ |
||||
RocketChat.slashCommands.add 'unmute', null, |
||||
description: TAPi18n.__ 'Unmute_someone_in_room' |
||||
params: '@username' |
||||
@ -0,0 +1,6 @@ |
||||
{ |
||||
"Username_doesnt_exist" : "The username `#%s` doesn't exist.", |
||||
"Username_is_not_in_this_room" : "The user `#%s` is not in this room.", |
||||
"Mute_someone_in_room" : "Mute someone in the room", |
||||
"Unmute_someone_in_room" : "Unmute someone in the room" |
||||
} |
||||
@ -0,0 +1,39 @@ |
||||
Package.describe({ |
||||
name: 'rocketchat:slashcommands-mute', |
||||
version: '0.0.1', |
||||
summary: 'Command handler for the /mute command', |
||||
git: '' |
||||
}); |
||||
|
||||
Package.onUse(function(api) { |
||||
|
||||
api.versionsFrom('1.0'); |
||||
|
||||
api.use([ |
||||
'coffeescript', |
||||
'check', |
||||
'rocketchat:lib@0.0.1' |
||||
]); |
||||
|
||||
api.addFiles('client/mute.coffee', 'client'); |
||||
api.addFiles('client/unmute.coffee', 'client'); |
||||
api.addFiles('server/mute.coffee', 'server'); |
||||
api.addFiles('server/unmute.coffee', 'server'); |
||||
|
||||
// TAPi18n
|
||||
api.use('templating', 'client'); |
||||
var _ = Npm.require('underscore'); |
||||
var fs = Npm.require('fs'); |
||||
tapi18nFiles = _.compact(_.map(fs.readdirSync('packages/rocketchat-slashcommands-mute/i18n'), function(filename) { |
||||
if (fs.statSync('packages/rocketchat-slashcommands-mute/i18n/' + filename).size > 16) { |
||||
return 'i18n/' + filename; |
||||
} |
||||
})); |
||||
api.use('tap:i18n@1.6.1', ['client', 'server']); |
||||
api.imply('tap:i18n'); |
||||
api.addFiles(tapi18nFiles, ['client', 'server']); |
||||
}); |
||||
|
||||
Package.onTest(function(api) { |
||||
|
||||
}); |
||||
@ -0,0 +1,40 @@ |
||||
### |
||||
# Mute is a named function that will replace /mute commands |
||||
### |
||||
|
||||
class Mute |
||||
constructor: (command, params, item) -> |
||||
if command isnt 'mute' or not Match.test params, String |
||||
return |
||||
|
||||
username = params.trim() |
||||
if username is '' |
||||
return |
||||
|
||||
username = username.replace('@', '') |
||||
|
||||
user = Meteor.users.findOne Meteor.userId() |
||||
mutedUser = RocketChat.models.Users.findOneByUsername username |
||||
room = RocketChat.models.Rooms.findOneById item.rid |
||||
|
||||
if not mutedUser? |
||||
RocketChat.Notifications.notifyUser Meteor.userId(), 'message', { |
||||
_id: Random.id() |
||||
rid: item.rid |
||||
ts: new Date |
||||
msg: TAPi18n.__('Username_doesnt_exist', { postProcess: 'sprintf', sprintf: [ username ] }, user.language); |
||||
} |
||||
return |
||||
|
||||
if username not in (room.usernames or []) |
||||
RocketChat.Notifications.notifyUser Meteor.userId(), 'message', { |
||||
_id: Random.id() |
||||
rid: item.rid |
||||
ts: new Date |
||||
msg: TAPi18n.__('Username_is_not_in_this_room', { postProcess: 'sprintf', sprintf: [ username ] }, user.language); |
||||
} |
||||
return |
||||
|
||||
Meteor.call 'muteUserInRoom', { rid: item.rid, username: username } |
||||
|
||||
RocketChat.slashCommands.add 'mute', Mute |
||||
@ -0,0 +1,40 @@ |
||||
### |
||||
# Unmute is a named function that will replace /unmute commands |
||||
### |
||||
|
||||
class Unmute |
||||
constructor: (command, params, item) -> |
||||
if command isnt 'unmute' or not Match.test params, String |
||||
return |
||||
|
||||
username = params.trim() |
||||
if username is '' |
||||
return |
||||
|
||||
username = username.replace('@', '') |
||||
|
||||
user = Meteor.users.findOne Meteor.userId() |
||||
unmutedUser = RocketChat.models.Users.findOneByUsername username |
||||
room = RocketChat.models.Rooms.findOneById item.rid |
||||
|
||||
if not unmutedUser? |
||||
RocketChat.Notifications.notifyUser Meteor.userId(), 'message', { |
||||
_id: Random.id() |
||||
rid: item.rid |
||||
ts: new Date |
||||
msg: TAPi18n.__('Username_doesnt_exist', { postProcess: 'sprintf', sprintf: [ username ] }, user.language); |
||||
} |
||||
return |
||||
|
||||
if username not in (room.usernames or []) |
||||
RocketChat.Notifications.notifyUser Meteor.userId(), 'message', { |
||||
_id: Random.id() |
||||
rid: item.rid |
||||
ts: new Date |
||||
msg: TAPi18n.__('Username_is_not_in_this_room', { postProcess: 'sprintf', sprintf: [ username ] }, user.language); |
||||
} |
||||
return |
||||
|
||||
Meteor.call 'unmuteUserInRoom', { rid: item.rid, username: username } |
||||
|
||||
RocketChat.slashCommands.add 'unmute', Unmute |
||||
@ -0,0 +1,26 @@ |
||||
Meteor.methods |
||||
muteUserInRoom: (data) -> |
||||
fromId = Meteor.userId() |
||||
console.log '[methods] muteUserInRoom -> '.green, 'fromId:', fromId, 'data:', data |
||||
|
||||
check(data, Match.ObjectIncluding({ rid: String, username: String })) |
||||
|
||||
unless RocketChat.authz.hasPermission(fromId, 'mute-user', data.rid) |
||||
throw new Meteor.Error 'not-allowed', 'Not allowed' |
||||
|
||||
room = RocketChat.models.Rooms.findOneById data.rid |
||||
|
||||
if data.username not in (room?.usernames or []) |
||||
throw new Meteor.Error 'not-in-room', 'User is not in this room' |
||||
|
||||
mutedUser = RocketChat.models.Users.findOneByUsername data.username |
||||
|
||||
RocketChat.models.Subscriptions.muteUserByRoomIdAndUserId data.rid, mutedUser._id |
||||
|
||||
fromUser = RocketChat.models.Users.findOneById fromId |
||||
RocketChat.models.Messages.createUserMutedWithRoomIdAndUser data.rid, mutedUser, |
||||
u: |
||||
_id: fromUser._id |
||||
username: fromUser.username |
||||
|
||||
return true |
||||
@ -0,0 +1,26 @@ |
||||
Meteor.methods |
||||
unmuteUserInRoom: (data) -> |
||||
fromId = Meteor.userId() |
||||
console.log '[methods] unmuteUserInRoom -> '.green, 'fromId:', fromId, 'data:', data |
||||
|
||||
check(data, Match.ObjectIncluding({ rid: String, username: String })) |
||||
|
||||
unless RocketChat.authz.hasPermission(fromId, 'mute-user', data.rid) |
||||
throw new Meteor.Error 'not-allowed', 'Not allowed' |
||||
|
||||
room = RocketChat.models.Rooms.findOneById data.rid |
||||
|
||||
if data.username not in (room?.usernames or []) |
||||
throw new Meteor.Error 'not-in-room', 'User is not in this room' |
||||
|
||||
unmutedUser = RocketChat.models.Users.findOneByUsername data.username |
||||
|
||||
RocketChat.models.Subscriptions.unmuteUserByRoomIdAndUserId data.rid, unmutedUser._id |
||||
|
||||
fromUser = RocketChat.models.Users.findOneById fromId |
||||
RocketChat.models.Messages.createUserUnmutedWithRoomIdAndUser data.rid, unmutedUser, |
||||
u: |
||||
_id: fromUser._id |
||||
username: fromUser.username |
||||
|
||||
return true |
||||
Loading…
Reference in new issue