Skip to content
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

Add publish file method #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
29 changes: 29 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ Returns a string path of where all of the cabals are stored on the hard drive.
* [CabalDetails](#CabalDetails)
* [new CabalDetails(cabal, done)](#new_CabalDetails_new)
* [.publishMessage(msg, [opts], [cb])](#CabalDetails+publishMessage)
* [.publishFile(msg, [opts], [cb])](#CabalDetails+publishFile)
* [.publishNick(nick, [cb])](#CabalDetails+publishNick)
* [.publishChannelTopic([channel], topic, cb)](#CabalDetails+publishChannelTopic)
* [.getTopic([channel])](#CabalDetails+getTopic) ⇒ <code>string</code>
Expand Down Expand Up @@ -478,6 +479,34 @@ cabalDetails.publishMessage({

* * *


<a name="CabalDetails+publishFile"></a>

### cabalDetails.publishFile(msg, [opts], [cb])
Publish a File up to consumer. See
[`cabal-core`](https://github.com/cabal-club/cabal-core/)
for the full list of options.

**Params**

- msg <code>object</code> - the full message objectmessage containing file info
- *opts* <code>object</code> - options passed down to cabal.publish
- *cb* <code>function</code> - callback function called when message is published

**Example**
```js
cabalDetails.publishMessage({
type: 'chat/files',
content: {
datKey: 'key'
filename: 'hello world',
channel: 'cabal-dev'
}
})
```

* * *

<a name="CabalDetails+publishNick"></a>

### cabalDetails.publishNick(nick, [cb])
Expand Down
21 changes: 21 additions & 0 deletions src/cabal-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,27 @@ class CabalDetails extends EventEmitter {
this._emitUpdate()
}


/**
*
* @param {object} msg the full message
* @param {function} [opts] options for cabal.publish
* @param {function} [cb] callback
*/
publishFile (msg, opts, cb) {
if (!cb) {
cb = noop
}
if (!msg.content.channel) {
msg.content.channel = this.chname
}
if (!msg.type) msg.type = 'chat/file';
this._cabal.publish(msg, opts, (err, m) => {
this._emitUpdate()
cb(err, m)
})
}

/**
* Publish a new channel topic to `channel`.
* @param {string} [channel=this.chname]
Expand Down