forked from RocketChat/Rocket.Chat
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes RocketChat#892 Closes RocketChat#7488 Fire global event for Load More during scroll
- Loading branch information
Daniel Schreiber
committed
Jul 30, 2017
1 parent
485b623
commit fb50b3e
Showing
16 changed files
with
138 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 10 additions & 24 deletions
34
packages/rocketchat-channel-settings/server/functions/saveRoomName.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,21 @@ | ||
|
||
RocketChat.saveRoomName = function(rid, name, user, sendMessage = true) { | ||
RocketChat.saveRoomName = function(rid, displayName, user, sendMessage = true) { | ||
const room = RocketChat.models.Rooms.findOneById(rid); | ||
if (room.t !== 'c' && room.t !== 'p') { | ||
throw new Meteor.Error('error-not-allowed', 'Not allowed', { | ||
'function': 'RocketChat.saveRoomName' | ||
'function': 'RocketChat.saveRoomdisplayName' | ||
}); | ||
} | ||
let nameValidation; | ||
try { | ||
nameValidation = new RegExp(`^${ RocketChat.settings.get('UTF8_Names_Validation') }$`); | ||
} catch (error) { | ||
nameValidation = new RegExp('^[0-9a-zA-Z-_.]+$'); | ||
} | ||
if (!nameValidation.test(name)) { | ||
throw new Meteor.Error('error-invalid-room-name', `${ name } is not a valid room name. Use only letters, numbers, hyphens and underscores`, { | ||
'function': 'RocketChat.saveRoomName', | ||
room_name: name | ||
}); | ||
} | ||
if (name === room.name) { | ||
if (displayName === room.name) { | ||
return; | ||
} | ||
if (RocketChat.models.Rooms.findOneByName(name)) { | ||
throw new Meteor.Error('error-duplicate-channel-name', `A channel with name '${ name }' exists`, { | ||
'function': 'RocketChat.saveRoomName', | ||
channel_name: name | ||
}); | ||
} | ||
const update = RocketChat.models.Rooms.setNameById(rid, name) && RocketChat.models.Subscriptions.updateNameAndAlertByRoomId(rid, name); | ||
|
||
const slugifiedRoomName = RocketChat.getValidRoomName(displayName, rid); | ||
|
||
const update = RocketChat.models.Rooms.setNameById(rid, slugifiedRoomName, displayName) && RocketChat.models.Subscriptions.updateNameAndAlertByRoomId(rid, slugifiedRoomName, displayName); | ||
|
||
if (update && sendMessage) { | ||
RocketChat.models.Messages.createRoomRenamedWithRoomIdRoomNameAndUser(rid, name, user); | ||
RocketChat.models.Messages.createRoomRenamedWithRoomIdRoomNameAndUser(rid, displayName, user); | ||
} | ||
return name; | ||
return displayName; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
RocketChat.getValidRoomName = function getValidRoomName(displayName, rid = '') { | ||
let slugifiedName = displayName; | ||
|
||
if (RocketChat.settings.get('UI_Allow_room_names_with_special_chars')) { | ||
const room = RocketChat.models.Rooms.findOneByDisplayName(displayName); | ||
if (room && room._id !== rid) { | ||
if (room.archived) { | ||
throw new Meteor.Error('error-archived-duplicate-name', `There's an archived channel with name ${ displayName }`, { function: 'RocketChat.getValidRoomName', channel_name: displayName }); | ||
} else { | ||
throw new Meteor.Error('error-duplicate-channel-name', `A channel with name '${ displayName }' exists`, { function: 'RocketChat.getValidRoomName', channel_name: displayName }); | ||
} | ||
} | ||
slugifiedName = s.slugify(displayName); | ||
} | ||
|
||
let nameValidation; | ||
try { | ||
nameValidation = new RegExp(`^${ RocketChat.settings.get('UTF8_Names_Validation') }$`); | ||
} catch (error) { | ||
nameValidation = new RegExp('^[0-9a-zA-Z-_.]+$'); | ||
} | ||
if (!nameValidation.test(slugifiedName)) { | ||
throw new Meteor.Error('error-invalid-room-name', `${ slugifiedName } is not a valid room name.`, { | ||
'function': 'RocketChat.getValidRoomName', | ||
channel_name: slugifiedName | ||
}); | ||
} | ||
|
||
const room = RocketChat.models.Rooms.findOneByName(slugifiedName); | ||
if (room && room._id !== rid) { | ||
if (RocketChat.settings.get('UI_Allow_room_names_with_special_chars')) { | ||
let tmpName = slugifiedName; | ||
let next = 0; | ||
while (RocketChat.models.Rooms.findOneByNameAndNotId(tmpName, rid)) { | ||
tmpName = `${ slugifiedName }-${ ++next }`; | ||
} | ||
slugifiedName = tmpName; | ||
} else if (room.archived) { | ||
throw new Meteor.Error('error-archived-duplicate-name', `There's an archived channel with name ${ slugifiedName }`, { function: 'RocketChat.getValidRoomName', channel_name: slugifiedName }); | ||
} else { | ||
throw new Meteor.Error('error-duplicate-channel-name', `A channel with name '${ slugifiedName }' exists`, { function: 'RocketChat.getValidRoomName', channel_name: slugifiedName }); | ||
} | ||
} | ||
|
||
return slugifiedName; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.