Skip to content

Commit

Permalink
getchannels: add onlyJoined param
Browse files Browse the repository at this point in the history
  • Loading branch information
cblgh committed Dec 11, 2021
1 parent 16c3a2a commit 1bb9d3d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/cabal-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,12 @@ class CabalDetails extends EventEmitter {
* @param {object} [opts]
* @property {boolean} includeArchived - Determines whether to include archived channels or not. Defaults to false.
* @property {boolean} includePM - Determines whether to include private message channels or not. Defaults to false.
* @property {boolean} onlyJoined - Determines whether to limit returned channels to only those that are joined or not. Defaults to false.
* @returns {string[]} a list of all the channels in this cabal. Does not return channels with 0 members.
*/
getChannels (opts) {
if (!opts || typeof opts !== "object" || opts[Symbol.iterator]) {
opts = { includeArchived: false, includePM: false }
opts = { includeArchived: false, includePM: false, onlyJoined: false}
}
// sort regular channels and PMs separately, then concat them together (if including PM) before returning
const sortedChannels = Object.keys(this.channels)
Expand All @@ -330,6 +331,7 @@ class CabalDetails extends EventEmitter {
&& this.channels[ch].members.size > 0
&& (!this.channels[ch].isPrivate)
&& (opts.includeArchived || !this.channels[ch].archived)
&& (!opts.onlyJoined || opts.onlyJoined && this.channels[ch].joined)
)
.sort()
// get all PMs with non-hidden users && sort them
Expand Down
1 change: 1 addition & 0 deletions src/channel-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ class PMChannelDetails extends ChannelDetails {
this.recipient = pubkey
this.isPrivate = true
this.topic = "private message with " + pubkey
this.joined = true
this.members.add(this.recipientKey) // makes sure # members > 0 :)
}

Expand Down

0 comments on commit 1bb9d3d

Please sign in to comment.