Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions lib/models/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const Team = require('../models/team')
const slack = require('slack')
const bluebird = require('bluebird')
const groups = bluebird.promisifyAll(slack.groups)

module.exports.get = function (team, filter) {
filter = filter || /.*/
Expand All @@ -13,17 +12,34 @@ module.exports.get = function (team, filter) {
} else {
teamP = bluebird.resolve(team)
}
return teamP.then(team => {

return teamP.then(async team => {
const token = team.bot.bot_access_token
return groups.listAsync({
// note: not paginated

const conversations = await slack.conversations.list({
token,
exclude_archived: 1
}).then(res => (
res.groups.filter(g => (
(g.name.match(filter) || `#${g.name}`.match(filter) || g.purpose.value.match(filter)) &&
!g.name.match(/^admin/i) &&
!g.purpose.value.match(/\[secret\]/gi)
))
))
exclude_archived: 1,
types: 'private_channel'
});

const channels = conversations.channels.filter(g => (
(g.name.match(filter) || `#${g.name}`.match(filter) || g.purpose.value.match(filter)) &&
!g.name.match(/^admin/i) &&
!g.purpose.value.match(/\[secret\]/gi)
));

const memberPopulatedChannelsP = await channels.map(async (g) => {
// note: not paginated
const res = await slack.conversations.members({
token,
channel: g.id
});

g.members = res.members;
return g;
});

return Promise.all(memberPopulatedChannelsP);
})
}
Loading