Skip to content
Snippets Groups Projects
Commit 270eee4c authored by Marcelo Schmidt's avatar Marcelo Schmidt
Browse files

Change room type

parent 278fb134
No related branches found
No related tags found
No related merge requests found
Template.channelSettings.helpers Template.channelSettings.helpers
notDirect: -> notDirect: ->
return ChatRoom.findOne(@rid).t isnt 'd' return ChatRoom.findOne(@rid)?.t isnt 'd'
roomType: -> roomType: ->
return ChatRoom.findOne(@rid).t return ChatRoom.findOne(@rid)?.t
Template.channelSettings.onCreated -> Template.channelSettings.events
'click .save': (e, t) ->
e.preventDefault()
settings =
roomType: t.$('input[name=roomType]:checked').val()
Meteor.call 'saveRoomSettings', t.data.rid, settings, (err, results) ->
return toastr.error err.reason if err
toastr.success TAPi18n.__ 'Settings_updated'
\ No newline at end of file
...@@ -22,6 +22,11 @@ Package.onUse(function(api) { ...@@ -22,6 +22,11 @@ Package.onUse(function(api) {
'client/stylesheets/channel-settings.less', 'client/stylesheets/channel-settings.less',
], 'client'); ], 'client');
api.addFiles([
'server/functions/changeRoomType.coffee',
'server/methods/saveRoomSettings.coffee'
], 'server');
// TAPi18n // TAPi18n
var _ = Npm.require('underscore'); var _ = Npm.require('underscore');
var fs = Npm.require('fs'); var fs = Npm.require('fs');
......
RocketChat.changeRoomType = (rid, roomType) ->
console.log '[function] RocketChat.changeRoomType'.green, rid, roomType
unless Match.test rid, String
throw new Meteor.Error 'invalid-rid'
if roomType not in ['c', 'p']
throw new Meteor.Error 'invalid-room-type'
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
Meteor.methods
saveRoomSettings: (rid, settings) ->
console.log '[method] saveRoomSettings'.green, rid, settings
unless Match.test rid, String
throw new Meteor.Error 'invalid-rid'
unless Match.test settings, Match.ObjectIncluding { roomType: String }
throw new Meteor.Error 'invalid-settings'
unless RocketChat.authz.hasPermission(Meteor.userId(), 'edit-room', rid)
throw new Meteor.Error 503, 'Not authorized'
room = RocketChat.models.Rooms.findOneById rid
if room?
if settings.roomType isnt room.t
RocketChat.changeRoomType(rid, settings.roomType)
return true
\ No newline at end of file
...@@ -290,6 +290,16 @@ RocketChat.models.Rooms = new class extends RocketChat.models._Base ...@@ -290,6 +290,16 @@ RocketChat.models.Rooms = new class extends RocketChat.models._Base
return @update query, update return @update query, update
setTypeById: (_id, type) ->
query =
_id: _id
update =
$set:
t: type
return @update query, update
# INSERT # INSERT
createWithTypeNameUserAndUsernames: (type, name, user, usernames, extraData) -> createWithTypeNameUserAndUsernames: (type, name, user, usernames, extraData) ->
......
...@@ -194,6 +194,16 @@ RocketChat.models.Subscriptions = new class extends RocketChat.models._Base ...@@ -194,6 +194,16 @@ RocketChat.models.Subscriptions = new class extends RocketChat.models._Base
return @update query, update, { multi: true } return @update query, update, { multi: true }
updateTypeByRoomId: (roomId, type) ->
query =
rid: roomId
update =
$set:
t: type
return @update query, update, { multi: true }
# INSERT # INSERT
createWithRoomAndUser: (room, user, extraData) -> createWithRoomAndUser: (room, user, extraData) ->
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment