mongodb-discuss
This is a simple small module which implements the core features of a forum or discussion list. This is intended to be the backend that drives a few different apps (discussions list, tasks management etc).
If you are looking for a full fledged bulletin-board functionality, I recommend looking at NodeBB. This module is meant to be simple enough to embed in other locations but also change to suit any specific needs and as such is not meant to be a complete product.
Install
npm install mongodb-disucc
Initialization
var discuss = require('mongodb-discuss')({mongoUrl: 'mongodb://user:password@host:port/database'});
API
This document is a work in progress. The unit tests cover bulk of the functionality and are probably easy enough to read at this point.
All APIs are of the following form:
discuss.method(userId, params, done);
- userId is expected to be the ID of the caller and should always be present.
- params is expected to be an object giving the parameters. This is sanitized for mongodb-injection type security issues.
- done is a regular Node-style callback to report errors as well as the JSON response.
As such, the APIs are modeled to be fairly simple to expose directly to a browser-based client for example -- with the caveat that no authorization or authentication is done by the module and that is left to the caller.
createTopic
All interactions with topics start from creating a topic.
var params = {
subject: "This is the subject of the topic",
body: "This is the body of the topic",
subscriberIds: ["A list of userIds who should be subscribed to this from day one"],
altTopicId: "An alternate ID to record with this topic; cf. findTopicIdFromAltId"
};
discuss.createTopic(creatorUserId, params, function (err, result) {
});
discuss.once('newTopic', function (topic) {
getSubscriptionState and setSubscriptionState
These methods allow a given user to figure out if (s)he is subscribed to a given topic.
discuss.getSubscriptionState(userId, {topicId: topicId}, function (err, result) {
if (!result.isSubscribed) {
discuss.setSubscriptionState(userId, {topicId: topicId, isSubscribed: true}, function (err) {
});
}
});
postMessage
This allows a user to post a message. Note that it possible to subscribe more people to the topic at this time and also note that a user who posts is automatically added to the list of subscribers.
discuss.postMessage(userId, {topicId: topicId, body: body, subscriberIds: newSubscriberIds}, function (err) {
});
discuss.on('mail', function (info) {
});
getRecentTopics
This fetches all recent topics on the system or all topics created by the current user.
var params = {type: 'all'};
discuss.getRecentTopics(userId, params, done);
getAllTopicDetails
This fetches all subscribers and messages for a topic.
discuss.getAllTopicDetails(userId, {topicId: topicId}, function (err, info) {
});
Not yet implemented
- Emoji
- Attachments
- Likes
- Tags