-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NEW] Subgroups #8873
[NEW] Subgroups #8873
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,8 +58,34 @@ Meteor.methods({ | |
method: 'addUsersToRoom' | ||
}); | ||
} | ||
if (room.subGroup) { | ||
let originalSub = RocketChat.models.Subscriptions.findOne({ | ||
'rid': room.originalRoomId, | ||
'u.username': username | ||
}); | ||
if (!originalSub) { | ||
throw new Meteor.Error('User_must_be_in_parent_room', 'User must be in parent room', { | ||
method: 'addUserToRoom' | ||
}); | ||
} | ||
} | ||
|
||
RocketChat.addUserToRoom(data.rid, newUser, user); | ||
|
||
if (room.subGroup) { | ||
let sub = RocketChat.models.Subscriptions.update({ | ||
'rid': data.rid | ||
}, | ||
{ | ||
$set: | ||
{ | ||
'subGroup': true, | ||
'subGroupName': room.subGroupName, | ||
'originalRoomId': room.originalRoomId | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. which property shall be used to form the hierarchy - or whether a hierarchy shall exist after all and not only some sort of "tagging" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, it was interesting to know whether the subroom is just a room within a room or whether it is started from a message (which actually made it a thread) |
||
} | ||
}, | ||
{ multi: true }); | ||
} | ||
}); | ||
|
||
return true; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<template name="subGroups"> | ||
<div class="flex-tab__header"> | ||
<div class="list-view animated"> | ||
<div class="title"> | ||
<h2>{{_ "Create_Subgroup"}}</h2> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="flex-tab__result"> | ||
<div class="search-form"> | ||
<div class="input-line"> | ||
<input type="text" id="group-name" class="content-background-color" placeholder="{{_ "Subgroup_name"}}" /> | ||
</div> | ||
<div class="input-line"> | ||
<input type="text" id="topic" class="content-background-color" placeholder="{{_ "Subgroup_topic"}}" /> | ||
</div> | ||
<div class="input-line"> | ||
<input type="text" id="description" class="content-background-color" placeholder="{{_ "Subgroup_description"}}" /> | ||
</div> | ||
<nav> | ||
<button class='button primary create-group'><span>{{_ "Create_Subgroup"}}</span></button> | ||
</nav> | ||
</div> | ||
</div> | ||
</template> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import toastr from 'toastr'; | ||
|
||
Template.subGroups.events({ | ||
'click .create-group': function() { | ||
|
||
let groupName = $('#group-name').val().trim(); | ||
let groupTopic = $('#topic').val().trim(); | ||
let groupDescription = $('#description').val().trim(); | ||
|
||
if (groupName.length === 0) { | ||
return toastr.warning("Please enter a subgroup name"); | ||
} else { | ||
Meteor.call('createSubGroup', groupName, groupTopic, groupDescription, Session.get('openedRoom'), Meteor.user(), (err, resp) => { | ||
if (!err) { | ||
$('#group-name').val(''); | ||
$('#topic').val(''); | ||
$('#description').val(''); | ||
toastr.success("Subgroup Created!"); | ||
return FlowRouter.go("/group/" + resp + "/"); | ||
} else { | ||
if (err.error === 'error-duplicate-channel-name') { | ||
return toastr.warning("This group name already exists"); | ||
} else if (err.error === 'error-subgroup-must-join-group-first') { | ||
return toastr.warning("You must join this channel first"); | ||
} else if (err.error === 'error-subgroup-no-nested-subgroups') { | ||
return toastr.warning("You cannot create a group from a group"); | ||
} else if (err.error === 'error-invalid-name') { | ||
return toastr.warning("Group names can only contain letters, numbers, hyphens, and underscores (no spaces)"); | ||
} else { | ||
return toastr.error("Something went wrong"); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Meteor.startup(function() { | ||
return Tracker.autorun(function() { | ||
if (RocketChat.settings.get('Enable_Subgroups')) { | ||
RocketChat.TabBar.addButton({ | ||
groups: ['channel', 'group'], | ||
id: 'subGroups', | ||
i18nTitle: 'Create_Subgroup', | ||
template: 'subGroups', | ||
order: 3, | ||
subGroups: true | ||
}); | ||
} else { | ||
RocketChat.TabBar.removeButton('subGroups'); | ||
} | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Package.describe({ | ||
name: 'rocketchat:subgroups', | ||
version: '0.0.1', | ||
summary: 'Channel subgroups', | ||
git: '' | ||
}); | ||
|
||
Package.onUse(function(api) { | ||
api.use([ | ||
'mongo', | ||
'jquery', | ||
'templating', | ||
'ecmascript', | ||
'rocketchat:lib' | ||
]); | ||
|
||
api.addFiles([ | ||
'client/subGroup.html', | ||
'client/subGroup.js', | ||
'client/tabBar.js' | ||
], 'client'); | ||
|
||
api.addFiles([ | ||
'server/createSubGroup.js', | ||
'server/settings.js', | ||
'server/hasSubGroups.js' | ||
], 'server') | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
Meteor.methods({ | ||
createSubGroup: function(groupName, groupTopic, groupDescription, roomId, user) { | ||
|
||
let username = user.username; | ||
let currentRoom = RocketChat.models.Rooms.findOneById(roomId); | ||
let currentName = currentRoom.name; | ||
let currentSub = RocketChat.models.Subscriptions.findOne({'rid': roomId, 'u.username': username}); | ||
let nameValidation; | ||
|
||
try { | ||
nameValidation = new RegExp('^' + RocketChat.settings.get('UTF8_Names_Validation') + '$'); | ||
} catch (error) { | ||
nameValidation = new RegExp('^[0-9a-zA-Z-_.]+$'); | ||
} | ||
|
||
if (!nameValidation.test(groupName)) { | ||
throw new Meteor.Error('error-invalid-name', 'Invalid name', { function: 'Meteor.createSubGroup' }); | ||
} | ||
|
||
if (!currentRoom || !currentSub) { | ||
throw new Meteor.Error('error-subgroup-must-join-group-first', 'Must join a channel before creating a subgroup', { function: 'createSubGroup' }); | ||
} | ||
|
||
if (currentSub.subGroup) { | ||
throw new Meteor.Error('error-subgroup-no-nested-subgroups', 'You cannot create a subgroup of a subgroup', { function: 'createSubGroup' }); | ||
} | ||
|
||
let newName = `${currentName}_${groupName}` | ||
let newRoom = RocketChat.createRoom('p', newName, username, [username]); | ||
|
||
// update new room | ||
RocketChat.models.Rooms.update({ | ||
'_id': newRoom.rid | ||
}, { | ||
$set: { | ||
'subGroup': true, | ||
'topic': groupTopic, | ||
'description': groupDescription, | ||
'subGroupName': groupName, | ||
'originalRoomId': roomId | ||
} | ||
}); | ||
|
||
// update the owner's subscriptions | ||
RocketChat.models.Subscriptions.update({ | ||
'rid': newRoom.rid | ||
}, { | ||
$set: { | ||
'subGroup': true, | ||
'subGroupName': groupName, | ||
'originalRoomId': roomId | ||
} | ||
}); | ||
|
||
return RocketChat.models.Rooms.findOne({'_id': newRoom.rid}).name; | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Meteor.methods({ | ||
hasSubGroups(rid) { | ||
if (!rid) { | ||
return false; | ||
} | ||
const subs = RocketChat.models.Rooms.find({ | ||
'originalRoomId': rid | ||
}).count(); | ||
return subs; | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
RocketChat.settings.addGroup('General', function() { | ||
this.section('Subgroups', function() { | ||
this.add('Enable_Subgroups', false, { type: 'boolean', public: true }); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was e. g. interesting to know whether the thread will be a separate room type or remain in the same type as the parent