From 92641f413020565aaa73e7069874888408ebdc85 Mon Sep 17 00:00:00 2001 From: Deepak Kothandan Date: Sun, 19 Jun 2016 19:56:32 +0200 Subject: [PATCH] slash command archive room --- .meteor/packages | 1 + .meteor/versions | 1 + packages/rocketchat-lib/i18n/en.i18n.json | 3 +- .../client.js | 4 ++ .../package.js | 22 ++++++++++ .../server.js | 41 +++++++++++++++++++ 6 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 packages/rocketchat-slashcommands-archiveroom/client.js create mode 100644 packages/rocketchat-slashcommands-archiveroom/package.js create mode 100644 packages/rocketchat-slashcommands-archiveroom/server.js diff --git a/.meteor/packages b/.meteor/packages index d34c8174890..4c967e7ee81 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -147,3 +147,4 @@ todda00:friendly-slugs underscorestring:underscore.string yasaricli:slugify yasinuslu:blaze-meta +rocketchat:slashcommands-archive diff --git a/.meteor/versions b/.meteor/versions index bb7482986dd..4717258ba39 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -174,6 +174,7 @@ rocketchat:piwik@0.0.1 rocketchat:push-notifications@0.0.1 rocketchat:reactions@0.0.1 rocketchat:slackbridge@0.0.1 +rocketchat:slashcommands-archive@0.0.1 rocketchat:slashcommands-asciiarts@0.0.1 rocketchat:slashcommands-invite@0.0.1 rocketchat:slashcommands-join@0.0.1 diff --git a/packages/rocketchat-lib/i18n/en.i18n.json b/packages/rocketchat-lib/i18n/en.i18n.json index ce6bc123be9..d045318426a 100644 --- a/packages/rocketchat-lib/i18n/en.i18n.json +++ b/packages/rocketchat-lib/i18n/en.i18n.json @@ -209,6 +209,7 @@ "Certificates_and_Keys" : "Certificates and Keys", "Changing_email" : "Changing email", "Channel" : "Channel", + "Channel_Archived" : "Channel with name `#%s` has been archived successfully", "Channel_doesnt_exist" : "The channel `#%s` does not exist.", "Channels" : "Channels", "Channels_list" : "List of public channels", @@ -291,7 +292,7 @@ "Dry_run" : "Dry run", "Dry_run_description" : "Will only send one email, to the same address as in From. The email must belong to a valid user.", "Duplicate_channel_name" : "A Channel with name '%s' exists", - "Duplicate_archived_channel_name" : "An archived Channel with name '%s' exists", + "Duplicate_archived_channel_name" : "An archived Channel with name `#%s` exists", "Duplicate_archived_private_group_name" : "An archived Private Group with name '%s' exists", "Duplicate_private_group_name" : "A Private Group with name '%s' exists", "Edit" : "Edit", diff --git a/packages/rocketchat-slashcommands-archiveroom/client.js b/packages/rocketchat-slashcommands-archiveroom/client.js new file mode 100644 index 00000000000..764d8a6567e --- /dev/null +++ b/packages/rocketchat-slashcommands-archiveroom/client.js @@ -0,0 +1,4 @@ +RocketChat.slashCommands.add('archive', null, { + description: TAPi18n.__('Archive'), + params: '#channel' +}); diff --git a/packages/rocketchat-slashcommands-archiveroom/package.js b/packages/rocketchat-slashcommands-archiveroom/package.js new file mode 100644 index 00000000000..16105fe216e --- /dev/null +++ b/packages/rocketchat-slashcommands-archiveroom/package.js @@ -0,0 +1,22 @@ +Package.describe({ + name: 'rocketchat:slashcommands-archive', + version: '0.0.1', + summary: 'Command handler for the /room command', + git: '' +}); + +Package.onUse(function(api) { + + api.versionsFrom('1.0'); + + api.use([ + 'ecmascript', + 'check', + 'rocketchat:lib' + ]); + + api.use('templating', 'client'); + + api.addFiles('client.js', 'client'); + api.addFiles('server.js', 'server'); +}); diff --git a/packages/rocketchat-slashcommands-archiveroom/server.js b/packages/rocketchat-slashcommands-archiveroom/server.js new file mode 100644 index 00000000000..1b7667966ea --- /dev/null +++ b/packages/rocketchat-slashcommands-archiveroom/server.js @@ -0,0 +1,41 @@ +function Archive(command, params, item) { + var channel, room, user; + if (command !== 'archive' || !Match.test(params, String)) { + return; + } + channel = params.trim(); + if (channel === '') { + return; + } + channel = channel.replace('#', ''); + + user = Meteor.users.findOne(Meteor.userId()); + room = RocketChat.models.Rooms.findOneByName(channel); + if (room.archived) { + RocketChat.Notifications.notifyUser(Meteor.userId(), 'message', { + _id: Random.id(), + rid: item.rid, + ts: new Date(), + msg: TAPi18n.__('Duplicate_archived_channel_name', { + postProcess: 'sprintf', + sprintf: [channel] + }, user.language) + }); + return; + } + Meteor.call('archiveRoom', room._id); + + RocketChat.Notifications.notifyUser(Meteor.userId(), 'message', { + _id: Random.id(), + rid: item.rid, + ts: new Date(), + msg: TAPi18n.__('Channel_Archived', { + postProcess: 'sprintf', + sprintf: [channel] + }, user.language) + }); + + return Archive; +} + +RocketChat.slashCommands.add('archive', Archive);