From 1a514fb4d3357c2f1286d4f680e691de699f838d Mon Sep 17 00:00:00 2001 From: Marcelo Schmidt Date: Mon, 16 Nov 2015 12:57:19 -0200 Subject: [PATCH 001/103] Channel settings: change name, topic, type --- client/methods/saveRoomName.coffee | 26 ---------- client/views/app/room.coffee | 22 ++------ client/views/app/room.html | 7 +-- i18n/en.i18n.json | 1 + .../client/views/channelSettings.coffee | 50 ++++++++++++++++--- .../client/views/channelSettings.html | 14 ++++++ .../i18n/en.i18n.json | 2 + .../rocketchat-channel-settings/package.js | 2 + .../server/functions/changeRoomTopic.coffee | 6 +++ .../server/functions/changeRoomType.coffee | 39 +-------------- .../server}/methods/saveRoomName.coffee | 4 +- .../server/methods/saveRoomSettings.coffee | 14 ++++-- .../rocketchat-lib/server/models/Rooms.coffee | 16 ++++-- .../assets/stylesheets/base.less | 6 ++- server/startup/roomPublishes.coffee | 2 + 15 files changed, 108 insertions(+), 103 deletions(-) delete mode 100644 client/methods/saveRoomName.coffee create mode 100644 packages/rocketchat-channel-settings/server/functions/changeRoomTopic.coffee rename {server => packages/rocketchat-channel-settings/server}/methods/saveRoomName.coffee (82%) diff --git a/client/methods/saveRoomName.coffee b/client/methods/saveRoomName.coffee deleted file mode 100644 index 2072d68fa0bb..000000000000 --- a/client/methods/saveRoomName.coffee +++ /dev/null @@ -1,26 +0,0 @@ -Meteor.methods - saveRoomName: (rid, name) -> - if not Meteor.userId() - throw new Meteor.Error 203, t('User_logged_out') - - room = ChatRoom.findOne rid - - if room.u._id isnt Meteor.userId() or room.t not in ['c', 'p'] - throw new Meteor.Error 403, t('Not allowed') - - name = _.slugify name - - if name is room.name - return - - ChatRoom.update rid, - $set: - name: name - - ChatSubscription.update - rid: rid - , - $set: - name: name - - return name diff --git a/client/views/app/room.coffee b/client/views/app/room.coffee index 80dd1c74fb99..4c128db8ece9 100644 --- a/client/views/app/room.coffee +++ b/client/views/app/room.coffee @@ -70,6 +70,11 @@ Template.room.helpers else return roomData.name + roomTopic: -> + roomData = Session.get('roomData' + this._id) + return '' unless roomData + return roomData.topic + roomIcon: -> roomData = Session.get('roomData' + this._id) return '' unless roomData?.t @@ -114,26 +119,9 @@ Template.room.helpers return '' unless roomData return roomData.t is 'c' - canEditName: -> - roomData = Session.get('roomData' + this._id) - return '' unless roomData - if roomData.t in ['c', 'p'] - return RocketChat.authz.hasAtLeastOnePermission('edit-room', this._id) - else - return '' - canDirectMessage: -> return Meteor.user()?.username isnt this.username - roomNameEdit: -> - return Session.get('roomData' + this._id)?.name - - editingTitle: -> - return 'hidden' if Session.get('editRoomTitle') - - showEditingTitle: -> - return 'hidden' if not Session.get('editRoomTitle') - flexOpened: -> return 'opened' if RocketChat.TabBar.isFlexOpen() diff --git a/client/views/app/room.html b/client/views/app/room.html index 3c2380b39296..3399c50d2133 100644 --- a/client/views/app/room.html +++ b/client/views/app/room.html @@ -13,11 +13,8 @@

{{/if}} - {{roomName}} - {{#if canEditName}} - - - {{/if}} + {{roomName}} + {{roomTopic}}

diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index 3c39e0ccab89..69cd384193ec 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -162,6 +162,7 @@ "Invalid_name" : "The name must not be empty", "Invalid_pass" : "The password must not be empty", "Invalid_room_name" : "%s is not a valid room name,
use only letters, numbers and dashes", + "Invalid_room_type" : "%s is not a valid room type.", "invisible" : "invisible", "Invisible" : "Invisible", "Invitation_HTML" : "Invitation HTML", diff --git a/packages/rocketchat-channel-settings/client/views/channelSettings.coffee b/packages/rocketchat-channel-settings/client/views/channelSettings.coffee index 4f9f5d344c5d..26abf2d703fb 100644 --- a/packages/rocketchat-channel-settings/client/views/channelSettings.coffee +++ b/packages/rocketchat-channel-settings/client/views/channelSettings.coffee @@ -3,6 +3,10 @@ Template.channelSettings.helpers return ChatRoom.findOne(@rid)?.t isnt 'd' roomType: -> return ChatRoom.findOne(@rid)?.t + roomName: -> + return ChatRoom.findOne(@rid)?.name + roomTopic: -> + return ChatRoom.findOne(@rid)?.topic Template.channelSettings.events 'click .save': (e, t) -> @@ -10,14 +14,44 @@ Template.channelSettings.events settings = roomType: t.$('input[name=roomType]:checked').val() + roomName: t.$('input[name=roomName]').val() + roomTopic: t.$('input[name=roomTopic]').val() - Meteor.call 'saveRoomSettings', t.data.rid, settings, (err, results) -> - return toastr.error err.reason if err - toastr.success TAPi18n.__ 'Settings_updated' + if t.validate() + Meteor.call 'saveRoomSettings', t.data.rid, settings, (err, results) -> + if err + if err.error in [ 'duplicate-name', 'name-invalid' ] + return toastr.error TAPi18n.__(err.reason, err.details.channelName) + if err.error is 'invalid-room-type' + return toastr.error TAPi18n.__(err.reason, err.details.roomType) + return toastr.error TAPi18n.__(err.reason) + toastr.success TAPi18n.__ 'Settings_updated' - # switch room.t - # when 'c' - # FlowRouter.go 'channel', name: name - # when 'p' - # FlowRouter.go 'group', name: name +Template.channelSettings.onCreated -> + @validateRoomType = => + type = @$('input[name=roomType]:checked').val() + if type not in ['c', 'p'] + toastr.error t('Invalid_room_type', type) + return true + + @validateRoomName = => + rid = Template.currentData()?.rid + room = ChatRoom.findOne rid + + if room.u._id isnt Meteor.userId() or room.t not in ['c', 'p'] + toastr.error t('Not_allowed') + return false + + name = $('input[name=roomName]').val() + if not /^[0-9a-z-_]+$/.test name + toastr.error t('Invalid_room_name', name) + return false + + return true + + @validateRoomTopic = => + return true + + @validate = => + return @validateRoomType() and @validateRoomName() and @validateRoomTopic() diff --git a/packages/rocketchat-channel-settings/client/views/channelSettings.html b/packages/rocketchat-channel-settings/client/views/channelSettings.html index c72ecae4ad66..13b76fb9cb74 100644 --- a/packages/rocketchat-channel-settings/client/views/channelSettings.html +++ b/packages/rocketchat-channel-settings/client/views/channelSettings.html @@ -7,6 +7,20 @@

{{_ "Room_Settings"}}

+ {{#if notDirect}} +
+ +
+ +
+
+ {{/if}} +
+ +
+ +
+
{{#if notDirect}}
diff --git a/packages/rocketchat-channel-settings/i18n/en.i18n.json b/packages/rocketchat-channel-settings/i18n/en.i18n.json index ba1d6c016df5..3100cf532a87 100644 --- a/packages/rocketchat-channel-settings/i18n/en.i18n.json +++ b/packages/rocketchat-channel-settings/i18n/en.i18n.json @@ -1,6 +1,8 @@ { "Channel": "Channel", "Private_Group": "Private Group", + "Room_Name": "Room Name", + "Room_Topic": "Room Topic", "Room_Type": "Room Type", "Room_Settings": "Room Settings", "room_changed_privacy": "Room type changed to: __room_type__ by __user_by__", diff --git a/packages/rocketchat-channel-settings/package.js b/packages/rocketchat-channel-settings/package.js index 06b8f3fe128a..eaffbdf1f567 100644 --- a/packages/rocketchat-channel-settings/package.js +++ b/packages/rocketchat-channel-settings/package.js @@ -26,6 +26,8 @@ Package.onUse(function(api) { api.addFiles([ 'server/functions/changeRoomType.coffee', + 'server/functions/changeRoomTopic.coffee', + 'server/methods/saveRoomName.coffee', 'server/methods/saveRoomSettings.coffee', 'server/models/Messages.coffee' ], 'server'); diff --git a/packages/rocketchat-channel-settings/server/functions/changeRoomTopic.coffee b/packages/rocketchat-channel-settings/server/functions/changeRoomTopic.coffee new file mode 100644 index 000000000000..9fd7c3f3ea64 --- /dev/null +++ b/packages/rocketchat-channel-settings/server/functions/changeRoomTopic.coffee @@ -0,0 +1,6 @@ +RocketChat.changeRoomTopic = (rid, roomTopic) -> + unless Match.test rid, String + throw new Meteor.Error 'invalid-rid' + + console.log '[function] RocketChat.changeRoomTopic'.green, rid, roomTopic + return RocketChat.models.Rooms.setTopicById(rid, roomTopic) diff --git a/packages/rocketchat-channel-settings/server/functions/changeRoomType.coffee b/packages/rocketchat-channel-settings/server/functions/changeRoomType.coffee index e9c89567302e..6885b59b03cd 100644 --- a/packages/rocketchat-channel-settings/server/functions/changeRoomType.coffee +++ b/packages/rocketchat-channel-settings/server/functions/changeRoomType.coffee @@ -5,43 +5,6 @@ RocketChat.changeRoomType = (rid, roomType) -> throw new Meteor.Error 'invalid-rid' if roomType not in ['c', 'p'] - throw new Meteor.Error 'invalid-room-type' + throw new Meteor.Error 'invalid-room-type', 'Invalid_room_type', { roomType: roomType } return RocketChat.models.Rooms.setTypeById(rid, roomType) and RocketChat.models.Subscriptions.updateTypeByRoomId(rid, roomType) - - - # username = s.trim username - # if not user or not username - # return false - - # if not /^[0-9a-zA-Z-_.]+$/.test username - # return false - - # # User already has desired username, return - # if user.username is username - # return user - - # # Check username availability - # unless RocketChat.checkUsernameAvailability username - # return false - - # previousUsername = user.username - - # # Username is available; if coming from old username, update all references - # if previousUsername - # RocketChat.models.Messages.updateAllUsernamesByUserId user._id, username - - # RocketChat.models.Messages.findByMention(previousUsername).forEach (msg) -> - # updatedMsg = msg.msg.replace(new RegExp("@#{previousUsername}", "ig"), "@#{username}") - # RocketChat.models.Messages.updateUsernameAndMessageOfMentionByIdAndOldUsername msg._id, previousUsername, username, updatedMsg - - # RocketChat.models.Rooms.replaceUsername previousUsername, username - # RocketChat.models.Rooms.replaceUsernameOfUserByUserId user._id, username - - # RocketChat.models.Subscriptions.setUserUsernameByUserId user._id, username - # RocketChat.models.Subscriptions.setNameForDirectRoomsWithOldName previousUsername, username - - # # Set new username - # Meteor.users.update { _id: user._id }, { $set: { username: username } } - # user.username = username - # return user diff --git a/server/methods/saveRoomName.coffee b/packages/rocketchat-channel-settings/server/methods/saveRoomName.coffee similarity index 82% rename from server/methods/saveRoomName.coffee rename to packages/rocketchat-channel-settings/server/methods/saveRoomName.coffee index 7dba0b2d710a..2dddd5344230 100644 --- a/server/methods/saveRoomName.coffee +++ b/packages/rocketchat-channel-settings/server/methods/saveRoomName.coffee @@ -13,7 +13,7 @@ Meteor.methods throw new Meteor.Error 403, 'Not allowed' if not /^[0-9a-z-_]+$/.test name - throw new Meteor.Error 'name-invalid' + throw new Meteor.Error 'name-invalid', 'Invalid_room_name', { channelName: name } name = _.slugify name @@ -22,7 +22,7 @@ Meteor.methods # avoid duplicate names if RocketChat.models.Rooms.findOneByName name - throw new Meteor.Error 'duplicate-name' + throw new Meteor.Error 'duplicate-name', 'Duplicate_channel_name', { channelName: name } RocketChat.models.Rooms.setNameById rid, name diff --git a/packages/rocketchat-channel-settings/server/methods/saveRoomSettings.coffee b/packages/rocketchat-channel-settings/server/methods/saveRoomSettings.coffee index 6375bf5f2891..340a0feeabc0 100644 --- a/packages/rocketchat-channel-settings/server/methods/saveRoomSettings.coffee +++ b/packages/rocketchat-channel-settings/server/methods/saveRoomSettings.coffee @@ -3,10 +3,10 @@ Meteor.methods console.log '[method] saveRoomSettings'.green, rid, settings unless Match.test rid, String - throw new Meteor.Error 'invalid-rid' + throw new Meteor.Error 'invalid-rid', 'Invalid room' - unless Match.test settings, Match.ObjectIncluding { roomType: String } - throw new Meteor.Error 'invalid-settings' + unless Match.test settings, Match.ObjectIncluding { roomName: String, roomTopic: String, roomType: String } + throw new Meteor.Error 'invalid-settings', 'Invalid settings provided' unless RocketChat.authz.hasPermission(Meteor.userId(), 'edit-room', rid) throw new Meteor.Error 503, 'Not authorized' @@ -23,4 +23,12 @@ Meteor.methods RocketChat.models.Messages.createRoomSettingsChangedWithTypeRoomIdMessageAndUser 'room_changed_privacy', rid, message, Meteor.user() + if settings.roomName isnt room.name + name = Meteor.call 'saveRoomName', rid, settings.roomName + + if settings.roomTopic isnt room.topic + RocketChat.changeRoomTopic(rid, settings.roomTopic) + message = settings.roomTopic + RocketChat.models.Messages.createRoomSettingsChangedWithTypeRoomIdMessageAndUser 'room_changed_topic', rid, message, Meteor.user() + return true diff --git a/packages/rocketchat-lib/server/models/Rooms.coffee b/packages/rocketchat-lib/server/models/Rooms.coffee index dddc8f8c0216..0ccfb2519b9a 100644 --- a/packages/rocketchat-lib/server/models/Rooms.coffee +++ b/packages/rocketchat-lib/server/models/Rooms.coffee @@ -291,15 +291,25 @@ RocketChat.models.Rooms = new class extends RocketChat.models._Base return @update query, update setTypeById: (_id, type) -> - query = + query = _id: _id - update = - $set: + update = + $set: t: type return @update query, update + setTopicById: (_id, topic) -> + query = + _id: _id + + update = + $set: + topic: topic + + return @update query, update + # INSERT createWithTypeNameUserAndUsernames: (type, name, user, usernames, extraData) -> diff --git a/packages/rocketchat-theme/assets/stylesheets/base.less b/packages/rocketchat-theme/assets/stylesheets/base.less index c8a913a1aa36..c7610498524e 100644 --- a/packages/rocketchat-theme/assets/stylesheets/base.less +++ b/packages/rocketchat-theme/assets/stylesheets/base.less @@ -1989,7 +1989,11 @@ a.github-fork { height: 100%; top: 0; left: 0; - + .room-topic { + font-size: 14px; + opacity: 0.4; + margin-left: 10px; + } .edit-room-title { margin-left: 4px; font-size: 16px; diff --git a/server/startup/roomPublishes.coffee b/server/startup/roomPublishes.coffee index ae5cdd0225f3..d7561a38b16c 100644 --- a/server/startup/roomPublishes.coffee +++ b/server/startup/roomPublishes.coffee @@ -7,6 +7,7 @@ Meteor.startup -> cl: 1 u: 1 usernames: 1 + topic: 1 return RocketChat.models.Rooms.findByTypeAndName 'c', identifier, options RocketChat.roomTypes.addPublish 'p', (identifier) -> @@ -17,6 +18,7 @@ Meteor.startup -> cl: 1 u: 1 usernames: 1 + topic: 1 user = RocketChat.models.Users.findOneById this.userId, fields: username: 1 return RocketChat.models.Rooms.findByTypeAndNameContainigUsername 'p', identifier, user.username, options From 2ddcf2c50ca53646868a3a0c897822366d748cd9 Mon Sep 17 00:00:00 2001 From: Marcelo Schmidt Date: Mon, 16 Nov 2015 15:23:22 -0200 Subject: [PATCH 002/103] Redesign --- client/lib/trackRoomNameChanged.coffee | 12 ----- client/views/app/room.coffee | 45 ------------------- .../client/startup/tabBar.coffee | 2 +- .../client/startup/trackSettingsChange.coffee | 12 +++++ .../client/stylesheets/channel-settings.less | 12 +++++ .../client/views/channelSettings.coffee | 6 +++ .../client/views/channelSettings.html | 29 +++++++----- .../i18n/en.i18n.json | 6 +-- .../rocketchat-channel-settings/package.js | 6 +-- .../server/functions/saveRoomName.coffee | 29 ++++++++++++ ...eRoomTopic.coffee => saveRoomTopic.coffee} | 4 +- ...ngeRoomType.coffee => saveRoomType.coffee} | 4 +- .../server/methods/saveRoomName.coffee | 33 -------------- .../server/methods/saveRoomSettings.coffee | 14 +++--- .../server/models/Messages.coffee | 3 ++ .../server/models/Messages.coffee | 4 -- 16 files changed, 99 insertions(+), 122 deletions(-) delete mode 100644 client/lib/trackRoomNameChanged.coffee create mode 100644 packages/rocketchat-channel-settings/server/functions/saveRoomName.coffee rename packages/rocketchat-channel-settings/server/functions/{changeRoomTopic.coffee => saveRoomTopic.coffee} (51%) rename packages/rocketchat-channel-settings/server/functions/{changeRoomType.coffee => saveRoomType.coffee} (72%) delete mode 100644 packages/rocketchat-channel-settings/server/methods/saveRoomName.coffee diff --git a/client/lib/trackRoomNameChanged.coffee b/client/lib/trackRoomNameChanged.coffee deleted file mode 100644 index 8b3a0769feba..000000000000 --- a/client/lib/trackRoomNameChanged.coffee +++ /dev/null @@ -1,12 +0,0 @@ -Meteor.startup -> - roomNameChangedCallback = (msg) -> - Tracker.nonreactive -> - if msg.t is 'r' - if Session.get('openedRoom') is msg.rid - type = if FlowRouter.current().route.name is 'channel' then 'c' else 'p' - RoomManager.close type + FlowRouter.getParam('name') - FlowRouter.go FlowRouter.current().route.name, name: msg.msg - - return msg - - RocketChat.callbacks.add 'streamMessage', roomNameChangedCallback, RocketChat.callbacks.priority.HIGH diff --git a/client/views/app/room.coffee b/client/views/app/room.coffee index 4c128db8ece9..f13aa98a9702 100644 --- a/client/views/app/room.coffee +++ b/client/views/app/room.coffee @@ -329,18 +329,6 @@ Template.room.events $('#room-title-field').focus().select() , 10 - 'keydown #room-title-field': (event) -> - if event.keyCode is 27 # esc - Session.set('editRoomTitle', false) - else if event.keyCode is 13 # enter - renameRoom @_id, $(event.currentTarget).val() - - 'blur #room-title-field': (event) -> - # TUDO: create a configuration to select the desired behaviour - # renameRoom this._id, $(event.currentTarget).val() - Session.set('editRoomTitle', false) - $(".fixed-title").removeClass "visible" - "click .flex-tab .user-image > a" : (e) -> RocketChat.TabBar.openFlex() Session.set('showUserInfo', $(e.currentTarget).data('username')) @@ -613,36 +601,3 @@ Template.room.onRendered -> if webrtc.localUrl.get()? RocketChat.TabBar.setTemplate 'membersList' RocketChat.TabBar.openFlex() - - -renameRoom = (rid, name) -> - name = name?.toLowerCase().trim() - console.log 'room renameRoom' if window.rocketDebug - room = Session.get('roomData' + rid) - if room.name is name - Session.set('editRoomTitle', false) - return false - - Meteor.call 'saveRoomName', rid, name, (error, result) -> - if result - Session.set('editRoomTitle', false) - # If room was renamed then close current room and send user to the new one - RoomManager.close room.t + room.name - switch room.t - when 'c' - FlowRouter.go 'channel', name: name - when 'p' - FlowRouter.go 'group', name: name - - toastr.success t('Room_name_changed_successfully') - if error - if error.error is 'name-invalid' - toastr.error t('Invalid_room_name', name) - return - if error.error is 'duplicate-name' - if room.t is 'c' - toastr.error t('Duplicate_channel_name', name) - else - toastr.error t('Duplicate_private_group_name', name) - return - toastr.error error.reason diff --git a/packages/rocketchat-channel-settings/client/startup/tabBar.coffee b/packages/rocketchat-channel-settings/client/startup/tabBar.coffee index 17d1680317e5..487be2c65a72 100644 --- a/packages/rocketchat-channel-settings/client/startup/tabBar.coffee +++ b/packages/rocketchat-channel-settings/client/startup/tabBar.coffee @@ -6,7 +6,7 @@ Meteor.startup -> RocketChat.TabBar.addButton id: 'channel-settings' i18nTitle: 'Channel_Settings' - icon: 'octicon octicon-gear' + icon: 'octicon octicon-info' template: 'channelSettings' order: 0 , RocketChat.callbacks.priority.MEDIUM, 'enter-room-tabbar-channel-settings' diff --git a/packages/rocketchat-channel-settings/client/startup/trackSettingsChange.coffee b/packages/rocketchat-channel-settings/client/startup/trackSettingsChange.coffee index b3618dd7232e..4594215267d1 100644 --- a/packages/rocketchat-channel-settings/client/startup/trackSettingsChange.coffee +++ b/packages/rocketchat-channel-settings/client/startup/trackSettingsChange.coffee @@ -13,3 +13,15 @@ Meteor.startup -> return msg RocketChat.callbacks.add 'streamMessage', roomSettingsChangedCallback, RocketChat.callbacks.priority.HIGH + + roomNameChangedCallback = (msg) -> + Tracker.nonreactive -> + if msg.t is 'r' + if Session.get('openedRoom') is msg.rid + type = if FlowRouter.current().route.name is 'channel' then 'c' else 'p' + RoomManager.close type + FlowRouter.getParam('name') + FlowRouter.go FlowRouter.current().route.name, name: msg.msg + + return msg + + RocketChat.callbacks.add 'streamMessage', roomNameChangedCallback, RocketChat.callbacks.priority.HIGH diff --git a/packages/rocketchat-channel-settings/client/stylesheets/channel-settings.less b/packages/rocketchat-channel-settings/client/stylesheets/channel-settings.less index 0227c11170d8..05f745e0abc5 100644 --- a/packages/rocketchat-channel-settings/client/stylesheets/channel-settings.less +++ b/packages/rocketchat-channel-settings/client/stylesheets/channel-settings.less @@ -15,3 +15,15 @@ } } } + +.input-line.double-col { + div { + line-height: 15px; + padding: 10px 20px 10px 0; + i.octicon { + font-size: 13px; + opacity: 0.4; + vertical-align: top; + } + } +} diff --git a/packages/rocketchat-channel-settings/client/views/channelSettings.coffee b/packages/rocketchat-channel-settings/client/views/channelSettings.coffee index 26abf2d703fb..a56bc8f54cb6 100644 --- a/packages/rocketchat-channel-settings/client/views/channelSettings.coffee +++ b/packages/rocketchat-channel-settings/client/views/channelSettings.coffee @@ -1,8 +1,14 @@ Template.channelSettings.helpers + canEdit: -> + return true + editing: (field) -> + return false notDirect: -> return ChatRoom.findOne(@rid)?.t isnt 'd' roomType: -> return ChatRoom.findOne(@rid)?.t + roomTypeDescription: -> + return if ChatRoom.findOne(@rid)?.t is 'c' then t('Channel') else t('Private_Group') roomName: -> return ChatRoom.findOne(@rid)?.name roomTopic: -> diff --git a/packages/rocketchat-channel-settings/client/views/channelSettings.html b/packages/rocketchat-channel-settings/client/views/channelSettings.html index 13b76fb9cb74..36a5cc72b4b2 100644 --- a/packages/rocketchat-channel-settings/client/views/channelSettings.html +++ b/packages/rocketchat-channel-settings/client/views/channelSettings.html @@ -9,31 +9,40 @@

{{_ "Room_Settings"}}

{{#if notDirect}}
- +
- + {{#if editing 'roomName'}} + + {{else}} + {{roomName}}{{#if canEdit}} {{/if}} + {{/if}}
{{/if}}
- +
- + {{#if editing 'roomTopic'}} + + {{else}} + {{roomTopic}}{{#if canEdit}} {{/if}} + {{/if}}
{{#if notDirect}}
- +
- - + {{#if editing 'roomType'}} + + + {{else}} + {{roomTypeDescription}}{{#if canEdit}} {{/if}} + {{/if}}
{{/if}}
-
- -
diff --git a/packages/rocketchat-channel-settings/i18n/en.i18n.json b/packages/rocketchat-channel-settings/i18n/en.i18n.json index 3100cf532a87..1191953e3ba8 100644 --- a/packages/rocketchat-channel-settings/i18n/en.i18n.json +++ b/packages/rocketchat-channel-settings/i18n/en.i18n.json @@ -1,9 +1,9 @@ { "Channel": "Channel", "Private_Group": "Private Group", - "Room_Name": "Room Name", - "Room_Topic": "Room Topic", - "Room_Type": "Room Type", + "Name": "Name", + "Topic": "Topic", + "Type": "Type", "Room_Settings": "Room Settings", "room_changed_privacy": "Room type changed to: __room_type__ by __user_by__", "room_changed_topic": "Room topic changed to: __room_topic__ by __user_by__" diff --git a/packages/rocketchat-channel-settings/package.js b/packages/rocketchat-channel-settings/package.js index eaffbdf1f567..127e12269405 100644 --- a/packages/rocketchat-channel-settings/package.js +++ b/packages/rocketchat-channel-settings/package.js @@ -25,9 +25,9 @@ Package.onUse(function(api) { ], 'client'); api.addFiles([ - 'server/functions/changeRoomType.coffee', - 'server/functions/changeRoomTopic.coffee', - 'server/methods/saveRoomName.coffee', + 'server/functions/saveRoomType.coffee', + 'server/functions/saveRoomTopic.coffee', + 'server/functions/saveRoomName.coffee', 'server/methods/saveRoomSettings.coffee', 'server/models/Messages.coffee' ], 'server'); diff --git a/packages/rocketchat-channel-settings/server/functions/saveRoomName.coffee b/packages/rocketchat-channel-settings/server/functions/saveRoomName.coffee new file mode 100644 index 000000000000..9833b88764b2 --- /dev/null +++ b/packages/rocketchat-channel-settings/server/functions/saveRoomName.coffee @@ -0,0 +1,29 @@ +RocketChat.saveRoomName = (rid, name) -> + if not Meteor.userId() + throw new Meteor.Error('invalid-user', "[methods] sendMessage -> Invalid user") + + room = RocketChat.models.Rooms.findOneById rid + + if room.t not in ['c', 'p'] + throw new Meteor.Error 403, 'Not allowed' + + unless RocketChat.authz.hasPermission(Meteor.userId(), 'edit-room', rid) + #if room.u._id isnt Meteor.userId() and not hasPermission + throw new Meteor.Error 403, 'Not allowed' + + if not /^[0-9a-z-_]+$/.test name + throw new Meteor.Error 'name-invalid', 'Invalid_room_name', { channelName: name } + + name = _.slugify name + + if name is room.name + return + + # avoid duplicate names + if RocketChat.models.Rooms.findOneByName name + throw new Meteor.Error 'duplicate-name', 'Duplicate_channel_name', { channelName: name } + + RocketChat.models.Rooms.setNameById rid, name + RocketChat.models.Subscriptions.updateNameByRoomId rid, name + + return name diff --git a/packages/rocketchat-channel-settings/server/functions/changeRoomTopic.coffee b/packages/rocketchat-channel-settings/server/functions/saveRoomTopic.coffee similarity index 51% rename from packages/rocketchat-channel-settings/server/functions/changeRoomTopic.coffee rename to packages/rocketchat-channel-settings/server/functions/saveRoomTopic.coffee index 9fd7c3f3ea64..6c08f38edfeb 100644 --- a/packages/rocketchat-channel-settings/server/functions/changeRoomTopic.coffee +++ b/packages/rocketchat-channel-settings/server/functions/saveRoomTopic.coffee @@ -1,6 +1,6 @@ -RocketChat.changeRoomTopic = (rid, roomTopic) -> +RocketChat.saveRoomTopic = (rid, roomTopic) -> unless Match.test rid, String throw new Meteor.Error 'invalid-rid' - console.log '[function] RocketChat.changeRoomTopic'.green, rid, roomTopic + console.log '[function] RocketChat.saveRoomTopic'.green, rid, roomTopic return RocketChat.models.Rooms.setTopicById(rid, roomTopic) diff --git a/packages/rocketchat-channel-settings/server/functions/changeRoomType.coffee b/packages/rocketchat-channel-settings/server/functions/saveRoomType.coffee similarity index 72% rename from packages/rocketchat-channel-settings/server/functions/changeRoomType.coffee rename to packages/rocketchat-channel-settings/server/functions/saveRoomType.coffee index 6885b59b03cd..5cd6d4c5259b 100644 --- a/packages/rocketchat-channel-settings/server/functions/changeRoomType.coffee +++ b/packages/rocketchat-channel-settings/server/functions/saveRoomType.coffee @@ -1,5 +1,5 @@ -RocketChat.changeRoomType = (rid, roomType) -> - console.log '[function] RocketChat.changeRoomType'.green, rid, roomType +RocketChat.saveRoomType = (rid, roomType) -> + console.log '[function] RocketChat.saveRoomType'.green, rid, roomType unless Match.test rid, String throw new Meteor.Error 'invalid-rid' diff --git a/packages/rocketchat-channel-settings/server/methods/saveRoomName.coffee b/packages/rocketchat-channel-settings/server/methods/saveRoomName.coffee deleted file mode 100644 index 2dddd5344230..000000000000 --- a/packages/rocketchat-channel-settings/server/methods/saveRoomName.coffee +++ /dev/null @@ -1,33 +0,0 @@ -Meteor.methods - saveRoomName: (rid, name) -> - if not Meteor.userId() - throw new Meteor.Error('invalid-user', "[methods] sendMessage -> Invalid user") - - room = RocketChat.models.Rooms.findOneById rid - - if room.t not in ['c', 'p'] - throw new Meteor.Error 403, 'Not allowed' - - unless RocketChat.authz.hasPermission(Meteor.userId(), 'edit-room', rid) - #if room.u._id isnt Meteor.userId() and not hasPermission - throw new Meteor.Error 403, 'Not allowed' - - if not /^[0-9a-z-_]+$/.test name - throw new Meteor.Error 'name-invalid', 'Invalid_room_name', { channelName: name } - - name = _.slugify name - - if name is room.name - return - - # avoid duplicate names - if RocketChat.models.Rooms.findOneByName name - throw new Meteor.Error 'duplicate-name', 'Duplicate_channel_name', { channelName: name } - - RocketChat.models.Rooms.setNameById rid, name - - RocketChat.models.Subscriptions.updateNameByRoomId rid, name - - RocketChat.models.Messages.createRoomRenamedWithRoomIdRoomNameAndUser rid, name, Meteor.user() - - return name diff --git a/packages/rocketchat-channel-settings/server/methods/saveRoomSettings.coffee b/packages/rocketchat-channel-settings/server/methods/saveRoomSettings.coffee index 340a0feeabc0..9cc15ad6fb40 100644 --- a/packages/rocketchat-channel-settings/server/methods/saveRoomSettings.coffee +++ b/packages/rocketchat-channel-settings/server/methods/saveRoomSettings.coffee @@ -13,8 +13,12 @@ Meteor.methods room = RocketChat.models.Rooms.findOneById rid if room? + if settings.roomName isnt room.name + name = RocketChat.saveRoomName rid, settings.roomName + RocketChat.models.Messages.createRoomRenamedWithRoomIdRoomNameAndUser rid, name, Meteor.user() + if settings.roomType isnt room.t - RocketChat.changeRoomType(rid, settings.roomType) + RocketChat.saveRoomType(rid, settings.roomType) if settings.roomType is 'c' message = TAPi18n.__('Channel') @@ -23,12 +27,8 @@ Meteor.methods RocketChat.models.Messages.createRoomSettingsChangedWithTypeRoomIdMessageAndUser 'room_changed_privacy', rid, message, Meteor.user() - if settings.roomName isnt room.name - name = Meteor.call 'saveRoomName', rid, settings.roomName - if settings.roomTopic isnt room.topic - RocketChat.changeRoomTopic(rid, settings.roomTopic) - message = settings.roomTopic - RocketChat.models.Messages.createRoomSettingsChangedWithTypeRoomIdMessageAndUser 'room_changed_topic', rid, message, Meteor.user() + RocketChat.saveRoomTopic(rid, settings.roomTopic) + RocketChat.models.Messages.createRoomSettingsChangedWithTypeRoomIdMessageAndUser 'room_changed_topic', rid, settings.roomTopic, Meteor.user() return true diff --git a/packages/rocketchat-channel-settings/server/models/Messages.coffee b/packages/rocketchat-channel-settings/server/models/Messages.coffee index 0a8e900e45d4..9a72fcd32bb0 100644 --- a/packages/rocketchat-channel-settings/server/models/Messages.coffee +++ b/packages/rocketchat-channel-settings/server/models/Messages.coffee @@ -1,2 +1,5 @@ RocketChat.models.Messages.createRoomSettingsChangedWithTypeRoomIdMessageAndUser = (type, roomId, message, user, extraData) -> return @createWithTypeRoomIdMessageAndUser type, roomId, message, user, extraData + +RocketChat.models.Messages.createRoomRenamedWithRoomIdRoomNameAndUser = (roomId, roomName, user, extraData) -> + return @createWithTypeRoomIdMessageAndUser 'r', roomId, roomName, user, extraData diff --git a/packages/rocketchat-lib/server/models/Messages.coffee b/packages/rocketchat-lib/server/models/Messages.coffee index 7c7d85c224a5..523309c14b8a 100644 --- a/packages/rocketchat-lib/server/models/Messages.coffee +++ b/packages/rocketchat-lib/server/models/Messages.coffee @@ -258,10 +258,6 @@ RocketChat.models.Messages = new class extends RocketChat.models._Base message = user.username return @createWithTypeRoomIdMessageAndUser 'au', roomId, message, user, extraData - createRoomRenamedWithRoomIdRoomNameAndUser: (roomId, roomName, user, extraData) -> - return @createWithTypeRoomIdMessageAndUser 'r', roomId, roomName, user, extraData - - # REMOVE removeById: (_id) -> query = From 5d5beb6da06d3470c124a6f797ff0208de494bdc Mon Sep 17 00:00:00 2001 From: Marcelo Schmidt Date: Wed, 9 Dec 2015 12:59:23 -0200 Subject: [PATCH 003/103] Merge --- packages/rocketchat-ui/package.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/rocketchat-ui/package.js b/packages/rocketchat-ui/package.js index af4028150c00..b5b3a7e08533 100644 --- a/packages/rocketchat-ui/package.js +++ b/packages/rocketchat-ui/package.js @@ -55,7 +55,6 @@ Package.onUse(function(api) { api.addFiles('lib/sideNav.coffee', 'client'); api.addFiles('lib/tapi18n.coffee', 'client'); api.addFiles('lib/textarea-autogrow.js', 'client'); - api.addFiles('lib/trackRoomNameChanged.coffee', 'client'); // LIB CORDOVA api.addFiles('lib/cordova/facebook-login.coffee', 'client'); From fd81049609d776fac1a0fb85ed30569baf3e2738 Mon Sep 17 00:00:00 2001 From: Matthias Brun Date: Thu, 10 Dec 2015 10:50:54 +0100 Subject: [PATCH 004/103] Add archive/unarchive button in the channel settings --- i18n/en.i18n.json | 2 ++ .../client/views/channelSettings.coffee | 15 +++++++++++++++ .../client/views/channelSettings.html | 11 +++++++++++ .../server/models/Subscriptions.coffee | 2 +- server/methods/unarchiveRoom.coffee | 6 +++--- server/startup/roomPublishes.coffee | 2 ++ 6 files changed, 34 insertions(+), 4 deletions(-) diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index 1b4ee2753961..d74bd48653c9 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -74,6 +74,7 @@ "API_Embed" : "Embed", "API_EmbedDisabledFor" : "Disable Embed for Users", "API_EmbedDisabledFor_Description" : "Comma-separated list of usernames", + "Archive" : "Archive", "are_also_typing" : "are also typing", "are_typing" : "are typing", "Are_you_sure" : "Are you sure?", @@ -452,6 +453,7 @@ "There_is_no_integrations" : "There is no integrations", "This_is_a_push_test_messsage" : "This is a push test messsage", "True" : "True", + "Unarchive" : "Unarchive", "Unnamed" : "Unnamed", "Unread_Rooms" : "Unread Rooms", "Unread_Rooms_Mode" : "Unread Rooms Mode", diff --git a/packages/rocketchat-channel-settings/client/views/channelSettings.coffee b/packages/rocketchat-channel-settings/client/views/channelSettings.coffee index 4f9f5d344c5d..18a254406ca7 100644 --- a/packages/rocketchat-channel-settings/client/views/channelSettings.coffee +++ b/packages/rocketchat-channel-settings/client/views/channelSettings.coffee @@ -3,6 +3,8 @@ Template.channelSettings.helpers return ChatRoom.findOne(@rid)?.t isnt 'd' roomType: -> return ChatRoom.findOne(@rid)?.t + archived: -> + return ChatRoom.findOne(@rid)?.archived Template.channelSettings.events 'click .save': (e, t) -> @@ -15,6 +17,19 @@ Template.channelSettings.events return toastr.error err.reason if err toastr.success TAPi18n.__ 'Settings_updated' + 'click .archive': (e, t) -> + e.preventDefault() + + Meteor.call 'archiveRoom', t.data.rid, true, (err, results) -> + return toastr.error err.reason if err + toastr.success 'Channel archived' + + 'click .unarchive': (e, t) -> + e.preventDefault() + + Meteor.call 'unarchiveRoom', t.data.rid, true, (err, results) -> + return toastr.error err.reason if err + toastr.success 'Channel unarchived' # switch room.t # when 'c' diff --git a/packages/rocketchat-channel-settings/client/views/channelSettings.html b/packages/rocketchat-channel-settings/client/views/channelSettings.html index c72ecae4ad66..a14bf375e922 100644 --- a/packages/rocketchat-channel-settings/client/views/channelSettings.html +++ b/packages/rocketchat-channel-settings/client/views/channelSettings.html @@ -21,5 +21,16 @@

{{_ "Room_Settings"}}

+
+ {{#if notDirect}} +
+ {{#if archived}} + + {{else}} + + {{/if}} +
+ {{/if}} +
diff --git a/packages/rocketchat-lib/server/models/Subscriptions.coffee b/packages/rocketchat-lib/server/models/Subscriptions.coffee index 20910f4e03d8..245f8b987a05 100644 --- a/packages/rocketchat-lib/server/models/Subscriptions.coffee +++ b/packages/rocketchat-lib/server/models/Subscriptions.coffee @@ -54,7 +54,7 @@ RocketChat.models.Subscriptions = new class extends RocketChat.models._Base update = $set: alert: false - open: false + open: true archived: false return @update query, update diff --git a/server/methods/unarchiveRoom.coffee b/server/methods/unarchiveRoom.coffee index eed9cbfdc2d0..b599865f0849 100644 --- a/server/methods/unarchiveRoom.coffee +++ b/server/methods/unarchiveRoom.coffee @@ -1,9 +1,9 @@ Meteor.methods - unArchiveRoom: (rid) -> + unarchiveRoom: (rid) -> if not Meteor.userId() - throw new Meteor.Error 'invalid-user', '[methods] unArchiveRoom -> Invalid user' + throw new Meteor.Error 'invalid-user', '[methods] unarchiveRoom -> Invalid user' - console.log '[methods] unArchiveRoom -> '.green, 'userId:', Meteor.userId(), 'arguments:', arguments + console.log '[methods] unarchiveRoom -> '.green, 'userId:', Meteor.userId(), 'arguments:', arguments room = RocketChat.models.Rooms.findOneById rid diff --git a/server/startup/roomPublishes.coffee b/server/startup/roomPublishes.coffee index 409131cc9b47..182c96d609a6 100644 --- a/server/startup/roomPublishes.coffee +++ b/server/startup/roomPublishes.coffee @@ -7,6 +7,7 @@ Meteor.startup -> cl: 1 u: 1 usernames: 1 + archived: 1 return RocketChat.models.Rooms.findByTypeAndName 'c', identifier, options RocketChat.roomTypes.setPublish 'p', (identifier) -> @@ -17,6 +18,7 @@ Meteor.startup -> cl: 1 u: 1 usernames: 1 + archived: 1 user = RocketChat.models.Users.findOneById this.userId, fields: username: 1 return RocketChat.models.Rooms.findByTypeAndNameContainigUsername 'p', identifier, user.username, options From bd2c75f17cfa3dbaa7177c7b14b0def74bf9fe94 Mon Sep 17 00:00:00 2001 From: Matthias Brun Date: Thu, 10 Dec 2015 11:05:26 +0100 Subject: [PATCH 005/103] Prevent archived rooms from showing up in the list of all channels --- packages/rocketchat-lib/server/models/Rooms.coffee | 11 +++++++++++ server/methods/channelsList.coffee | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/rocketchat-lib/server/models/Rooms.coffee b/packages/rocketchat-lib/server/models/Rooms.coffee index e1588bc54841..6db1614eb469 100644 --- a/packages/rocketchat-lib/server/models/Rooms.coffee +++ b/packages/rocketchat-lib/server/models/Rooms.coffee @@ -147,6 +147,17 @@ RocketChat.models.Rooms = new class extends RocketChat.models._Base return @find query, options + findByTypeAndArchivationState: (type, archivationstate, options) -> + query = + t: type + + if archivationstate + query.archived = true + else + query.archived = { $ne: true } + + return @find query, options + findByVisitorToken: (visitorToken, options) -> query = "v.token": visitorToken diff --git a/server/methods/channelsList.coffee b/server/methods/channelsList.coffee index 7aa42ff63518..c57d66e3a547 100644 --- a/server/methods/channelsList.coffee +++ b/server/methods/channelsList.coffee @@ -1,3 +1,3 @@ Meteor.methods channelsList: -> - return { channels: RocketChat.models.Rooms.findByType('c', { sort: { msgs:-1 } }).fetch() } + return { channels: RocketChat.models.Rooms.findByTypeAndArchivationState('c', false, { sort: { msgs:-1 } }).fetch() } From bb0590eb0c2a314fafb8709014dcd8719489cfbe Mon Sep 17 00:00:00 2001 From: Matthias Brun Date: Thu, 10 Dec 2015 11:13:35 +0100 Subject: [PATCH 006/103] Prevent archived private groups from showing up in the list of all private groups --- .../rocketchat-ui-sidenav/side-nav/listPrivateGroupsFlex.coffee | 2 +- server/publications/subscription.coffee | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/rocketchat-ui-sidenav/side-nav/listPrivateGroupsFlex.coffee b/packages/rocketchat-ui-sidenav/side-nav/listPrivateGroupsFlex.coffee index 08ea0d9eb0c7..1c4e3d423b69 100644 --- a/packages/rocketchat-ui-sidenav/side-nav/listPrivateGroupsFlex.coffee +++ b/packages/rocketchat-ui-sidenav/side-nav/listPrivateGroupsFlex.coffee @@ -1,6 +1,6 @@ Template.listPrivateGroupsFlex.helpers groups: -> - return ChatSubscription.find { t: { $in: ['p']}, f: { $ne: true } }, { sort: 't': 1, 'name': 1 } + return ChatSubscription.find { t: { $in: ['p']}, f: { $ne: true }, archived: { $ne: true } }, { sort: 't': 1, 'name': 1 } Template.listPrivateGroupsFlex.events 'click header': -> diff --git a/server/publications/subscription.coffee b/server/publications/subscription.coffee index f188e99522e3..3fe0f7d627da 100644 --- a/server/publications/subscription.coffee +++ b/server/publications/subscription.coffee @@ -15,3 +15,4 @@ Meteor.publish 'subscription', -> open: 1 alert: 1 unread: 1 + archived: 1 From 9635fa5d024a74f93c1d141664d1d06f78456fb9 Mon Sep 17 00:00:00 2001 From: Matthias Brun Date: Thu, 10 Dec 2015 11:33:08 +0100 Subject: [PATCH 007/103] Change the way archived rooms are displayed in the history --- i18n/en.i18n.json | 1 + .../views/app/privateHistory.coffee | 9 +++++++- .../views/app/privateHistory.html | 23 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index d74bd48653c9..1f024523cf40 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -405,6 +405,7 @@ "Settings_updated" : "Settings updated", "Should_exists_a_user_with_this_username" : "Should exists a user with this username.", "Showing_online_users" : "Showing __total_online__ of __total__ users", + "Showing_archived_results" : "

Showing %s archived results

", "Showing_results" : "

Showing %s results

", "Silence" : "Silence", "since_creation" : "since %s", diff --git a/packages/rocketchat-ui/views/app/privateHistory.coffee b/packages/rocketchat-ui/views/app/privateHistory.coffee index b04ecd4f8037..97a45d9aca7b 100644 --- a/packages/rocketchat-ui/views/app/privateHistory.coffee +++ b/packages/rocketchat-ui/views/app/privateHistory.coffee @@ -1,6 +1,13 @@ Template.privateHistory.helpers history: -> - items = ChatSubscription.find { name: { $regex: Session.get('historyFilter'), $options: 'i' }, t: { $in: ['d', 'c', 'p'] } }, {'sort': { 'ts': -1 } } + items = ChatSubscription.find { name: { $regex: Session.get('historyFilter'), $options: 'i' }, t: { $in: ['d', 'c', 'p'] }, archived: { $ne: true } }, {'sort': { 'ts': -1 } } + return { + items: items + length: items.count() + } + + archivedHistory: -> + items = ChatSubscription.find { name: { $regex: Session.get('historyFilter'), $options: 'i' }, t: { $in: ['d', 'c', 'p'] }, archived: true }, {'sort': { 'ts': -1 } } return { items: items length: items.count() diff --git a/packages/rocketchat-ui/views/app/privateHistory.html b/packages/rocketchat-ui/views/app/privateHistory.html index 7b51de5161cd..fd8d6caa3a46 100644 --- a/packages/rocketchat-ui/views/app/privateHistory.html +++ b/packages/rocketchat-ui/views/app/privateHistory.html @@ -35,6 +35,29 @@

{{name}}

{{/each}} +
+ {{{_ "Showing_archived_results" archivedHistory.length}}} +
+ From 982569dc2bf2fbfa3aeb8cedad3bfef29d016a97 Mon Sep 17 00:00:00 2001 From: Matthias Brun Date: Fri, 11 Dec 2015 17:27:27 +0100 Subject: [PATCH 008/103] Show specific error message when trying to create a channel named like an archived one --- i18n/en.i18n.json | 1 + .../rocketchat-ui-sidenav/side-nav/createChannelFlex.coffee | 3 +++ .../rocketchat-ui-sidenav/side-nav/createChannelFlex.html | 6 ++++++ server/methods/createChannel.coffee | 5 ++++- 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index 1f024523cf40..a1c92e560445 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -134,6 +134,7 @@ "Disable_New_Message_Notification" : "Disable New Message Notification", "Disable_New_Room_Notification" : "Disable New Room Notification", "Drop_to_upload_file" : "Drop to upload file", + "Duplicate_archived_channel_name" : "An archived Channel with name '%s' exists", "Duplicate_channel_name" : "A Channel with name '%s' exists", "Duplicate_private_group_name" : "A Private Group with name '%s' exists", "E-mail" : "E-mail", diff --git a/packages/rocketchat-ui-sidenav/side-nav/createChannelFlex.coffee b/packages/rocketchat-ui-sidenav/side-nav/createChannelFlex.coffee index 7d5448acdb92..a6abfa19958e 100644 --- a/packages/rocketchat-ui-sidenav/side-nav/createChannelFlex.coffee +++ b/packages/rocketchat-ui-sidenav/side-nav/createChannelFlex.coffee @@ -90,6 +90,9 @@ Template.createChannelFlex.events if err.error is 'duplicate-name' instance.error.set({ duplicate: true }) return + if err.error is 'archived-duplicate-name' + instance.error.set({ archivedduplicate: true }) + return else return toastr.error err.reason diff --git a/packages/rocketchat-ui-sidenav/side-nav/createChannelFlex.html b/packages/rocketchat-ui-sidenav/side-nav/createChannelFlex.html index 2f5e30431261..32f223608d24 100644 --- a/packages/rocketchat-ui-sidenav/side-nav/createChannelFlex.html +++ b/packages/rocketchat-ui-sidenav/side-nav/createChannelFlex.html @@ -40,6 +40,12 @@

{{_ "Create_new_public_channel" }}

{{{_ "Duplicate_channel_name" roomName}}} {{/if}} + {{#if error.archivedduplicate}} +
+ {{_ "Oops!"}} + {{{_ "Duplicate_archived_channel_name" roomName}}} +
+ {{/if}}
diff --git a/server/methods/createChannel.coffee b/server/methods/createChannel.coffee index 3c8319079d37..0fd82cb0c030 100644 --- a/server/methods/createChannel.coffee +++ b/server/methods/createChannel.coffee @@ -23,7 +23,10 @@ Meteor.methods # avoid duplicate names if RocketChat.models.Rooms.findOneByName name - throw new Meteor.Error 'duplicate-name' + if RocketChat.models.Rooms.findOneByName(name).archived + throw new Meteor.Error 'archived-duplicate-name' + else + throw new Meteor.Error 'duplicate-name' # name = s.slugify name From 801864c20335d45943f6d0c3dcc319fc3de99c12 Mon Sep 17 00:00:00 2001 From: Matthias Brun Date: Fri, 11 Dec 2015 17:39:10 +0100 Subject: [PATCH 009/103] Show specific error message when trying to create a private group named like an archived one --- i18n/en.i18n.json | 1 + .../rocketchat-ui-sidenav/side-nav/privateGroupsFlex.coffee | 3 +++ .../rocketchat-ui-sidenav/side-nav/privateGroupsFlex.html | 6 ++++++ server/methods/createPrivateGroup.coffee | 5 ++++- 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index a1c92e560445..aa8f22f21ab9 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -136,6 +136,7 @@ "Drop_to_upload_file" : "Drop to upload file", "Duplicate_archived_channel_name" : "An archived Channel with name '%s' exists", "Duplicate_channel_name" : "A 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", "E-mail" : "E-mail", "edited" : "edited", diff --git a/packages/rocketchat-ui-sidenav/side-nav/privateGroupsFlex.coffee b/packages/rocketchat-ui-sidenav/side-nav/privateGroupsFlex.coffee index 2b8db2c1bd67..260dec67a5ca 100644 --- a/packages/rocketchat-ui-sidenav/side-nav/privateGroupsFlex.coffee +++ b/packages/rocketchat-ui-sidenav/side-nav/privateGroupsFlex.coffee @@ -85,6 +85,9 @@ Template.privateGroupsFlex.events if err.error is 'duplicate-name' instance.error.set({ duplicate: true }) return + if err.error is 'archived-duplicate-name' + instance.error.set({ archivedduplicate: true }) + return return toastr.error err.reason SideNav.closeFlex() instance.clearForm() diff --git a/packages/rocketchat-ui-sidenav/side-nav/privateGroupsFlex.html b/packages/rocketchat-ui-sidenav/side-nav/privateGroupsFlex.html index 24e9050283e2..821a4361efa4 100644 --- a/packages/rocketchat-ui-sidenav/side-nav/privateGroupsFlex.html +++ b/packages/rocketchat-ui-sidenav/side-nav/privateGroupsFlex.html @@ -40,6 +40,12 @@

{{_ "Create_new_private_group"}}

{{{_ "Duplicate_private_group_name" groupName}}}
{{/if}} + {{#if error.archivedduplicate}} +
+ {{_ "Oops!"}} + {{{_ "Duplicate_archived_private_group_name" groupName}}} +
+ {{/if}}
diff --git a/server/methods/createPrivateGroup.coffee b/server/methods/createPrivateGroup.coffee index 22080081372e..11f068c08bdd 100644 --- a/server/methods/createPrivateGroup.coffee +++ b/server/methods/createPrivateGroup.coffee @@ -26,7 +26,10 @@ Meteor.methods # avoid duplicate names if RocketChat.models.Rooms.findOneByName name - throw new Meteor.Error 'duplicate-name' + if RocketChat.models.Rooms.findOneByName(name).archived + throw new Meteor.Error 'archived-duplicate-name' + else + throw new Meteor.Error 'duplicate-name' # create new room room = RocketChat.models.Rooms.createWithTypeNameUserAndUsernames 'p', name, me, members, From f838e9efb88902148d9cf0400d18802de24abc4c Mon Sep 17 00:00:00 2001 From: Matthias Brun Date: Fri, 11 Dec 2015 17:58:50 +0100 Subject: [PATCH 010/103] Add localization for archived/unarchived messages --- i18n/en.i18n.json | 2 ++ .../client/views/channelSettings.coffee | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index aa8f22f21ab9..d194a0784fc7 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -366,6 +366,8 @@ "Restart" : "Restart", "Restart_the_server" : "Restart the server", "Room" : "Room", + "Room_archived" : "Room archived", + "Room_unarchived" : "Room unarchived", "Room_name_changed" : "Room name changed to: __room_name__ by __user_by__", "Room_name_changed_successfully" : "Room name changed successfully", "Room_not_found" : "Room not found", diff --git a/packages/rocketchat-channel-settings/client/views/channelSettings.coffee b/packages/rocketchat-channel-settings/client/views/channelSettings.coffee index 18a254406ca7..a325ef9f55e8 100644 --- a/packages/rocketchat-channel-settings/client/views/channelSettings.coffee +++ b/packages/rocketchat-channel-settings/client/views/channelSettings.coffee @@ -22,14 +22,14 @@ Template.channelSettings.events Meteor.call 'archiveRoom', t.data.rid, true, (err, results) -> return toastr.error err.reason if err - toastr.success 'Channel archived' + toastr.success TAPi18n.__ 'Room_archived' 'click .unarchive': (e, t) -> e.preventDefault() Meteor.call 'unarchiveRoom', t.data.rid, true, (err, results) -> return toastr.error err.reason if err - toastr.success 'Channel unarchived' + toastr.success TAPi18n.__ 'Room_unarchived' # switch room.t # when 'c' From 866a000e11e2febcf6851a2e2196cf2b90cf974b Mon Sep 17 00:00:00 2001 From: Marcelo Schmidt Date: Tue, 15 Dec 2015 13:14:26 -0200 Subject: [PATCH 011/103] Save individual room settings --- .../client/stylesheets/channel-settings.less | 4 + .../client/views/channelSettings.coffee | 89 ++++++++++++++----- .../client/views/channelSettings.html | 14 +-- .../i18n/en.i18n.json | 6 +- .../server/methods/saveRoomSettings.coffee | 39 ++++---- .../rocketchat-lib/client/lib/roomExit.coffee | 9 +- 6 files changed, 109 insertions(+), 52 deletions(-) diff --git a/packages/rocketchat-channel-settings/client/stylesheets/channel-settings.less b/packages/rocketchat-channel-settings/client/stylesheets/channel-settings.less index 05f745e0abc5..a09d3ee179c2 100644 --- a/packages/rocketchat-channel-settings/client/stylesheets/channel-settings.less +++ b/packages/rocketchat-channel-settings/client/stylesheets/channel-settings.less @@ -13,6 +13,10 @@ margin-top: 30px; text-align: center; } + + [data-edit] { + cursor: pointer; + } } } diff --git a/packages/rocketchat-channel-settings/client/views/channelSettings.coffee b/packages/rocketchat-channel-settings/client/views/channelSettings.coffee index a56bc8f54cb6..7f5639384fe1 100644 --- a/packages/rocketchat-channel-settings/client/views/channelSettings.coffee +++ b/packages/rocketchat-channel-settings/client/views/channelSettings.coffee @@ -1,40 +1,64 @@ Template.channelSettings.helpers canEdit: -> - return true + return RocketChat.authz.hasAllPermission('edit-room', @rid) editing: (field) -> - return false + return Template.instance().editing.get() is field notDirect: -> return ChatRoom.findOne(@rid)?.t isnt 'd' roomType: -> return ChatRoom.findOne(@rid)?.t roomTypeDescription: -> - return if ChatRoom.findOne(@rid)?.t is 'c' then t('Channel') else t('Private_Group') + roomType = ChatRoom.findOne(@rid)?.t + if roomType is 'c' + return t('Channel') + else if roomType is 'p' + return t('Private_Group') roomName: -> return ChatRoom.findOne(@rid)?.name roomTopic: -> return ChatRoom.findOne(@rid)?.topic Template.channelSettings.events - 'click .save': (e, t) -> - e.preventDefault() + # 'click .save': (e, t) -> + # e.preventDefault() + + # settings = + # roomType: t.$('input[name=roomType]:checked').val() + # roomName: t.$('input[name=roomName]').val() + # roomTopic: t.$('input[name=roomTopic]').val() + + # if t.validate() + # Meteor.call 'saveRoomSettings', t.data.rid, settings, (err, results) -> + # if err + # if err.error in [ 'duplicate-name', 'name-invalid' ] + # return toastr.error TAPi18n.__(err.reason, err.details.channelName) + # if err.error is 'invalid-room-type' + # return toastr.error TAPi18n.__(err.reason, err.details.roomType) + # return toastr.error TAPi18n.__(err.reason) + + # toastr.success TAPi18n.__ 'Settings_updated' - settings = - roomType: t.$('input[name=roomType]:checked').val() - roomName: t.$('input[name=roomName]').val() - roomTopic: t.$('input[name=roomTopic]').val() + 'keydown input[type=text]': (e, t) -> + if e.keyCode is 13 + e.preventDefault() + t.saveSetting() - if t.validate() - Meteor.call 'saveRoomSettings', t.data.rid, settings, (err, results) -> - if err - if err.error in [ 'duplicate-name', 'name-invalid' ] - return toastr.error TAPi18n.__(err.reason, err.details.channelName) - if err.error is 'invalid-room-type' - return toastr.error TAPi18n.__(err.reason, err.details.roomType) - return toastr.error TAPi18n.__(err.reason) + 'click [data-edit]': (e, t) -> + e.preventDefault() + t.editing.set($(e.currentTarget).data('edit')) + setTimeout (-> t.$('input.editing').focus().select()), 100 + + 'click .cancel': (e, t) -> + e.preventDefault() + t.editing.set() - toastr.success TAPi18n.__ 'Settings_updated' + 'click .save': (e, t) -> + e.preventDefault() + t.saveSetting() Template.channelSettings.onCreated -> + @editing = new ReactiveVar + @validateRoomType = => type = @$('input[name=roomType]:checked').val() if type not in ['c', 'p'] @@ -45,7 +69,7 @@ Template.channelSettings.onCreated -> rid = Template.currentData()?.rid room = ChatRoom.findOne rid - if room.u._id isnt Meteor.userId() or room.t not in ['c', 'p'] + if not RocketChat.authz.hasAllPermission('edit-room', @rid) or room.t not in ['c', 'p'] toastr.error t('Not_allowed') return false @@ -59,5 +83,28 @@ Template.channelSettings.onCreated -> @validateRoomTopic = => return true - @validate = => - return @validateRoomType() and @validateRoomName() and @validateRoomTopic() + @saveSetting = => + switch @editing.get() + when 'roomName' + if @validateRoomName() + Meteor.call 'saveRoomSettings', @data?.rid, 'roomName', @$('input[name=roomName]').val(), (err, result) -> + if err + if err.error in [ 'duplicate-name', 'name-invalid' ] + return toastr.error TAPi18n.__(err.reason, err.details.channelName) + return toastr.error TAPi18n.__(err.reason) + toastr.success TAPi18n.__ 'Room_name_changed_successfully' + when 'roomTopic' + if @validateRoomTopic() + Meteor.call 'saveRoomSettings', @data?.rid, 'roomTopic', @$('input[name=roomTopic]').val(), (err, result) -> + if err + return toastr.error TAPi18n.__(err.reason) + toastr.success TAPi18n.__ 'Room_topic_changed_successfully' + when 'roomType' + if @validateRoomType() + Meteor.call 'saveRoomSettings', @data?.rid, 'roomType', @$('input[name=roomType]:checked').val(), (err, result) -> + if err + if err.error is 'invalid-room-type' + return toastr.error TAPi18n.__(err.reason, err.details.roomType) + return toastr.error TAPi18n.__(err.reason) + toastr.success TAPi18n.__ 'Room_type_changed_successfully' + @editing.set() diff --git a/packages/rocketchat-channel-settings/client/views/channelSettings.html b/packages/rocketchat-channel-settings/client/views/channelSettings.html index 36a5cc72b4b2..042abb276142 100644 --- a/packages/rocketchat-channel-settings/client/views/channelSettings.html +++ b/packages/rocketchat-channel-settings/client/views/channelSettings.html @@ -12,9 +12,9 @@

{{_ "Room_Settings"}}

{{#if editing 'roomName'}} - + {{else}} - {{roomName}}{{#if canEdit}} {{/if}} + {{roomName}}{{#if canEdit}} {{/if}} {{/if}}
@@ -23,9 +23,9 @@

{{_ "Room_Settings"}}

{{#if editing 'roomTopic'}} - + {{else}} - {{roomTopic}}{{#if canEdit}} {{/if}} + {{roomTopic}}{{#if canEdit}} {{/if}} {{/if}}
@@ -34,10 +34,12 @@

{{_ "Room_Settings"}}

{{#if editing 'roomType'}} - + + + {{else}} - {{roomTypeDescription}}{{#if canEdit}} {{/if}} + {{roomTypeDescription}}{{#if canEdit}} {{/if}} {{/if}}
diff --git a/packages/rocketchat-channel-settings/i18n/en.i18n.json b/packages/rocketchat-channel-settings/i18n/en.i18n.json index 1191953e3ba8..f9b02ab82b58 100644 --- a/packages/rocketchat-channel-settings/i18n/en.i18n.json +++ b/packages/rocketchat-channel-settings/i18n/en.i18n.json @@ -1,10 +1,14 @@ { + "Cancel": "Cancel", "Channel": "Channel", "Private_Group": "Private Group", "Name": "Name", + "Save": "Save", "Topic": "Topic", "Type": "Type", "Room_Settings": "Room Settings", "room_changed_privacy": "Room type changed to: __room_type__ by __user_by__", - "room_changed_topic": "Room topic changed to: __room_topic__ by __user_by__" + "room_changed_topic": "Room topic changed to: __room_topic__ by __user_by__", + "Room_topic_changed_successfully": "Room topic changed successfully", + "Room_type_changed_successfully": "Room type changed successfully" } diff --git a/packages/rocketchat-channel-settings/server/methods/saveRoomSettings.coffee b/packages/rocketchat-channel-settings/server/methods/saveRoomSettings.coffee index 9cc15ad6fb40..348d43afc661 100644 --- a/packages/rocketchat-channel-settings/server/methods/saveRoomSettings.coffee +++ b/packages/rocketchat-channel-settings/server/methods/saveRoomSettings.coffee @@ -1,11 +1,11 @@ Meteor.methods - saveRoomSettings: (rid, settings) -> - console.log '[method] saveRoomSettings'.green, rid, settings + saveRoomSettings: (rid, setting, value) -> + console.log '[method] saveRoomSettings'.green, rid, setting, value unless Match.test rid, String throw new Meteor.Error 'invalid-rid', 'Invalid room' - unless Match.test settings, Match.ObjectIncluding { roomName: String, roomTopic: String, roomType: String } + if setting not in ['roomName', 'roomTopic', 'roomType'] throw new Meteor.Error 'invalid-settings', 'Invalid settings provided' unless RocketChat.authz.hasPermission(Meteor.userId(), 'edit-room', rid) @@ -13,22 +13,21 @@ Meteor.methods room = RocketChat.models.Rooms.findOneById rid if room? - if settings.roomName isnt room.name - name = RocketChat.saveRoomName rid, settings.roomName - RocketChat.models.Messages.createRoomRenamedWithRoomIdRoomNameAndUser rid, name, Meteor.user() - - if settings.roomType isnt room.t - RocketChat.saveRoomType(rid, settings.roomType) - - if settings.roomType is 'c' - message = TAPi18n.__('Channel') - else - message = TAPi18n.__('Private_Group') - - RocketChat.models.Messages.createRoomSettingsChangedWithTypeRoomIdMessageAndUser 'room_changed_privacy', rid, message, Meteor.user() - - if settings.roomTopic isnt room.topic - RocketChat.saveRoomTopic(rid, settings.roomTopic) - RocketChat.models.Messages.createRoomSettingsChangedWithTypeRoomIdMessageAndUser 'room_changed_topic', rid, settings.roomTopic, Meteor.user() + switch setting + when 'roomName' + name = RocketChat.saveRoomName rid, value + RocketChat.models.Messages.createRoomRenamedWithRoomIdRoomNameAndUser rid, name, Meteor.user() + when 'roomTopic' + if value isnt room.topic + RocketChat.saveRoomTopic(rid, value) + RocketChat.models.Messages.createRoomSettingsChangedWithTypeRoomIdMessageAndUser 'room_changed_topic', rid, value, Meteor.user() + when 'roomType' + if value isnt room.t + RocketChat.saveRoomType(rid, value) + if value is 'c' + message = TAPi18n.__('Channel') + else + message = TAPi18n.__('Private_Group') + RocketChat.models.Messages.createRoomSettingsChangedWithTypeRoomIdMessageAndUser 'room_changed_privacy', rid, message, Meteor.user() return true diff --git a/packages/rocketchat-lib/client/lib/roomExit.coffee b/packages/rocketchat-lib/client/lib/roomExit.coffee index d8a44ae00a37..7ee736f5e2ea 100644 --- a/packages/rocketchat-lib/client/lib/roomExit.coffee +++ b/packages/rocketchat-lib/client/lib/roomExit.coffee @@ -10,8 +10,9 @@ if child? if child.classList.contains('room-container') wrapper = child.querySelector('.messages-box > .wrapper') - if wrapper.scrollTop >= wrapper.scrollHeight - wrapper.clientHeight - child.oldScrollTop = 10e10 - else - child.oldScrollTop = wrapper.scrollTop + if wrapper + if wrapper.scrollTop >= wrapper.scrollHeight - wrapper.clientHeight + child.oldScrollTop = 10e10 + else + child.oldScrollTop = wrapper.scrollTop mainNode.removeChild child From ddd3ed53830ff1f2627072f36407c39283b37a92 Mon Sep 17 00:00:00 2001 From: Marcelo Schmidt Date: Tue, 15 Dec 2015 13:32:19 -0200 Subject: [PATCH 012/103] Fix errors --- packages/rocketchat-lib/server/models/Messages.coffee | 3 --- packages/rocketchat-ui/views/app/room.coffee | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/rocketchat-lib/server/models/Messages.coffee b/packages/rocketchat-lib/server/models/Messages.coffee index b7449cddf475..f39ffe2b9a5f 100644 --- a/packages/rocketchat-lib/server/models/Messages.coffee +++ b/packages/rocketchat-lib/server/models/Messages.coffee @@ -266,9 +266,6 @@ RocketChat.models.Messages = new class extends RocketChat.models._Base message = user.username return @createWithTypeRoomIdMessageAndUser 'au', roomId, message, user, extraData - createRoomRenamedWithRoomIdRoomNameAndUser: (roomId, roomName, user, extraData) -> - return @createWithTypeRoomIdMessageAndUser 'r', roomId, roomName, user, extraData - createCommandWithRoomIdAndUser: (command, roomId, user, extraData) -> return @createWithTypeRoomIdMessageAndUser 'command', roomId, command, user, extraData diff --git a/packages/rocketchat-ui/views/app/room.coffee b/packages/rocketchat-ui/views/app/room.coffee index f5fc19fde96d..fa93c7f9c7d2 100644 --- a/packages/rocketchat-ui/views/app/room.coffee +++ b/packages/rocketchat-ui/views/app/room.coffee @@ -177,7 +177,7 @@ Template.room.helpers formatUnreadSince: -> room = ChatRoom.findOne(this._id, { reactive: false }) - room = RoomManager.openedRooms[room.t + room.name] + room = RoomManager.openedRooms[room?.t + room?.name] date = room?.unreadSince.get() if not date? then return From 61aced6acb713761f38fb217e108222c537bef58 Mon Sep 17 00:00:00 2001 From: Marcelo Schmidt Date: Tue, 15 Dec 2015 13:44:56 -0200 Subject: [PATCH 013/103] Fix error on parsing message --- packages/rocketchat-ui/lib/RoomManager.coffee | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/rocketchat-ui/lib/RoomManager.coffee b/packages/rocketchat-ui/lib/RoomManager.coffee index 0a70060a78eb..640b54f66ca7 100644 --- a/packages/rocketchat-ui/lib/RoomManager.coffee +++ b/packages/rocketchat-ui/lib/RoomManager.coffee @@ -111,11 +111,11 @@ RocketChat.Notifications.onUser 'message', (msg) -> msgStream.on openedRooms[typeName].rid, (msg) -> if msg.t isnt 'command' ChatMessage.upsert { _id: msg._id }, msg - else - Meteor.defer -> - RoomManager.updateMentionsMarksOfRoom typeName - RocketChat.callbacks.run 'streamMessage', msg + Meteor.defer -> + RoomManager.updateMentionsMarksOfRoom typeName + + RocketChat.callbacks.run 'streamMessage', msg RocketChat.Notifications.onRoom openedRooms[typeName].rid, 'deleteMessage', onDeleteMessageStream From 45a85e5fe7fe10a3a29b838e956a940fdb66e7d9 Mon Sep 17 00:00:00 2001 From: Marcelo Schmidt Date: Tue, 15 Dec 2015 14:58:18 -0200 Subject: [PATCH 014/103] Room Info --- .../client/startup/tabBar.coffee | 14 +++++++------- .../client/views/channelSettings.html | 2 +- .../rocketchat-channel-settings/i18n/en.i18n.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/rocketchat-channel-settings/client/startup/tabBar.coffee b/packages/rocketchat-channel-settings/client/startup/tabBar.coffee index 487be2c65a72..a78fd0ec324b 100644 --- a/packages/rocketchat-channel-settings/client/startup/tabBar.coffee +++ b/packages/rocketchat-channel-settings/client/startup/tabBar.coffee @@ -2,11 +2,11 @@ Meteor.startup -> RocketChat.callbacks.add 'enter-room', (subscription) -> - if RocketChat.authz.hasAtLeastOnePermission('edit-room', subscription?.rid) - RocketChat.TabBar.addButton - id: 'channel-settings' - i18nTitle: 'Channel_Settings' - icon: 'octicon octicon-info' - template: 'channelSettings' - order: 0 + RocketChat.TabBar.addButton + id: 'channel-settings' + i18nTitle: 'Room_Info' + icon: 'octicon octicon-info' + template: 'channelSettings' + order: 0 + , RocketChat.callbacks.priority.MEDIUM, 'enter-room-tabbar-channel-settings' diff --git a/packages/rocketchat-channel-settings/client/views/channelSettings.html b/packages/rocketchat-channel-settings/client/views/channelSettings.html index 042abb276142..bba2381095c2 100644 --- a/packages/rocketchat-channel-settings/client/views/channelSettings.html +++ b/packages/rocketchat-channel-settings/client/views/channelSettings.html @@ -1,7 +1,7 @@ From b98c77c1cc5374d7915a15ef207a859725dd99c7 Mon Sep 17 00:00:00 2001 From: Marcelo Schmidt Date: Tue, 22 Dec 2015 18:53:13 -0200 Subject: [PATCH 052/103] Fix for links stopped working --- packages/rocketchat-ui/views/app/room.coffee | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/rocketchat-ui/views/app/room.coffee b/packages/rocketchat-ui/views/app/room.coffee index 2d0e4ba0b082..2127c7662af4 100644 --- a/packages/rocketchat-ui/views/app/room.coffee +++ b/packages/rocketchat-ui/views/app/room.coffee @@ -411,8 +411,6 @@ Template.room.events RoomHistoryManager.clear(template?.data?._id) 'click .message': (e, template) -> - e.preventDefault() - e.stopPropagation() if template.selectable.get() document.selection?.empty() or window.getSelection?().removeAllRanges() data = Blaze.getData(e.currentTarget) From cf296057928fbc025275ded1456bc1f0aaa19704 Mon Sep 17 00:00:00 2001 From: Gabriel Engel Date: Tue, 22 Dec 2015 18:53:47 -0200 Subject: [PATCH 053/103] move file to example --- build.sh => example-build.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename build.sh => example-build.sh (100%) diff --git a/build.sh b/example-build.sh similarity index 100% rename from build.sh rename to example-build.sh From 35ea9998590d2c770221ce61259b1e3903cb3939 Mon Sep 17 00:00:00 2001 From: Gabriel Engel Date: Tue, 22 Dec 2015 18:55:32 -0200 Subject: [PATCH 054/103] ignoring the customised build.sh --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 2ae4ddd56cc0..fdec437e0c51 100644 --- a/.gitignore +++ b/.gitignore @@ -66,3 +66,4 @@ tramp ecosystem.json pm2.json settings.json +build.sh From ad83f9778619e6548a8511d18174c22934f8b006 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Tue, 22 Dec 2015 19:29:21 -0200 Subject: [PATCH 055/103] Finish the outgoing hook cadastre --- .../client/views/integrations.html | 50 +++++++---- .../client/views/integrationsIncoming.coffee | 6 +- .../client/views/integrationsOutgoing.coffee | 34 ++++--- .../client/views/integrationsOutgoing.html | 12 ++- packages/rocketchat-integrations/package.js | 8 +- .../addIncomingIntegration.coffee} | 16 ++-- .../deleteIncomingIntegration.coffee} | 4 +- .../updateIncomingIntegration.coffee} | 12 +-- .../outgoing/addOutgoingIntegration.coffee | 88 ++++++++----------- .../outgoing/deleteOutgoingIntegration.coffee | 13 +++ .../outgoing/updateOutgoingIntegration.coffee | 84 ++++++++++++++++++ 11 files changed, 228 insertions(+), 99 deletions(-) rename packages/rocketchat-integrations/server/methods/{addIntegration.coffee => incoming/addIncomingIntegration.coffee} (69%) rename packages/rocketchat-integrations/server/methods/{deleteIntegration.coffee => incoming/deleteIncomingIntegration.coffee} (75%) rename packages/rocketchat-integrations/server/methods/{updateIntegration.coffee => incoming/updateIncomingIntegration.coffee} (67%) create mode 100644 packages/rocketchat-integrations/server/methods/outgoing/deleteOutgoingIntegration.coffee create mode 100644 packages/rocketchat-integrations/server/methods/outgoing/updateOutgoingIntegration.coffee diff --git a/packages/rocketchat-integrations/client/views/integrations.html b/packages/rocketchat-integrations/client/views/integrations.html index d1075af7756b..580b06e6ab17 100644 --- a/packages/rocketchat-integrations/client/views/integrations.html +++ b/packages/rocketchat-integrations/client/views/integrations.html @@ -7,26 +7,46 @@
diff --git a/packages/rocketchat-integrations/client/views/integrationsIncoming.coffee b/packages/rocketchat-integrations/client/views/integrationsIncoming.coffee index f61b55199dc0..b3aabfa5bc03 100644 --- a/packages/rocketchat-integrations/client/views/integrationsIncoming.coffee +++ b/packages/rocketchat-integrations/client/views/integrationsIncoming.coffee @@ -108,7 +108,7 @@ Template.integrationsIncoming.events closeOnConfirm: false html: false , -> - Meteor.call "deleteIntegration", params.id, (err, data) -> + Meteor.call "deleteIncomingIntegration", params.id, (err, data) -> swal title: t('Deleted') text: t('Your_entry_has_been_deleted') @@ -141,7 +141,7 @@ Template.integrationsIncoming.events params = Template.instance().data.params?() if params?.id? - Meteor.call "updateIntegration", params.id, integration, (err, data) -> + Meteor.call "updateIncomingIntegration", params.id, integration, (err, data) -> if err? return toastr.error TAPi18n.__(err.error) @@ -150,7 +150,7 @@ Template.integrationsIncoming.events integration.type = 'webhook-incoming' integration.username = username - Meteor.call "addIntegration", integration, (err, data) -> + Meteor.call "addIncomingIntegration", integration, (err, data) -> if err? return toastr.error TAPi18n.__(err.error) diff --git a/packages/rocketchat-integrations/client/views/integrationsOutgoing.coffee b/packages/rocketchat-integrations/client/views/integrationsOutgoing.coffee index 63ac2cfc0814..5430d9c97d9d 100644 --- a/packages/rocketchat-integrations/client/views/integrationsOutgoing.coffee +++ b/packages/rocketchat-integrations/client/views/integrationsOutgoing.coffee @@ -1,10 +1,7 @@ Template.integrationsOutgoing.onCreated -> @record = new ReactiveVar - name: 'name' - alias: 'alias' - channel: '#general' - triggerWords: ['send', 'sent'] - urls: ['https://www.google.com', 'https://www.google.com'] + username: 'rocket.cat' + token: Random.id(24) Template.integrationsOutgoing.helpers @@ -82,6 +79,7 @@ Template.integrationsOutgoing.events emoji: $('[name=emoji]').val().trim() avatar: $('[name=avatar]').val().trim() channel: $('[name=channel]').val().trim() + username: $('[name=username]').val().trim() triggerWords: $('[name=triggerWords]').val().trim() urls: $('[name=urls]').val().trim() token: $('[name=token]').val().trim() @@ -101,7 +99,7 @@ Template.integrationsOutgoing.events closeOnConfirm: false html: false , -> - Meteor.call "deleteIntegration", params.id, (err, data) -> + Meteor.call "deleteOutgoingIntegration", params.id, (err, data) -> swal title: t('Deleted') text: t('Your_entry_has_been_deleted') @@ -117,23 +115,37 @@ Template.integrationsOutgoing.events emoji = $('[name=emoji]').val().trim() avatar = $('[name=avatar]').val().trim() channel = $('[name=channel]').val().trim() + username = $('[name=username]').val().trim() triggerWords = $('[name=triggerWords]').val().trim() urls = $('[name=urls]').val().trim() token = $('[name=token]').val().trim() - if triggerWords is '' + if username is '' + return toastr.error TAPi18n.__("The_username_is_required") + + triggerWords = triggerWords.split(',') + for triggerWord, index in triggerWords + triggerWords[index] = triggerWord.trim() + delete triggerWords[index] if triggerWord.trim() is '' + + triggerWords = _.without triggerWords, [undefined] + + if triggerWords.length is 0 and channel.trim() is '' return toastr.error TAPi18n.__("You should inform at least one trigger word if you do not inform a channel") - urlsArr = urls.split('\n') - urls = [] - for url in urlsArr - urls.push url.trim() if url.trim() isnt '' + urls = urls.split('\n') + for url, index in urls + urls[index] = url.trim() + delete urls[index] if url.trim() is '' + + urls = _.without urls, [undefined] if urls.length is 0 return toastr.error TAPi18n.__("You_should_inform_one_url_at_least") integration = channel: channel + username: username alias: alias if alias isnt '' emoji: emoji if emoji isnt '' avatar: avatar if avatar isnt '' diff --git a/packages/rocketchat-integrations/client/views/integrationsOutgoing.html b/packages/rocketchat-integrations/client/views/integrationsOutgoing.html index 1b83d457bf4b..1b009cd93c09 100644 --- a/packages/rocketchat-integrations/client/views/integrationsOutgoing.html +++ b/packages/rocketchat-integrations/client/views/integrationsOutgoing.html @@ -24,7 +24,7 @@
- +
{{_ "When a line starts with one of these words, post to the URL(s) below"}}
{{_ "Optional if a channel is chosen"}}
{{_ "Separate multiple words with commas"}}
@@ -37,6 +37,14 @@
{{_ "Enter as many URLs as you like, one per line, please"}}
+
+ +
+ +
{{_ "Choose_the_username_that_this_integration_will_post_as"}}
+
{{_ "Should_exists_a_user_with_this_username"}}
+
+
@@ -63,7 +71,7 @@
- +
diff --git a/packages/rocketchat-integrations/package.js b/packages/rocketchat-integrations/package.js index e78c4dac4210..ff01a9012937 100644 --- a/packages/rocketchat-integrations/package.js +++ b/packages/rocketchat-integrations/package.js @@ -42,10 +42,12 @@ Package.onUse(function(api) { api.addFiles('server/publications/integrations.coffee', 'server'); // methods - api.addFiles('server/methods/addIntegration.coffee', 'server'); - api.addFiles('server/methods/updateIntegration.coffee', 'server'); - api.addFiles('server/methods/deleteIntegration.coffee', 'server'); + api.addFiles('server/methods/incoming/addIncomingIntegration.coffee', 'server'); + api.addFiles('server/methods/incoming/updateIncomingIntegration.coffee', 'server'); + api.addFiles('server/methods/incoming/deleteIncomingIntegration.coffee', 'server'); api.addFiles('server/methods/outgoing/addOutgoingIntegration.coffee', 'server'); + api.addFiles('server/methods/outgoing/updateOutgoingIntegration.coffee', 'server'); + api.addFiles('server/methods/outgoing/deleteOutgoingIntegration.coffee', 'server'); // api api.addFiles('server/api/api.coffee', 'server'); diff --git a/packages/rocketchat-integrations/server/methods/addIntegration.coffee b/packages/rocketchat-integrations/server/methods/incoming/addIncomingIntegration.coffee similarity index 69% rename from packages/rocketchat-integrations/server/methods/addIntegration.coffee rename to packages/rocketchat-integrations/server/methods/incoming/addIncomingIntegration.coffee index 454b87d6bd23..316127e53acd 100644 --- a/packages/rocketchat-integrations/server/methods/addIntegration.coffee +++ b/packages/rocketchat-integrations/server/methods/incoming/addIncomingIntegration.coffee @@ -1,22 +1,22 @@ Meteor.methods - addIntegration: (integration) -> + addIncomingIntegration: (integration) -> if not RocketChat.authz.hasPermission @userId, 'manage-integrations' throw new Meteor.Error 'not_authorized' if not _.isString(integration.channel) - throw new Meteor.Error 'invalid_channel', '[methods] addIntegration -> channel must be string' + throw new Meteor.Error 'invalid_channel', '[methods] addIncomingIntegration -> channel must be string' if integration.channel.trim() is '' - throw new Meteor.Error 'invalid_channel', '[methods] addIntegration -> channel can\'t be empty' + throw new Meteor.Error 'invalid_channel', '[methods] addIncomingIntegration -> channel can\'t be empty' if integration.channel[0] not in ['@', '#'] - throw new Meteor.Error 'invalid_channel', '[methods] addIntegration -> channel should start with # or @' + throw new Meteor.Error 'invalid_channel', '[methods] addIncomingIntegration -> channel should start with # or @' if not _.isString(integration.username) - throw new Meteor.Error 'invalid_username', '[methods] addIntegration -> username must be string' + throw new Meteor.Error 'invalid_username', '[methods] addIncomingIntegration -> username must be string' if integration.username.trim() is '' - throw new Meteor.Error 'invalid_username', '[methods] addIntegration -> username can\'t be empty' + throw new Meteor.Error 'invalid_username', '[methods] addIncomingIntegration -> username can\'t be empty' record = undefined channelType = integration.channel[0] @@ -37,12 +37,12 @@ Meteor.methods ] if record is undefined - throw new Meteor.Error 'channel_does_not_exists', "[methods] addIntegration -> The channel does not exists" + throw new Meteor.Error 'channel_does_not_exists', "[methods] addIncomingIntegration -> The channel does not exists" user = RocketChat.models.Users.findOne({username: integration.username}) if not user? - throw new Meteor.Error 'user_does_not_exists', "[methods] addIntegration -> The username does not exists" + throw new Meteor.Error 'user_does_not_exists', "[methods] addIncomingIntegration -> The username does not exists" stampedToken = Accounts._generateStampedLoginToken() hashStampedToken = Accounts._hashStampedToken(stampedToken) diff --git a/packages/rocketchat-integrations/server/methods/deleteIntegration.coffee b/packages/rocketchat-integrations/server/methods/incoming/deleteIncomingIntegration.coffee similarity index 75% rename from packages/rocketchat-integrations/server/methods/deleteIntegration.coffee rename to packages/rocketchat-integrations/server/methods/incoming/deleteIncomingIntegration.coffee index d6f22c27701d..692bb014d273 100644 --- a/packages/rocketchat-integrations/server/methods/deleteIntegration.coffee +++ b/packages/rocketchat-integrations/server/methods/incoming/deleteIncomingIntegration.coffee @@ -1,12 +1,12 @@ Meteor.methods - deleteIntegration: (integrationId) -> + deleteIncomingIntegration: (integrationId) -> if not RocketChat.authz.hasPermission @userId, 'manage-integrations' throw new Meteor.Error 'not_authorized' integration = RocketChat.models.Integrations.findOne(integrationId) if not integration? - throw new Meteor.Error 'invalid_integration', '[methods] addIntegration -> integration not found' + throw new Meteor.Error 'invalid_integration', '[methods] deleteIncomingIntegration -> integration not found' updateObj = $pull: diff --git a/packages/rocketchat-integrations/server/methods/updateIntegration.coffee b/packages/rocketchat-integrations/server/methods/incoming/updateIncomingIntegration.coffee similarity index 67% rename from packages/rocketchat-integrations/server/methods/updateIntegration.coffee rename to packages/rocketchat-integrations/server/methods/incoming/updateIncomingIntegration.coffee index e09c565efb09..25787a289875 100644 --- a/packages/rocketchat-integrations/server/methods/updateIntegration.coffee +++ b/packages/rocketchat-integrations/server/methods/incoming/updateIncomingIntegration.coffee @@ -1,19 +1,19 @@ Meteor.methods - updateIntegration: (integrationId, integration) -> + updateIncomingIntegration: (integrationId, integration) -> if not RocketChat.authz.hasPermission @userId, 'manage-integrations' throw new Meteor.Error 'not_authorized' if not _.isString(integration.channel) - throw new Meteor.Error 'invalid_channel', '[methods] addIntegration -> channel must be string' + throw new Meteor.Error 'invalid_channel', '[methods] updateIncomingIntegration -> channel must be string' if integration.channel.trim() is '' - throw new Meteor.Error 'invalid_channel', '[methods] addIntegration -> channel can\'t be empty' + throw new Meteor.Error 'invalid_channel', '[methods] updateIncomingIntegration -> channel can\'t be empty' if integration.channel[0] not in ['@', '#'] - throw new Meteor.Error 'invalid_channel', '[methods] addIntegration -> channel should start with # or @' + throw new Meteor.Error 'invalid_channel', '[methods] updateIncomingIntegration -> channel should start with # or @' if not RocketChat.models.Integrations.findOne(integrationId)? - throw new Meteor.Error 'invalid_integration', '[methods] addIntegration -> integration not found' + throw new Meteor.Error 'invalid_integration', '[methods] updateIncomingIntegration -> integration not found' record = undefined channelType = integration.channel[0] @@ -34,7 +34,7 @@ Meteor.methods ] if record is undefined - throw new Meteor.Error 'channel_does_not_exists', "[methods] addIntegration -> The channel does not exists" + throw new Meteor.Error 'channel_does_not_exists', "[methods] updateIncomingIntegration -> The channel does not exists" RocketChat.models.Integrations.update integrationId, $set: diff --git a/packages/rocketchat-integrations/server/methods/outgoing/addOutgoingIntegration.coffee b/packages/rocketchat-integrations/server/methods/outgoing/addOutgoingIntegration.coffee index e164c310dfc0..be7e0372172e 100644 --- a/packages/rocketchat-integrations/server/methods/outgoing/addOutgoingIntegration.coffee +++ b/packages/rocketchat-integrations/server/methods/outgoing/addOutgoingIntegration.coffee @@ -3,80 +3,70 @@ Meteor.methods if not RocketChat.authz.hasPermission @userId, 'manage-integrations' throw new Meteor.Error 'not_authorized' - if Match.test integration.urls, [String] + if integration.username.trim() is '' + throw new Meteor.Error 'invalid_username', '[methods] addOutgoingIntegration -> username can\'t be empty' + + if not Match.test integration.urls, [String] throw new Meteor.Error 'invalid_urls', '[methods] addOutgoingIntegration -> urls must be an array' - for url, index in urls - delete urls[index] if url.trim() is '' + for url, index in integration.urls + delete integration.urls[index] if url.trim() is '' - urls = _.without urls, [undefined] + integration.urls = _.without integration.urls, [undefined] if integration.urls.length is 0 throw new Meteor.Error 'invalid_urls', '[methods] addOutgoingIntegration -> urls is required' - # if integration.channel.trim() is '' - # throw new Meteor.Error 'invalid_channel', '[methods] addIntegration -> channel can\'t be empty' + if integration.channel?.trim() isnt '' and integration.channel[0] not in ['@', '#'] + throw new Meteor.Error 'invalid_channel', '[methods] addOutgoingIntegration -> channel should start with # or @' - # if integration.channel[0] not in ['@', '#'] - # throw new Meteor.Error 'invalid_channel', '[methods] addIntegration -> channel should start with # or @' + if not integration.token? or integration.token?.trim() is '' + throw new Meteor.Error 'invalid_token', '[methods] addOutgoingIntegration -> token is required' - # if not _.isString(integration.username) - # throw new Meteor.Error 'invalid_username', '[methods] addIntegration -> username must be string' + if integration.triggerWords? + if not Match.test integration.triggerWords, [String] + throw new Meteor.Error 'invalid_triggerWords', '[methods] addOutgoingIntegration -> triggerWords must be an array' - # if integration.username.trim() is '' - # throw new Meteor.Error 'invalid_username', '[methods] addIntegration -> username can\'t be empty' + for triggerWord, index in integration.triggerWords + delete integration.triggerWords[index] if triggerWord.trim() is '' + integration.triggerWords = _.without integration.triggerWords, [undefined] - # urlsArr = urls.split('\n') - # urls = [] - # for url in urlsArr - # urls.push url.trim() if url.trim() isnt '' + if integration.triggerWords.length is 0 and not integration.channel? + throw new Meteor.Error 'invalid_triggerWords', '[methods] addOutgoingIntegration -> triggerWords is required if channel is empty' - # if urls.length is 0 - # return toastr.error TAPi18n.__("You_should_inform_one_url_at_least") - record = undefined - channelType = integration.channel[0] - channel = integration.channel.substr(1) + if integration.channel?.trim() isnt '' + record = undefined + channelType = integration.channel[0] + channel = integration.channel.substr(1) - switch channelType - when '#' - record = RocketChat.models.Rooms.findOne - $or: [ - {_id: channel} - {name: channel} - ] - when '@' - record = RocketChat.models.Users.findOne - $or: [ - {_id: channel} - {username: channel} - ] + switch channelType + when '#' + record = RocketChat.models.Rooms.findOne + $or: [ + {_id: channel} + {name: channel} + ] + when '@' + record = RocketChat.models.Users.findOne + $or: [ + {_id: channel} + {username: channel} + ] - if record is undefined - throw new Meteor.Error 'channel_does_not_exists', "[methods] addIntegration -> The channel does not exists" + if record is undefined + throw new Meteor.Error 'channel_does_not_exists', "[methods] addOutgoingIntegration -> The channel does not exists" user = RocketChat.models.Users.findOne({username: integration.username}) if not user? - throw new Meteor.Error 'user_does_not_exists', "[methods] addIntegration -> The username does not exists" - - stampedToken = Accounts._generateStampedLoginToken() - hashStampedToken = Accounts._hashStampedToken(stampedToken) + throw new Meteor.Error 'user_does_not_exists', "[methods] addOutgoingIntegration -> The username does not exists" - updateObj = - $push: - 'services.resume.loginTokens': - hashedToken: hashStampedToken.hashedToken - integration: true - - integration.token = hashStampedToken.hashedToken integration.userId = user._id integration._createdAt = new Date integration._createdBy = RocketChat.models.Users.findOne @userId, {fields: {username: 1}} - RocketChat.models.Users.update {_id: user._id}, updateObj - integration._id = RocketChat.models.Integrations.insert integration return integration diff --git a/packages/rocketchat-integrations/server/methods/outgoing/deleteOutgoingIntegration.coffee b/packages/rocketchat-integrations/server/methods/outgoing/deleteOutgoingIntegration.coffee new file mode 100644 index 000000000000..b13af8bdd514 --- /dev/null +++ b/packages/rocketchat-integrations/server/methods/outgoing/deleteOutgoingIntegration.coffee @@ -0,0 +1,13 @@ +Meteor.methods + deleteOutgoingIntegration: (integrationId) -> + if not RocketChat.authz.hasPermission @userId, 'manage-integrations' + throw new Meteor.Error 'not_authorized' + + integration = RocketChat.models.Integrations.findOne(integrationId) + + if not integration? + throw new Meteor.Error 'invalid_integration', '[methods] deleteOutgoingIntegration -> integration not found' + + RocketChat.models.Integrations.remove _id: integrationId + + return true diff --git a/packages/rocketchat-integrations/server/methods/outgoing/updateOutgoingIntegration.coffee b/packages/rocketchat-integrations/server/methods/outgoing/updateOutgoingIntegration.coffee new file mode 100644 index 000000000000..d91c552aed19 --- /dev/null +++ b/packages/rocketchat-integrations/server/methods/outgoing/updateOutgoingIntegration.coffee @@ -0,0 +1,84 @@ +Meteor.methods + updateOutgoingIntegration: (integrationId, integration) -> + if not RocketChat.authz.hasPermission @userId, 'manage-integrations' + throw new Meteor.Error 'not_authorized' + + if integration.username.trim() is '' + throw new Meteor.Error 'invalid_username', '[methods] updateOutgoingIntegration -> username can\'t be empty' + + if not Match.test integration.urls, [String] + throw new Meteor.Error 'invalid_urls', '[methods] updateOutgoingIntegration -> urls must be an array' + + for url, index in integration.urls + delete integration.urls[index] if url.trim() is '' + + integration.urls = _.without integration.urls, [undefined] + + if integration.urls.length is 0 + throw new Meteor.Error 'invalid_urls', '[methods] updateOutgoingIntegration -> urls is required' + + if integration.channel?.trim() isnt '' and integration.channel[0] not in ['@', '#'] + throw new Meteor.Error 'invalid_channel', '[methods] updateOutgoingIntegration -> channel should start with # or @' + + if not integration.token? or integration.token?.trim() is '' + throw new Meteor.Error 'invalid_token', '[methods] updateOutgoingIntegration -> token is required' + + if integration.triggerWords? + if not Match.test integration.triggerWords, [String] + throw new Meteor.Error 'invalid_triggerWords', '[methods] updateOutgoingIntegration -> triggerWords must be an array' + + for triggerWord, index in integration.triggerWords + delete integration.triggerWords[index] if triggerWord.trim() is '' + + integration.triggerWords = _.without integration.triggerWords, [undefined] + + if integration.triggerWords.length is 0 and not integration.channel? + throw new Meteor.Error 'invalid_triggerWords', '[methods] updateOutgoingIntegration -> triggerWords is required if channel is empty' + + if not RocketChat.models.Integrations.findOne(integrationId)? + throw new Meteor.Error 'invalid_integration', '[methods] updateOutgoingIntegration -> integration not found' + + + if integration.channel?.trim() isnt '' + record = undefined + channelType = integration.channel[0] + channel = integration.channel.substr(1) + + switch channelType + when '#' + record = RocketChat.models.Rooms.findOne + $or: [ + {_id: channel} + {name: channel} + ] + when '@' + record = RocketChat.models.Users.findOne + $or: [ + {_id: channel} + {username: channel} + ] + + if record is undefined + throw new Meteor.Error 'channel_does_not_exists', "[methods] updateOutgoingIntegration -> The channel does not exists" + + user = RocketChat.models.Users.findOne({username: integration.username}) + + if not user? + throw new Meteor.Error 'user_does_not_exists', "[methods] updateOutgoingIntegration -> The username does not exists" + + RocketChat.models.Integrations.update integrationId, + $set: + name: integration.name + avatar: integration.avatar + emoji: integration.emoji + alias: integration.alias + channel: integration.channel + username: integration.username + userId: user._id + urls: integration.urls + token: integration.token + triggerWords: integration.triggerWords + _updatedAt: new Date + _updatedBy: RocketChat.models.Users.findOne @userId, {fields: {username: 1}} + + return RocketChat.models.Integrations.findOne(integrationId) From f5aae4f334d38c94a12171116c38edf91b3dc442 Mon Sep 17 00:00:00 2001 From: Marcelo Schmidt Date: Tue, 22 Dec 2015 19:31:45 -0200 Subject: [PATCH 056/103] Fix conflitcs --- .../client/views/channelSettings.html | 31 ++++++------------- .../i18n/en.i18n.json | 1 + 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/packages/rocketchat-channel-settings/client/views/channelSettings.html b/packages/rocketchat-channel-settings/client/views/channelSettings.html index 35f3b002127a..8a326bd49117 100644 --- a/packages/rocketchat-channel-settings/client/views/channelSettings.html +++ b/packages/rocketchat-channel-settings/client/views/channelSettings.html @@ -27,7 +27,6 @@

{{_ "Room_Info"}}

{{roomTopic}}{{#if canEdit}} {{/if}} {{/if}}
-<<<<<<< HEAD {{#if notDirect}}
  • @@ -44,31 +43,21 @@

    {{_ "Room_Info"}}

  • {{/if}} + {{#if notDirect}} +
  • + + {{#if archived}} + + {{else}} + + {{/if}} +
  • + {{/if}} {{#each channelSettings}} {{> Template.dynamic template=template data=data}} {{/each}}
    -======= -
    - {{/if}} - -
    - -
    - -
    - {{#if notDirect}} -
    - {{#if archived}} - - {{else}} - - {{/if}} -
    - {{/if}} -
    ->>>>>>> f838e9efb88902148d9cf0400d18802de24abc4c diff --git a/packages/rocketchat-channel-settings/i18n/en.i18n.json b/packages/rocketchat-channel-settings/i18n/en.i18n.json index 44e8aa2ccb95..c6ebf4e70dc9 100644 --- a/packages/rocketchat-channel-settings/i18n/en.i18n.json +++ b/packages/rocketchat-channel-settings/i18n/en.i18n.json @@ -1,4 +1,5 @@ { + "Archive_Unarchive": "Archive / Unarchive", "Cancel": "Cancel", "Channel": "Channel", "Private_Group": "Private Group", From 1b73cd314c020fd591a853446d89eb62ded0274c Mon Sep 17 00:00:00 2001 From: Gabriel Engel Date: Tue, 22 Dec 2015 19:33:58 -0200 Subject: [PATCH 057/103] update aldeed:simple-schema to 1.5.2 and cosmos:browserify to 0.9.3 --- .meteor/versions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.meteor/versions b/.meteor/versions index 7fcf629285f8..11a58480adcd 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -7,7 +7,7 @@ accounts-oauth@1.1.8 accounts-password@1.1.4 accounts-twitter@1.0.6 alanning:roles@1.2.14 -aldeed:simple-schema@1.5.1 +aldeed:simple-schema@1.5.2 arunoda:streams@0.1.17 autoupdate@1.2.4 babel-compiler@5.8.24_1 @@ -25,7 +25,7 @@ cfs:http-methods@0.0.30 check@1.1.0 chrismbeckett:toastr@2.1.2_1 coffeescript@1.0.11 -cosmos:browserify@0.9.2 +cosmos:browserify@0.9.3 dandv:caret-position@2.1.1 ddp@1.2.2 ddp-client@1.2.1 From 280a9d8c9a38d98bfbf0b4d1446f91cfd5e0d939 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Tue, 22 Dec 2015 22:25:16 -0200 Subject: [PATCH 058/103] Execute outgoing triggers --- packages/rocketchat-integrations/package.js | 3 + .../server/triggers.coffee | 96 +++++++++++++++++++ .../server/functions/sendMessage.coffee | 2 +- 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 packages/rocketchat-integrations/server/triggers.coffee diff --git a/packages/rocketchat-integrations/package.js b/packages/rocketchat-integrations/package.js index ff01a9012937..beb7b8d849a2 100644 --- a/packages/rocketchat-integrations/package.js +++ b/packages/rocketchat-integrations/package.js @@ -52,6 +52,9 @@ Package.onUse(function(api) { // api api.addFiles('server/api/api.coffee', 'server'); + + api.addFiles('server/triggers.coffee', 'server'); + var _ = Npm.require('underscore'); var fs = Npm.require('fs'); tapi18nFiles = _.compact(_.map(fs.readdirSync('packages/rocketchat-integrations/i18n'), function(filename) { diff --git a/packages/rocketchat-integrations/server/triggers.coffee b/packages/rocketchat-integrations/server/triggers.coffee new file mode 100644 index 000000000000..3d40bffe8e0f --- /dev/null +++ b/packages/rocketchat-integrations/server/triggers.coffee @@ -0,0 +1,96 @@ +triggers = {} + +RocketChat.models.Integrations.find({type: 'webhook-outgoing'}).observe + added: (record) -> + channel = record.channel or '__any' + triggers[channel] ?= {} + triggers[channel][record._id] = record + + changed: (record) -> + channel = record.channel or '__any' + triggers[channel] ?= {} + triggers[channel][record._id] = record + + removed: (record) -> + channel = record.channel or '__any' + delete triggers[channel][record._id] + + +ExecuteTriggerUrl = (url, trigger, message, room, tries=0) -> + urlObj = URL.parse url + + console.log tries + word = undefined + if trigger.triggerWords?.length > 0 + for triggerWord in trigger.triggerWords + if message.msg.indexOf(triggerWord) is 0 + word = triggerWord + break + + # Stop if there are triggerWords but none match + if not word? + return + + data = + token: trigger.token + # team_id=T0001 + # team_domain=example + channel_id: room._id + channel_name: room.name + timestamp: message.ts + user_id: message.u._id + user_name: message.u.username + text: message.msg + + if word? + data.trigger_word = word + + opts = + data: data + npmRequestOptions: + rejectUnauthorized: !RocketChat.settings.get 'Allow_Invalid_SelfSigned_Certs' + strictSSL: !RocketChat.settings.get 'Allow_Invalid_SelfSigned_Certs' + headers: + 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.0 Safari/537.36' + + HTTP.call 'POST', url, opts, (error, result) -> + console.log error, result + if not result? or result.statusCode isnt 200 + if tries <= 6 + # Try again in 0.1s, 1s, 10s, 1m40s, 16m40s, 2h46m40s and 27h46m40s + Meteor.setTimeout -> + ExecuteTriggerUrl url, trigger, message, room, tries+1 + , Math.pow(10, tries+2) + return + + # TODO process return and insert message if necessary + + + +ExecuteTrigger = (trigger, message, room) -> + for url in trigger.urls + ExecuteTriggerUrl url, trigger, message, room + + +ExecuteTriggers = (message, room) -> + if not room? + return + + triggersToExecute = [] + + if triggers[room._id]? + triggersToExecute.push trigger for key, trigger of triggers[room._id] + + if triggers[room.name]? + triggersToExecute.push trigger for key, trigger of triggers[room.name] + + if triggers.__any? + triggersToExecute.push trigger for key, trigger of triggers.__any + + for triggerToExecute in triggersToExecute + ExecuteTrigger triggerToExecute, message, room + + return message + + +RocketChat.callbacks.add 'afterSaveMessage', ExecuteTriggers, RocketChat.callbacks.priority.LOW diff --git a/packages/rocketchat-lib/server/functions/sendMessage.coffee b/packages/rocketchat-lib/server/functions/sendMessage.coffee index 20620d1c9dc5..6b14009c97cc 100644 --- a/packages/rocketchat-lib/server/functions/sendMessage.coffee +++ b/packages/rocketchat-lib/server/functions/sendMessage.coffee @@ -30,7 +30,7 @@ RocketChat.sendMessage = (user, message, room, options) -> ### Meteor.defer -> - RocketChat.callbacks.run 'afterSaveMessage', message + RocketChat.callbacks.run 'afterSaveMessage', message, room ### Update all the room activity tracker fields From 312347b9257573bd760ec06fe20fff954b737b2e Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Wed, 23 Dec 2015 09:21:52 -0200 Subject: [PATCH 059/103] better message positioning --- .../rocketchat-theme/assets/stylesheets/base.less | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/rocketchat-theme/assets/stylesheets/base.less b/packages/rocketchat-theme/assets/stylesheets/base.less index 33a92f341218..dcd4e3b63172 100644 --- a/packages/rocketchat-theme/assets/stylesheets/base.less +++ b/packages/rocketchat-theme/assets/stylesheets/base.less @@ -2493,7 +2493,7 @@ a.github-fork { } .message { - padding: 11px 20px 11px 70px; + padding: 8px 20px 4px 70px; position: relative; line-height: 20px; min-height: 40px; @@ -2635,7 +2635,6 @@ a.github-fork { .thumb { position: absolute; left: 20px; - top: 11px; display: block; width: 40px; height: 40px; @@ -2671,6 +2670,7 @@ a.github-fork { min-height: 20px; padding-top: 4px; padding-bottom: 4px; + margin-top: 0px; .user { display: none; } @@ -2699,6 +2699,9 @@ a.github-fork { margin-left: 1px; } } + .body { + margin-top: 0px; + } // .message-dropdown { // top: 100%; @@ -2735,6 +2738,7 @@ a.github-fork { .body { opacity: 1; .transition(opacity 1s linear); + margin-top: 2px; .inline-image { background-size: contain; @@ -2765,9 +2769,9 @@ a.github-fork { .compact { .message { - padding: 5px 20px 5px 70px; - .thumb { - top: 5px; + padding: 4px 20px 4px 70px; + .body { + margin-top: 0px; } } } From 69a22342acedaa1233ccf2843fefbf0b8a26ada1 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Wed, 23 Dec 2015 11:13:06 -0200 Subject: [PATCH 060/103] Move set of integration type to server side --- .../client/views/integrationsIncoming.coffee | 1 - .../client/views/integrationsOutgoing.coffee | 2 -- .../server/methods/incoming/addIncomingIntegration.coffee | 1 + .../server/methods/outgoing/addOutgoingIntegration.coffee | 1 + 4 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/rocketchat-integrations/client/views/integrationsIncoming.coffee b/packages/rocketchat-integrations/client/views/integrationsIncoming.coffee index b3aabfa5bc03..8e8f09dd0e12 100644 --- a/packages/rocketchat-integrations/client/views/integrationsIncoming.coffee +++ b/packages/rocketchat-integrations/client/views/integrationsIncoming.coffee @@ -147,7 +147,6 @@ Template.integrationsIncoming.events toastr.success TAPi18n.__("Integration_updated") else - integration.type = 'webhook-incoming' integration.username = username Meteor.call "addIncomingIntegration", integration, (err, data) -> diff --git a/packages/rocketchat-integrations/client/views/integrationsOutgoing.coffee b/packages/rocketchat-integrations/client/views/integrationsOutgoing.coffee index 5430d9c97d9d..7a46f17ffb20 100644 --- a/packages/rocketchat-integrations/client/views/integrationsOutgoing.coffee +++ b/packages/rocketchat-integrations/client/views/integrationsOutgoing.coffee @@ -162,8 +162,6 @@ Template.integrationsOutgoing.events toastr.success TAPi18n.__("Integration_updated") else - integration.type = 'webhook-outgoing' - Meteor.call "addOutgoingIntegration", integration, (err, data) -> if err? return toastr.error TAPi18n.__(err.error) diff --git a/packages/rocketchat-integrations/server/methods/incoming/addIncomingIntegration.coffee b/packages/rocketchat-integrations/server/methods/incoming/addIncomingIntegration.coffee index 316127e53acd..316c748ca198 100644 --- a/packages/rocketchat-integrations/server/methods/incoming/addIncomingIntegration.coffee +++ b/packages/rocketchat-integrations/server/methods/incoming/addIncomingIntegration.coffee @@ -53,6 +53,7 @@ Meteor.methods hashedToken: hashStampedToken.hashedToken integration: true + integration.type = 'webhook-incoming' integration.token = hashStampedToken.hashedToken integration.userId = user._id integration._createdAt = new Date diff --git a/packages/rocketchat-integrations/server/methods/outgoing/addOutgoingIntegration.coffee b/packages/rocketchat-integrations/server/methods/outgoing/addOutgoingIntegration.coffee index be7e0372172e..fe01c82b0968 100644 --- a/packages/rocketchat-integrations/server/methods/outgoing/addOutgoingIntegration.coffee +++ b/packages/rocketchat-integrations/server/methods/outgoing/addOutgoingIntegration.coffee @@ -63,6 +63,7 @@ Meteor.methods if not user? throw new Meteor.Error 'user_does_not_exists', "[methods] addOutgoingIntegration -> The username does not exists" + integration.type = 'webhook-outgoing' integration.userId = user._id integration._createdAt = new Date integration._createdBy = RocketChat.models.Users.findOne @userId, {fields: {username: 1}} From 3ca4af3e43c28e458438dddf97481ed5ce84e3f1 Mon Sep 17 00:00:00 2001 From: Christian Kniep Date: Wed, 23 Dec 2015 14:13:36 +0100 Subject: [PATCH 061/103] adjust tgz filename --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 9980acc5751c..361dbcb90f63 100755 --- a/install.sh +++ b/install.sh @@ -8,7 +8,7 @@ if [ "$1" == "development" ]; then fi cd $ROOTPATH -curl -fSL "https://s3.amazonaws.com/rocketchatbuild/demo.rocket.chat-v.latest.tgz" -o rocket.chat.tgz +curl -fSL "https://s3.amazonaws.com/rocketchatbuild/rocket.chat-develop.tgz" -o rocket.chat.tgz tar zxf rocket.chat.tgz && rm rocket.chat.tgz cd $ROOTPATH/bundle/programs/server npm install From 77122baa1b13243934664b90960b9ac3e019cb9e Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Wed, 23 Dec 2015 11:13:48 -0200 Subject: [PATCH 062/103] Add role bot to users of integrations in scope bot --- packages/rocketchat-authorization/server/startup.coffee | 2 +- packages/rocketchat-integrations/package.js | 1 + .../server/methods/incoming/addIncomingIntegration.coffee | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/rocketchat-authorization/server/startup.coffee b/packages/rocketchat-authorization/server/startup.coffee index 663f7354970a..81924e48b3a7 100644 --- a/packages/rocketchat-authorization/server/startup.coffee +++ b/packages/rocketchat-authorization/server/startup.coffee @@ -103,7 +103,7 @@ Meteor.startup -> roles : ['admin']} { _id: 'manage-integrations', - roles : ['admin']} + roles : ['admin', 'bot']} ] #alanning:roles diff --git a/packages/rocketchat-integrations/package.js b/packages/rocketchat-integrations/package.js index beb7b8d849a2..06aebfe354d3 100644 --- a/packages/rocketchat-integrations/package.js +++ b/packages/rocketchat-integrations/package.js @@ -13,6 +13,7 @@ Package.onUse(function(api) { api.use('underscore'); api.use('simple:highlight.js'); api.use('rocketchat:lib@0.0.1'); + api.use('alanning:roles@1.2.12'); api.use('kadira:flow-router', 'client'); api.use('templating', 'client'); diff --git a/packages/rocketchat-integrations/server/methods/incoming/addIncomingIntegration.coffee b/packages/rocketchat-integrations/server/methods/incoming/addIncomingIntegration.coffee index 316c748ca198..67c33d156f6a 100644 --- a/packages/rocketchat-integrations/server/methods/incoming/addIncomingIntegration.coffee +++ b/packages/rocketchat-integrations/server/methods/incoming/addIncomingIntegration.coffee @@ -61,6 +61,8 @@ Meteor.methods RocketChat.models.Users.update {_id: user._id}, updateObj + Roles.addUsersToRoles user._id, 'bot', 'bot' + integration._id = RocketChat.models.Integrations.insert integration return integration From 0034c372be9114aa076b3b08f9d29b9a3f05d2f9 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Wed, 23 Dec 2015 11:14:06 -0200 Subject: [PATCH 063/103] Allow creation of outgoing integrations from bots --- .../server/methods/outgoing/addOutgoingIntegration.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rocketchat-integrations/server/methods/outgoing/addOutgoingIntegration.coffee b/packages/rocketchat-integrations/server/methods/outgoing/addOutgoingIntegration.coffee index fe01c82b0968..c27c7c124418 100644 --- a/packages/rocketchat-integrations/server/methods/outgoing/addOutgoingIntegration.coffee +++ b/packages/rocketchat-integrations/server/methods/outgoing/addOutgoingIntegration.coffee @@ -1,6 +1,6 @@ Meteor.methods addOutgoingIntegration: (integration) -> - if not RocketChat.authz.hasPermission @userId, 'manage-integrations' + if not RocketChat.authz.hasPermission(@userId, 'manage-integrations') and not RocketChat.authz.hasPermission(@userId, 'manage-integrations', 'bot') throw new Meteor.Error 'not_authorized' if integration.username.trim() is '' From 4745f771cc612a4e1c97e7a3b7342b84c77dcaa5 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Wed, 23 Dec 2015 11:14:18 -0200 Subject: [PATCH 064/103] Fix update of permissions --- packages/rocketchat-authorization/server/startup.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rocketchat-authorization/server/startup.coffee b/packages/rocketchat-authorization/server/startup.coffee index 81924e48b3a7..7e347bdeffb5 100644 --- a/packages/rocketchat-authorization/server/startup.coffee +++ b/packages/rocketchat-authorization/server/startup.coffee @@ -110,7 +110,7 @@ Meteor.startup -> roles = _.pluck(Roles.getAllRoles().fetch(), 'name'); for permission in permissions - RocketChat.models.Permissions.upsert( permission._id, {$setOnInsert : permission }) + RocketChat.models.Permissions.upsert( permission._id, {$set: permission }) for role in permission.roles unless role in roles Roles.createRole role From 1790480840959b4ddc577e9d2acf501c60d7bbcf Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Wed, 23 Dec 2015 11:14:36 -0200 Subject: [PATCH 065/103] Add route to cadastre new integrations via API --- .../server/api/api.coffee | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/rocketchat-integrations/server/api/api.coffee b/packages/rocketchat-integrations/server/api/api.coffee index 068df884161f..46cf791c1a76 100644 --- a/packages/rocketchat-integrations/server/api/api.coffee +++ b/packages/rocketchat-integrations/server/api/api.coffee @@ -100,3 +100,29 @@ Api.addRoute ':integrationId/:userId/:token', authRequired: true, statusCode: 200 body: success: true + + +Api.addRoute 'manageintegrations/:integrationId/:userId/:token', authRequired: true, + post: -> + if @bodyParams?.payload? + @bodyParams = JSON.parse @bodyParams.payload + + integration = RocketChat.models.Integrations.findOne(@urlParams.integrationId) + user = RocketChat.models.Users.findOne(@userId) + + if not integration? + return {} = + statusCode: 400 + body: + success: false + error: 'Invalid integraiton id' + + switch @bodyParams.action + when 'addOutgoingIntegration' + Meteor.runAsUser user._id, => + Meteor.call 'addOutgoingIntegration', @bodyParams.data + + return {} = + statusCode: 200 + body: + success: true From 9dbde68d25e0fa0947f3ed521749752a67e4653f Mon Sep 17 00:00:00 2001 From: Christian Kniep Date: Wed, 23 Dec 2015 14:15:32 +0100 Subject: [PATCH 066/103] adjust tgz filename in Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d43c1d2cd2cd..cbb9a7bfe124 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ RUN gpg --keyserver ha.pool.sks-keyservers.net --recv-keys 0E163286C20D07B9787EB WORKDIR /app -RUN curl -fSL "https://s3.amazonaws.com/rocketchatbuild/develop.rocket.chat-v.latest.tgz" -o rocket.chat.tgz \ +RUN curl -fSL "https://s3.amazonaws.com/rocketchatbuild/rocket.chat-develop.tgz" -o rocket.chat.tgz \ && tar zxvf ./rocket.chat.tgz \ && rm ./rocket.chat.tgz \ && cd /app/bundle/programs/server \ From 8929012001aed057bf3cdf1c36a9c294e1e4fcfa Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Wed, 23 Dec 2015 12:33:08 -0200 Subject: [PATCH 067/103] enable/disable livechat pre registration form pick a department at livechat pre registration --- .../rocketchat-livechat/app/.meteor/packages | 2 + .../rocketchat-livechat/app/.meteor/versions | 1 + .../app/client/lib/collections.coffee | 1 + .../app/client/routes/router.coffee | 2 +- .../app/client/stylesheets/main.less | 23 ++++--- .../views/{room.html => livechatWindow.html} | 8 +-- .../views/{room.js => livechatWindow.js} | 40 +++++++------ .../app/client/views/register.coffee | 50 ---------------- .../app/client/views/register.html | 11 +++- .../app/client/views/register.js | 60 +++++++++++++++++++ .../rocketchat-livechat/app/i18n/en.i18n.json | 3 +- packages/rocketchat-livechat/config.js | 1 + .../rocketchat-livechat/i18n/en.i18n.json | 1 + packages/rocketchat-livechat/package.js | 1 + .../server/lib/getNextAgent.js | 2 +- .../server/methods/registerGuest.js | 5 +- .../server/methods/sendMessageLivechat.js | 5 +- .../server/models/LivechatDepartment.js | 8 +++ .../publications/availableDepartments.js | 3 + 19 files changed, 134 insertions(+), 93 deletions(-) rename packages/rocketchat-livechat/app/client/views/{room.html => livechatWindow.html} (89%) rename packages/rocketchat-livechat/app/client/views/{room.js => livechatWindow.js} (56%) delete mode 100644 packages/rocketchat-livechat/app/client/views/register.coffee create mode 100644 packages/rocketchat-livechat/app/client/views/register.js create mode 100644 packages/rocketchat-livechat/server/publications/availableDepartments.js diff --git a/packages/rocketchat-livechat/app/.meteor/packages b/packages/rocketchat-livechat/app/.meteor/packages index 2f093f910063..83352a667a8d 100644 --- a/packages/rocketchat-livechat/app/.meteor/packages +++ b/packages/rocketchat-livechat/app/.meteor/packages @@ -36,3 +36,5 @@ accounts-password standard-minifiers tap:i18n kevohagan:sweetalert +ecmascript +es5-shim diff --git a/packages/rocketchat-livechat/app/.meteor/versions b/packages/rocketchat-livechat/app/.meteor/versions index 34a2055ee61d..3105a3bc8090 100644 --- a/packages/rocketchat-livechat/app/.meteor/versions +++ b/packages/rocketchat-livechat/app/.meteor/versions @@ -27,6 +27,7 @@ ecmascript@0.1.6 ecmascript-runtime@0.2.6 ejson@1.0.7 email@1.0.8 +es5-shim@4.1.14 geojson-utils@1.0.4 html-tools@1.0.5 htmljs@1.0.5 diff --git a/packages/rocketchat-livechat/app/client/lib/collections.coffee b/packages/rocketchat-livechat/app/client/lib/collections.coffee index 788b96e44405..c86ad59f9dde 100644 --- a/packages/rocketchat-livechat/app/client/lib/collections.coffee +++ b/packages/rocketchat-livechat/app/client/lib/collections.coffee @@ -2,3 +2,4 @@ @ChatRoom = new Meteor.Collection 'rocketchat_room' @Settings = new Meteor.Collection 'rocketchat_settings' @Trigger = new Meteor.Collection 'rocketchat_livechat_trigger' +@Department = new Meteor.Collection 'rocketchat_livechat_department' diff --git a/packages/rocketchat-livechat/app/client/routes/router.coffee b/packages/rocketchat-livechat/app/client/routes/router.coffee index 1105938efd90..6b1712849214 100644 --- a/packages/rocketchat-livechat/app/client/routes/router.coffee +++ b/packages/rocketchat-livechat/app/client/routes/router.coffee @@ -9,4 +9,4 @@ FlowRouter.route '/livechat', ] action: -> - BlazeLayout.render 'main', {center: 'room'} + BlazeLayout.render 'main', {center: 'livechatWindow'} diff --git a/packages/rocketchat-livechat/app/client/stylesheets/main.less b/packages/rocketchat-livechat/app/client/stylesheets/main.less index 94064d9f020a..f355eca4e455 100644 --- a/packages/rocketchat-livechat/app/client/stylesheets/main.less +++ b/packages/rocketchat-livechat/app/client/stylesheets/main.less @@ -1,4 +1,3 @@ -@import url(//fonts.googleapis.com/css?family=Roboto:300,400,500,600,700&subset=latin,cyrillic-ext,greek-ext,greek,vietnamese,latin-ext,cyrillic); @import "_variables.less"; @import "utils/_lesshat.import.less"; @import "utils/_reset.import.less"; @@ -13,11 +12,9 @@ html, body { height: 100%; } body { - padding: 0; margin: 0; - font-size: 10pt; - font-family: "Roboto", "HelveticaNeue", sans-serif; - // font-size: 14px; + font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif, "Meiryo UI"; + font-size: 0.8rem; color: @primary-font-color; height: 100%; width: 100%; @@ -36,6 +33,11 @@ textarea { font-family: inherit; font-size: inherit; line-height: inherit; + padding: 5px; + margin: 5px; + border: 1px solid #E7E7E7; + border-radius: 5px; + outline: none; } input:focus { @@ -54,6 +56,7 @@ input:focus { word-spacing: 0; box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.125); border: none; + border-radius: 0; line-height: 16px; position: relative; cursor: pointer;background-color: #FFF; @@ -367,9 +370,7 @@ input:focus { padding-right: 38px; overflow-y: auto; resize: none; - border: 1px solid #E7E7E7; - // margin: 10px; - border-radius: 5px; + margin: 0; max-height: 200px; width: 100%; font-size: 12px; @@ -378,7 +379,6 @@ input:focus { line-height: normal; background-color: #fff; position: relative; - outline: none; } } } @@ -399,11 +399,10 @@ input:focus { border-right: 1px solid #E7E7E7; padding: 5px; - input, button { + input, button, select { display: block; - padding: 5px; - margin: 5px; } + .error { display: none; // width: 100%; diff --git a/packages/rocketchat-livechat/app/client/views/room.html b/packages/rocketchat-livechat/app/client/views/livechatWindow.html similarity index 89% rename from packages/rocketchat-livechat/app/client/views/room.html rename to packages/rocketchat-livechat/app/client/views/livechatWindow.html index 6cb419c8c79c..91618ab52262 100644 --- a/packages/rocketchat-livechat/app/client/views/room.html +++ b/packages/rocketchat-livechat/app/client/views/livechatWindow.html @@ -1,4 +1,4 @@ - diff --git a/packages/rocketchat-livechat/app/public/logo-dark.svg b/packages/rocketchat-livechat/app/public/logo-dark.svg new file mode 100644 index 000000000000..4f6fa55412cd --- /dev/null +++ b/packages/rocketchat-livechat/app/public/logo-dark.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 43c1189d3fe9ed641ee3108b4cdc526c0516642f Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Thu, 24 Dec 2015 12:12:38 -0200 Subject: [PATCH 090/103] fix livechat triggers not triggering --- .../lib/fromApp/RoomHistoryManager.coffee | 2 ++ .../app/client/lib/triggers.js | 24 ++++++++++++++++--- .../assets/rocket-livechat.js | 2 +- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/packages/rocketchat-livechat/app/client/lib/fromApp/RoomHistoryManager.coffee b/packages/rocketchat-livechat/app/client/lib/fromApp/RoomHistoryManager.coffee index c12bd00df8d2..d21a2a296144 100644 --- a/packages/rocketchat-livechat/app/client/lib/fromApp/RoomHistoryManager.coffee +++ b/packages/rocketchat-livechat/app/client/lib/fromApp/RoomHistoryManager.coffee @@ -30,6 +30,8 @@ ts = new Date Meteor.call 'loadHistory', rid, ts, limit, undefined, (err, result) -> + return if err? + for item in result?.messages or [] if item.t isnt 'command' ChatMessage.upsert {_id: item._id}, item diff --git a/packages/rocketchat-livechat/app/client/lib/triggers.js b/packages/rocketchat-livechat/app/client/lib/triggers.js index 9d05e1845c05..f9f528cf1b36 100644 --- a/packages/rocketchat-livechat/app/client/lib/triggers.js +++ b/packages/rocketchat-livechat/app/client/lib/triggers.js @@ -1,9 +1,20 @@ this.Triggers = (function() { var triggers = []; + var initiated = false; + var requests = []; var init = function() { + initiated = true; Tracker.autorun(function() { triggers = Trigger.find().fetch(); + + if (requests.length > 0 && triggers.length > 0) { + requests.forEach(function(request) { + processRequest(request); + }); + + requests = []; + } }); }; @@ -14,13 +25,17 @@ this.Triggers = (function() { } actions.forEach(function(action) { if (action.name === 'send-message') { - var room = Random.id(); - visitor.setRoom(room); + var roomId = visitor.getRoom(); + + if (!roomId) { + roomId = Random.id(); + visitor.setRoom(roomId); + } Session.set('triggered', true); ChatMessage.insert({ msg: action.params.msg, - rid: room, + rid: roomId, u: { username: action.params.name } @@ -32,6 +47,9 @@ this.Triggers = (function() { }; var processRequest = function(request) { + if (!initiated) { + return requests.push(request); + } triggers.forEach(function(trigger) { trigger.conditions.forEach(function(condition) { switch (condition.name) { diff --git a/packages/rocketchat-livechat/assets/rocket-livechat.js b/packages/rocketchat-livechat/assets/rocket-livechat.js index 823152f797e5..47e29c10333a 100644 --- a/packages/rocketchat-livechat/assets/rocket-livechat.js +++ b/packages/rocketchat-livechat/assets/rocket-livechat.js @@ -119,7 +119,7 @@ w.addEventListener('message', function(msg) { if (typeof msg.data === 'object' && msg.data.src !== undefined && msg.data.src === 'rocketchat') { if (api[msg.data.fn] !== undefined && typeof api[msg.data.fn] === 'function') { - var args = [].concat(msg.data.args || []) + var args = [].concat(msg.data.args || []); api[msg.data.fn].apply(null, args); } } From c5837cf9727cf8da7329fe92a23ca57fffa7aded Mon Sep 17 00:00:00 2001 From: Gabriel Engel Date: Thu, 24 Dec 2015 16:04:07 -0200 Subject: [PATCH 091/103] make sample data into array --- .../server/api/api.coffee | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/rocketchat-integrations/server/api/api.coffee b/packages/rocketchat-integrations/server/api/api.coffee index 308ef4465c6b..c45b719b3287 100644 --- a/packages/rocketchat-integrations/server/api/api.coffee +++ b/packages/rocketchat-integrations/server/api/api.coffee @@ -182,19 +182,38 @@ Api.addRoute 'remove/:integrationId/:userId/:token', authRequired: true, Api.addRoute 'sample/:integrationId/:userId/:token', authRequired: true, get: -> - console.log 'Sample integration' + console.log 'Sample Integration' return {} = statusCode: 200 - body: + body: [ + token: Random.id(24) + channel_id: Random.id() + channel_name: 'general' + timestamp: new Date + user_id: Random.id() + user_name: 'rocket.cat' + text: 'Sample text 1' + trigger_word: 'Sample' + ],[ + token: Random.id(24) + channel_id: Random.id() + channel_name: 'general' + timestamp: new Date + user_id: Random.id() + user_name: 'rocket.cat' + text: 'Sample text 2' + trigger_word: 'Sample' + ],[ token: Random.id(24) channel_id: Random.id() channel_name: 'general' timestamp: new Date user_id: Random.id() user_name: 'rocket.cat' - text: 'Sample text' + text: 'Sample text 3' trigger_word: 'Sample' + ] Api.addRoute 'info/:integrationId/:userId/:token', authRequired: true, From ec194a13b1a1dd951f2980c416a6d4e33906410d Mon Sep 17 00:00:00 2001 From: Gabriel Engel Date: Thu, 24 Dec 2015 16:10:30 -0200 Subject: [PATCH 092/103] embarrassing mistake --- packages/rocketchat-integrations/server/api/api.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/rocketchat-integrations/server/api/api.coffee b/packages/rocketchat-integrations/server/api/api.coffee index c45b719b3287..f2d9e11873a1 100644 --- a/packages/rocketchat-integrations/server/api/api.coffee +++ b/packages/rocketchat-integrations/server/api/api.coffee @@ -195,7 +195,7 @@ Api.addRoute 'sample/:integrationId/:userId/:token', authRequired: true, user_name: 'rocket.cat' text: 'Sample text 1' trigger_word: 'Sample' - ],[ + , token: Random.id(24) channel_id: Random.id() channel_name: 'general' @@ -204,7 +204,7 @@ Api.addRoute 'sample/:integrationId/:userId/:token', authRequired: true, user_name: 'rocket.cat' text: 'Sample text 2' trigger_word: 'Sample' - ],[ + , token: Random.id(24) channel_id: Random.id() channel_name: 'general' From 9ea943e0a271e8a81e8d84e697e2a836d6832287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mauricio=20S=C3=A1nchez?= Date: Thu, 24 Dec 2015 13:13:12 -0500 Subject: [PATCH 093/103] Added new color variables to the theme editor --- .../stylesheets/utils/_colors.import.less | 41 +++++++++---------- packages/rocketchat-theme/i18n/en.i18n.json | 9 +++- .../rocketchat-theme/server/variables.coffee | 8 ++++ 3 files changed, 36 insertions(+), 22 deletions(-) mode change 100644 => 100755 packages/rocketchat-theme/assets/stylesheets/utils/_colors.import.less mode change 100644 => 100755 packages/rocketchat-theme/i18n/en.i18n.json mode change 100644 => 100755 packages/rocketchat-theme/server/variables.coffee diff --git a/packages/rocketchat-theme/assets/stylesheets/utils/_colors.import.less b/packages/rocketchat-theme/assets/stylesheets/utils/_colors.import.less old mode 100644 new mode 100755 index 7bdb7b45f75c..13141a7836e5 --- a/packages/rocketchat-theme/assets/stylesheets/utils/_colors.import.less +++ b/packages/rocketchat-theme/assets/stylesheets/utils/_colors.import.less @@ -123,7 +123,7 @@ blockquote { } html { - .custom-scroll(transparent, rgba(255, 255, 255, 0.05), 3px); + .custom-scroll(transparent, @custom-scrollbar-color, 3px); } body { @@ -212,9 +212,8 @@ label.required:after { // new layout buttons .button { - background-color: #FFF; color: rgba(255, 255, 255, 0.85); - background-color: lighten(desaturate(@primary-background-color, 15%), 12.5%); + background-color: @action-buttons-color; &:before { background-color: rgba(0, 0, 0, 0.1); } @@ -237,7 +236,7 @@ label.required:after { background-color: #02acec; } &.clean { - background-color: rgba(0, 0, 0, 0.025); + background-color: @clean-buttons-color; } &.facebook { background-color: #325c99; @@ -328,7 +327,7 @@ a.github-fork { .info { background-color:@primary-background-color; h4 { - color: rgba(255, 255, 255, 0.65); + color: fade( @quaternary-font-color, 65% ); } &.status-offline { .thumb:after { @@ -384,29 +383,29 @@ a.github-fork { border-color: #9f0030; background-color: #D30230; } - } + } } span.soon { color: #aaa; } a { - color: rgba(255, 255, 255, 0.5); + color: fade( @quaternary-font-color, 50% ); border-bottom-color: darken(@primary-background-color, 2%); &:hover { background-color: darken(@primary-background-color, 2%); - color: rgba(255, 255, 255, 0.75); + color: fade( @quaternary-font-color, 75% ); } } } &.active .info, .info:hover { h4 { - color: rgba(255, 255, 255, 0.85); + color: fade(@quaternary-font-color, 85% ); } } .hover & { .info h4 { - color: rgba(255, 255, 255, 0.85); + color: fade(@quaternary-font-color, 85% ); } } } @@ -416,7 +415,7 @@ a.github-fork { //background-color: @primary-background-color; background-color: transparent; color: @tertiary-font-color; - .custom-scroll(transparent, rgba(255, 255, 255, 0.05)); + .custom-scroll(transparent, @custom-scrollbar-color); header { background-color: @primary-background-color; } @@ -424,7 +423,7 @@ a.github-fork { background-color: @primary-background-color; } .content { - .custom-scroll(transparent, rgba(255, 255, 255, 0.05)); + .custom-scroll(transparent, @custom-scrollbar-color); background-color: @primary-background-color; } .input-line { @@ -455,7 +454,7 @@ a.github-fork { } .rooms-list { background-color: lighten(@primary-background-color, 2%); - .custom-scroll(transparent, rgba(255, 255, 255, 0.05)); + .custom-scroll(transparent, @custom-scrollbar-color); } .more { color: @tertiary-font-color; @@ -478,7 +477,7 @@ a.github-fork { &:hover { &:before, &:after { - background-color: rgba(255, 255, 255, 0.85); + background-color: fade( @quaternary-font-color, 85% ); } } } @@ -499,7 +498,7 @@ a.github-fork { } } .unread { - background-color: #1dce73; + background-color: @unread-notification-color; color: #FFF; } ul { @@ -515,8 +514,8 @@ a.github-fork { } &.active { a { - background-color: rgba(255, 255, 255, 0.075); - color: rgba(255, 255, 255, 0.75); + background-color: @active-channel-background-color; + color: @active-channel-font-color; } .opt { background-color: transparent; @@ -524,7 +523,7 @@ a.github-fork { } &.has-alert { .name { - color: #ffffff; + color: @quaternary-font-color; } } &.away { @@ -542,14 +541,14 @@ a.github-fork { .opt { background-color: transparent; i { - color: rgba(255, 255, 255, 0.5); + color: fade(@quaternary-font-color, 50% ); &:hover { - color: rgba(255, 255, 255, 0.75); + color: fade(@quaternary-font-color, 75% ); } } } i { - color: rgba(255, 255, 255, 0.35); + color: fade(@quaternary-font-color, 35% ); } input[type=text] { color: #000; diff --git a/packages/rocketchat-theme/i18n/en.i18n.json b/packages/rocketchat-theme/i18n/en.i18n.json old mode 100644 new mode 100755 index ec3bfc800ccd..464bbbb1ea38 --- a/packages/rocketchat-theme/i18n/en.i18n.json +++ b/packages/rocketchat-theme/i18n/en.i18n.json @@ -20,5 +20,12 @@ "theme-color-status-offline" : "Offline Status Color", "theme-color-status-online" : "Online Status Color", "theme-color-tertiary-background-color" : "Tertiary Background Color", - "theme-color-tertiary-font-color" : "Tertiary Font Color" + "theme-color-tertiary-font-color" : "Tertiary Font Color", + "theme-color-quaternary-font-color": "Quaternary Font Color", + "theme-color-active-channel-background-color": "Active Channel Background Color", + "theme-color-active-channel-font-color": "Active Channel Font Color", + "theme-color-custom-scrollbar-color": "Custom Scrollbar Color", + "theme-color-action-buttons-color": "Actions Buttons Color", + "theme-color-clean-buttons-color": "Clean Buttons Color", + "theme-color-unread-notification-color": "Unread Notifications Color" } \ No newline at end of file diff --git a/packages/rocketchat-theme/server/variables.coffee b/packages/rocketchat-theme/server/variables.coffee old mode 100644 new mode 100755 index 2ffe15d83d93..e194e55da626 --- a/packages/rocketchat-theme/server/variables.coffee +++ b/packages/rocketchat-theme/server/variables.coffee @@ -5,6 +5,7 @@ RocketChat.theme.addPublicColor "tertiary-background-color", "#EAEAEA" RocketChat.theme.addPublicColor "primary-font-color", "#444444" RocketChat.theme.addPublicColor "secondary-font-color", "#7F7F7F" RocketChat.theme.addPublicColor "tertiary-font-color", "rgba(255, 255, 255, 0.6)" +RocketChat.theme.addPublicColor "quaternary-font-color", "#FFF" RocketChat.theme.addPublicColor "input-font-color", "rgba(255, 255, 255, 0.85)" RocketChat.theme.addPublicColor "link-font-color", "#008CE3" RocketChat.theme.addPublicColor "info-font-color", "#AAAAAA" @@ -20,3 +21,10 @@ RocketChat.theme.addPublicColor "code-border", "#CCC" RocketChat.theme.addPublicColor "code-color", "#333" RocketChat.theme.addPublicColor "blockquote-background", "#CCC" RocketChat.theme.addPublicColor "message-hover-background-color", "#f9f9f9" +RocketChat.theme.addPublicColor "active-channel-background-color", "rgba(255, 255, 255, 0.075)" +RocketChat.theme.addPublicColor "active-channel-font-color", "rgba(255, 255, 255, 0.75)" +RocketChat.theme.addPublicColor "custom-scrollbar-color", "rgba(255, 255, 255, 0.05)" +RocketChat.theme.addPublicColor "action-buttons-color", "#FFF" +RocketChat.theme.addPublicColor "clean-buttons-color", "rgba(0, 0, 0, 0.025)" +RocketChat.theme.addPublicColor "unread-notification-color", "#1dce73" + From cd9fbe6bce3199183b48da1e7c6f6007b68f3850 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Thu, 24 Dec 2015 16:24:55 -0200 Subject: [PATCH 094/103] Set user role in integration update too --- .../methods/incoming/updateIncomingIntegration.coffee | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/rocketchat-integrations/server/methods/incoming/updateIncomingIntegration.coffee b/packages/rocketchat-integrations/server/methods/incoming/updateIncomingIntegration.coffee index 25787a289875..da7aa3dd15f2 100644 --- a/packages/rocketchat-integrations/server/methods/incoming/updateIncomingIntegration.coffee +++ b/packages/rocketchat-integrations/server/methods/incoming/updateIncomingIntegration.coffee @@ -12,7 +12,8 @@ Meteor.methods if integration.channel[0] not in ['@', '#'] throw new Meteor.Error 'invalid_channel', '[methods] updateIncomingIntegration -> channel should start with # or @' - if not RocketChat.models.Integrations.findOne(integrationId)? + currentIntegration = RocketChat.models.Integrations.findOne(integrationId) + if not currentIntegration? throw new Meteor.Error 'invalid_integration', '[methods] updateIncomingIntegration -> integration not found' record = undefined @@ -36,6 +37,9 @@ Meteor.methods if record is undefined throw new Meteor.Error 'channel_does_not_exists', "[methods] updateIncomingIntegration -> The channel does not exists" + user = RocketChat.models.Users.findOne({username: currentIntegration.username}) + Roles.addUsersToRoles user._id, 'bot', 'bot' + RocketChat.models.Integrations.update integrationId, $set: name: integration.name From 08593fc635bbad6538394fc74b6d78fde669b67e Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Thu, 24 Dec 2015 16:25:24 -0200 Subject: [PATCH 095/103] Get integration name from body --- packages/rocketchat-integrations/server/api/api.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/rocketchat-integrations/server/api/api.coffee b/packages/rocketchat-integrations/server/api/api.coffee index f2d9e11873a1..f5da4bf07f48 100644 --- a/packages/rocketchat-integrations/server/api/api.coffee +++ b/packages/rocketchat-integrations/server/api/api.coffee @@ -130,7 +130,7 @@ Api.addRoute 'add/:integrationId/:userId/:token', authRequired: true, Meteor.call 'addOutgoingIntegration', username: 'rocket.cat' urls: [@bodyParams.target_url] - name: @bodyParams.data.name + name: @bodyParams.name channel: @bodyParams.data.channel_name triggerWords: @bodyParams.data.trigger_words @@ -141,7 +141,7 @@ Api.addRoute 'add/:integrationId/:userId/:token', authRequired: true, Meteor.call 'addOutgoingIntegration', username: 'rocket.cat' urls: [@bodyParams.target_url] - name: @bodyParams.data.name + name: @bodyParams.name channel: @bodyParams.data.username triggerWords: @bodyParams.data.trigger_words From 9699e552caf875579c1a1885e64bf008f132fa31 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Thu, 24 Dec 2015 16:37:37 -0200 Subject: [PATCH 096/103] Enforce data in body params --- packages/rocketchat-integrations/server/api/api.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/rocketchat-integrations/server/api/api.coffee b/packages/rocketchat-integrations/server/api/api.coffee index f5da4bf07f48..a7321099b93c 100644 --- a/packages/rocketchat-integrations/server/api/api.coffee +++ b/packages/rocketchat-integrations/server/api/api.coffee @@ -124,6 +124,8 @@ Api.addRoute 'add/:integrationId/:userId/:token', authRequired: true, Meteor.runAsUser user._id, => switch @bodyParams['event'] when 'newMessageOnChannel' + @bodyParams.data ?= {} + if @bodyParams.data.channel_name? and @bodyParams.data.channel_name.indexOf('#') is -1 @bodyParams.data.channel_name = '#' + @bodyParams.data.channel_name From f68d4cee761914e2365fa557040dc918dc95f433 Mon Sep 17 00:00:00 2001 From: Gabriel Engel Date: Thu, 24 Dec 2015 16:58:47 -0200 Subject: [PATCH 097/103] code formatting --- packages/rocketchat-theme/i18n/en.i18n.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/rocketchat-theme/i18n/en.i18n.json b/packages/rocketchat-theme/i18n/en.i18n.json index 464bbbb1ea38..10f2f83c6366 100755 --- a/packages/rocketchat-theme/i18n/en.i18n.json +++ b/packages/rocketchat-theme/i18n/en.i18n.json @@ -1,9 +1,14 @@ { + "theme-color-action-buttons-color" : "Actions Buttons Color", + "theme-color-active-channel-background-color" : "Active Channel Background Color", + "theme-color-active-channel-font-color" : "Active Channel Font Color", "theme-color-blockquote-background" : "Blockquote Background Color", + "theme-color-clean-buttons-color" : "Clean Buttons Color", "theme-color-code-background" : "Code Background Color", "theme-color-code-border" : "Code Border Color", "theme-color-code-color" : "Code Color", "theme-color-content-background-color" : "Content Background Color", + "theme-color-custom-scrollbar-color" : "Custom Scrollbar Color", "theme-color-info-active-font-color" : "Active Info Font Color", "theme-color-info-font-color" : "Info Font Color", "theme-color-input-font-color" : "Input Font Color", @@ -11,6 +16,7 @@ "theme-color-message-hover-background-color" : "Message Hover BG Color", "theme-color-primary-background-color" : "Primary Background Color", "theme-color-primary-font-color" : "Primary Font Color", + "theme-color-quaternary-font-color" : "Quaternary Font Color", "theme-color-secondary-background-color" : "Secondary Background Color", "theme-color-secondary-font-color" : "Secondary Font Color", "theme-color-smallprint-font-color" : "Small Print Font Color", @@ -21,11 +27,5 @@ "theme-color-status-online" : "Online Status Color", "theme-color-tertiary-background-color" : "Tertiary Background Color", "theme-color-tertiary-font-color" : "Tertiary Font Color", - "theme-color-quaternary-font-color": "Quaternary Font Color", - "theme-color-active-channel-background-color": "Active Channel Background Color", - "theme-color-active-channel-font-color": "Active Channel Font Color", - "theme-color-custom-scrollbar-color": "Custom Scrollbar Color", - "theme-color-action-buttons-color": "Actions Buttons Color", - "theme-color-clean-buttons-color": "Clean Buttons Color", - "theme-color-unread-notification-color": "Unread Notifications Color" -} \ No newline at end of file + "theme-color-unread-notification-color" : "Unread Notifications Color" +} From ee16950df53d1abc4d1a68b73f6c98d8e9b46eca Mon Sep 17 00:00:00 2001 From: Gabriel Engel Date: Thu, 24 Dec 2015 17:18:35 -0200 Subject: [PATCH 098/103] re order settings --- .../rocketchat-theme/server/variables.coffee | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/rocketchat-theme/server/variables.coffee b/packages/rocketchat-theme/server/variables.coffee index e194e55da626..ce01a462e00f 100755 --- a/packages/rocketchat-theme/server/variables.coffee +++ b/packages/rocketchat-theme/server/variables.coffee @@ -1,30 +1,30 @@ -RocketChat.theme.addPublicColor "content-background-color", "#FFF" RocketChat.theme.addPublicColor "primary-background-color", "#04436A" -RocketChat.theme.addPublicColor "secondary-background-color", "#F4F4F4" -RocketChat.theme.addPublicColor "tertiary-background-color", "#EAEAEA" RocketChat.theme.addPublicColor "primary-font-color", "#444444" +RocketChat.theme.addPublicColor "secondary-background-color", "#F4F4F4" RocketChat.theme.addPublicColor "secondary-font-color", "#7F7F7F" +RocketChat.theme.addPublicColor "tertiary-background-color", "#EAEAEA" RocketChat.theme.addPublicColor "tertiary-font-color", "rgba(255, 255, 255, 0.6)" RocketChat.theme.addPublicColor "quaternary-font-color", "#FFF" + +RocketChat.theme.addPublicColor "action-buttons-color", "#13679a" +RocketChat.theme.addPublicColor "active-channel-background-color", "rgba(255, 255, 255, 0.075)" +RocketChat.theme.addPublicColor "active-channel-font-color", "rgba(255, 255, 255, 0.75)" +RocketChat.theme.addPublicColor "blockquote-background", "#CCC" +RocketChat.theme.addPublicColor "clean-buttons-color", "rgba(0, 0, 0, 0.025)" +RocketChat.theme.addPublicColor "code-background", "#F8F8F8" +RocketChat.theme.addPublicColor "code-border", "#CCC" +RocketChat.theme.addPublicColor "code-color", "#333" +RocketChat.theme.addPublicColor "content-background-color", "#FFF" +RocketChat.theme.addPublicColor "custom-scrollbar-color", "rgba(255, 255, 255, 0.05)" +RocketChat.theme.addPublicColor "info-active-font-color", "#FF0000" +RocketChat.theme.addPublicColor "info-font-color", "#AAAAAA" RocketChat.theme.addPublicColor "input-font-color", "rgba(255, 255, 255, 0.85)" RocketChat.theme.addPublicColor "link-font-color", "#008CE3" -RocketChat.theme.addPublicColor "info-font-color", "#AAAAAA" -RocketChat.theme.addPublicColor "info-active-font-color", "#FF0000" +RocketChat.theme.addPublicColor "message-hover-background-color", "#f9f9f9" RocketChat.theme.addPublicColor "smallprint-font-color", "#C2E7FF" RocketChat.theme.addPublicColor "smallprint-hover-color", "#FFFFFF" -RocketChat.theme.addPublicColor "status-online", "#35AC19" -RocketChat.theme.addPublicColor "status-offline", "rgba(150, 150, 150, 0.50)" -RocketChat.theme.addPublicColor "status-busy", "#D30230" RocketChat.theme.addPublicColor "status-away", "#FCB316" -RocketChat.theme.addPublicColor "code-background", "#F8F8F8" -RocketChat.theme.addPublicColor "code-border", "#CCC" -RocketChat.theme.addPublicColor "code-color", "#333" -RocketChat.theme.addPublicColor "blockquote-background", "#CCC" -RocketChat.theme.addPublicColor "message-hover-background-color", "#f9f9f9" -RocketChat.theme.addPublicColor "active-channel-background-color", "rgba(255, 255, 255, 0.075)" -RocketChat.theme.addPublicColor "active-channel-font-color", "rgba(255, 255, 255, 0.75)" -RocketChat.theme.addPublicColor "custom-scrollbar-color", "rgba(255, 255, 255, 0.05)" -RocketChat.theme.addPublicColor "action-buttons-color", "#FFF" -RocketChat.theme.addPublicColor "clean-buttons-color", "rgba(0, 0, 0, 0.025)" +RocketChat.theme.addPublicColor "status-busy", "#D30230" +RocketChat.theme.addPublicColor "status-offline", "rgba(150, 150, 150, 0.50)" +RocketChat.theme.addPublicColor "status-online", "#35AC19" RocketChat.theme.addPublicColor "unread-notification-color", "#1dce73" - From 076d58af62f98ab6a509e981f771e0ede1b8b262 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Sat, 26 Dec 2015 14:39:04 -0200 Subject: [PATCH 099/103] Fix preview of images in mobile --- lib/fileUpload.coffee | 4 ++++ .../client/messageAttachment.coffee | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/fileUpload.coffee b/lib/fileUpload.coffee index cb84a73bab33..3ee0e68c276d 100644 --- a/lib/fileUpload.coffee +++ b/lib/fileUpload.coffee @@ -73,6 +73,10 @@ if UploadFS? uid = cookie.get('rc_uid', rawCookies) if rawCookies? token = cookie.get('rc_token', rawCookies) if rawCookies? + if not uid? + uid = req.query.rc_uid + token = req.query.rc_token + unless uid and token and RocketChat.models.Users.findOneByIdAndLoginToken(uid, token) res.writeHead 403 return false diff --git a/packages/rocketchat-message-attachments/client/messageAttachment.coffee b/packages/rocketchat-message-attachments/client/messageAttachment.coffee index a224b9a872fc..5cf3138934cf 100644 --- a/packages/rocketchat-message-attachments/client/messageAttachment.coffee +++ b/packages/rocketchat-message-attachments/client/messageAttachment.coffee @@ -1,7 +1,13 @@ Template.messageAttachment.helpers fixCordova: (url) -> if Meteor.isCordova and url?[0] is '/' - return Meteor.absoluteUrl().replace(/\/$/, '') + url + url = Meteor.absoluteUrl().replace(/\/$/, '') + url + query = "rc_uid=#{Meteor.userId()}&rc_token=#{Meteor._localStorage.getItem('Meteor.loginToken')}" + if url.indexOf('?') is -1 + url = url + '?' + query + else + url = url + '&' + query + return url showImage: -> From 0f3fa28662cc896dd43e246e52cc920ee1863439 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Sat, 26 Dec 2015 18:22:54 -0200 Subject: [PATCH 100/103] Do not load all settings to process.env --- packages/rocketchat-lib/server/functions/settings.coffee | 9 ++++++--- packages/rocketchat-lib/server/startup/settings.coffee | 8 ++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/rocketchat-lib/server/functions/settings.coffee b/packages/rocketchat-lib/server/functions/settings.coffee index 7cb1a13ab796..a0e48bade8a5 100644 --- a/packages/rocketchat-lib/server/functions/settings.coffee +++ b/packages/rocketchat-lib/server/functions/settings.coffee @@ -147,14 +147,17 @@ RocketChat.settings.init = -> RocketChat.models.Settings.find().observe added: (record) -> Meteor.settings[record._id] = record.value - process.env[record._id] = record.value + if record.env is true + process.env[record._id] = record.value RocketChat.settings.load record._id, record.value, initialLoad changed: (record) -> Meteor.settings[record._id] = record.value - process.env[record._id] = record.value + if record.env is true + process.env[record._id] = record.value RocketChat.settings.load record._id, record.value, initialLoad removed: (record) -> delete Meteor.settings[record._id] - delete process.env[record._id] + if record.env is true + delete process.env[record._id] RocketChat.settings.load record._id, undefined, initialLoad initialLoad = false diff --git a/packages/rocketchat-lib/server/startup/settings.coffee b/packages/rocketchat-lib/server/startup/settings.coffee index 0393c868e50d..aab77d73469c 100644 --- a/packages/rocketchat-lib/server/startup/settings.coffee +++ b/packages/rocketchat-lib/server/startup/settings.coffee @@ -91,10 +91,10 @@ RocketChat.settings.addGroup 'API', -> RocketChat.settings.addGroup 'SMTP', -> - @add 'SMTP_Host', '', { type: 'string' } - @add 'SMTP_Port', '', { type: 'string' } - @add 'SMTP_Username', '', { type: 'string' } - @add 'SMTP_Password', '', { type: 'string' } + @add 'SMTP_Host', '', { type: 'string', env: true } + @add 'SMTP_Port', '', { type: 'string', env: true } + @add 'SMTP_Username', '', { type: 'string', env: true } + @add 'SMTP_Password', '', { type: 'string', env: true } @add 'From_Email', '', { type: 'string', placeholder: 'email@domain' } @section 'Invitation', -> From ea95b08013c9dc5967a260d58f2fde370bc2ab3d Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Sat, 26 Dec 2015 18:25:41 -0200 Subject: [PATCH 101/103] Remove unecessary logs --- packages/rocketchat-file/file.server.coffee | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/rocketchat-file/file.server.coffee b/packages/rocketchat-file/file.server.coffee index 80b6e64bfc7f..b974aff0ba49 100644 --- a/packages/rocketchat-file/file.server.coffee +++ b/packages/rocketchat-file/file.server.coffee @@ -21,26 +21,19 @@ RocketChatFile = detectGM = -> - console.log 'GM: Getting GraphicsMagick version' exec 'gm version', Meteor.bindEnvironment (error, stdout, stderr) -> - console.log 'GM: GraphicsMagick', arguments if not error? and stdout.indexOf('GraphicsMagick') > -1 - console.log 'GM: GraphicsMagick installed' RocketChatFile.enable() RocketChat.Info.GraphicsMagick = enabled: true version: stdout else - console.log 'GM: GraphicsMagick not installed' RocketChat.Info.GraphicsMagick = enabled: false - console.log 'GM: Getting ImageMagick version' exec 'convert -version', Meteor.bindEnvironment (error, stdout, stderr) -> - console.log 'GM: ImageMagick', arguments if not error? and stdout.indexOf('ImageMagick') > -1 - console.log 'GM: ImageMagick installed' if RocketChatFile.enabled isnt true # Enable GM to work with ImageMagick if no GraphicsMagick RocketChatFile.gm = RocketChatFile.gm.subClass({imageMagick: true}) @@ -50,7 +43,6 @@ detectGM = -> enabled: true version: stdout else - console.log 'GM: ImageMagick not installed' if RocketChatFile.enabled isnt true RocketChatFile.disable() From decaf1305ad71234038d4e6e1e041e35006db9ea Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Mon, 28 Dec 2015 09:16:31 -0200 Subject: [PATCH 102/103] using branding image from main app --- .../app/client/views/messages.html | 2 +- .../app/public/logo-dark.svg | 77 ------------------- 2 files changed, 1 insertion(+), 78 deletions(-) delete mode 100644 packages/rocketchat-livechat/app/public/logo-dark.svg diff --git a/packages/rocketchat-livechat/app/client/views/messages.html b/packages/rocketchat-livechat/app/client/views/messages.html index 09a6658f0a72..8e3fe168b7d5 100644 --- a/packages/rocketchat-livechat/app/client/views/messages.html +++ b/packages/rocketchat-livechat/app/client/views/messages.html @@ -22,7 +22,7 @@

    Powered by - +

    diff --git a/packages/rocketchat-livechat/app/public/logo-dark.svg b/packages/rocketchat-livechat/app/public/logo-dark.svg deleted file mode 100644 index 4f6fa55412cd..000000000000 --- a/packages/rocketchat-livechat/app/public/logo-dark.svg +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 8f3576fbd647ed9168658d3006e3b815a512b99d Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Mon, 28 Dec 2015 10:21:28 -0200 Subject: [PATCH 103/103] Tokenize message on message render to prevent re processing --- packages/rocketchat-highlight/highlight.coffee | 11 ++++++++++- packages/rocketchat-markdown/markdown.coffee | 17 ++++++++++++++--- .../message/message.coffee | 4 ++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/packages/rocketchat-highlight/highlight.coffee b/packages/rocketchat-highlight/highlight.coffee index c98270151ae1..57944340bcdd 100644 --- a/packages/rocketchat-highlight/highlight.coffee +++ b/packages/rocketchat-highlight/highlight.coffee @@ -8,6 +8,7 @@ class Highlight constructor: (message) -> if s.trim message.html + message.tokens ?= [] # Count occurencies of ``` count = (message.html.match(/```/g) || []).length @@ -40,7 +41,15 @@ class Highlight result = hljs.highlightAuto code else result = hljs.highlight lang, code - msgParts[index] = "
    ```
    " + result.value + "
    ```
    " + + token = "$#{Random.id()}$" + + message.tokens.push + highlight: true + token: token + text: "
    ```
    " + result.value + "
    ```
    " + + msgParts[index] = token else msgParts[index] = part diff --git a/packages/rocketchat-markdown/markdown.coffee b/packages/rocketchat-markdown/markdown.coffee index c578fec71605..f33c817e5273 100644 --- a/packages/rocketchat-markdown/markdown.coffee +++ b/packages/rocketchat-markdown/markdown.coffee @@ -13,6 +13,20 @@ class Markdown else return message + # Support `text` + if _.isString message + msg = msg.replace(/(^|>|[ >_*~])\`([^`\r\n]+)\`([<_*~]|\B|\b|$)/gm, '$1`$2`$3') + else + message.tokens ?= [] + msg = msg.replace /(^|>|[ >_*~])\`([^`\r\n]+)\`([<_*~]|\B|\b|$)/gm, (match, p1, p2, p3, offset, text) -> + token = "$#{Random.id()}$" + + message.tokens.push + token: token + text: "#{p1}`#{p2}`#{p3}" + + return token + # Support ![alt text](http://image url) msg = msg.replace(/!\[([^\]]+)\]\((https?:\/\/[^\)]+)\)/gm, '
    ') @@ -35,9 +49,6 @@ class Markdown # Support # Text for h4 msg = msg.replace(/^#### (([\w\d-_\/\*\.,\\] ?)+)/gm, '

    $1

    ') - # Support `text` - msg = msg.replace(/(^|>|[ >_*~])\`([^`\r\n]+)\`([<_*~]|\B|\b|$)/gm, '$1`$2`$3') - # Support *text* to make bold msg = msg.replace(/(^|>|[ >_~`])\*{1,2}([^\*\r\n]+)\*{1,2}([<_~`]|\B|\b|$)/gm, '$1*$2*$3') diff --git a/packages/rocketchat-ui-message/message/message.coffee b/packages/rocketchat-ui-message/message/message.coffee index 7d9bcffbe281..dff309fa1fbb 100644 --- a/packages/rocketchat-ui-message/message/message.coffee +++ b/packages/rocketchat-ui-message/message/message.coffee @@ -102,6 +102,10 @@ Template.message.onCreated -> msg.html = _.escapeHTML msg.html message = RocketChat.callbacks.run 'renderMessage', msg + if message.tokens?.length > 0 + for token in message.tokens + message.html = message.html.replace token.token, token.text + # console.log JSON.stringify message msg.html = message.html.replace /\n/gm, '
    ' return msg.html