Skip to content

Commit

Permalink
[Bubble] #27312 Add parameter boolWithHistory in API createBubble to …
Browse files Browse the repository at this point in the history
…offer or not full history for newcomers
  • Loading branch information
oanguenot committed May 19, 2017
1 parent 637dcdb commit 4c2ea12
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,6 @@
"location": "start"
}
],
"vars-on-top": 0,
"vars-on-top": 0
}
}
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Here is the list of the changes and features provided by the **Rainbow-Node-SDK*

- [Contact] Switch to new get contacts API (Privacy concerns) - Internal change

- [Bubble] #27312 Add parameter boolWithHistory in API createBubble to offer or not full history for newcomers

### v0.10.13

- [Contact] Methods **getContactByJid()**, **getContactById()** or **getContactByLoginEmail()** are now Promise based functions.
Expand Down
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ $ npm install --save rainbow-node-sdk
## Usage

```js
var RainbowSDK = require('rainbow-node-sdk');
let RainbowSDK = require('rainbow-node-sdk');

// instantiate the SDK
var rainbowSDK = new RainbowSDK(options);
let rainbowSDK = new RainbowSDK(options);

// start the SDK
rainbowSDK.start();
Expand All @@ -61,7 +61,7 @@ The `options` parameter allows to enter your credentials and to target the Rainb

```js
// Define your configuration
var options = {
let options = {
rainbow: {
host: "sandbox", // can be "sandbox" (developer platform), "official" or any other hostname when using dedicated AIO
},
Expand Down Expand Up @@ -220,7 +220,7 @@ Once connected, the Rainbow SDK will automatically retrieve the list of contacts
...
rainbowSDK.events.on('rainbow_onconnectionok', function() {
// do something when the connection to Rainbow is up
var contacts = rainbowSDK.contacts.getAll();
let contacts = rainbowSDK.contacts.getAll();
});
```

Expand Down Expand Up @@ -253,8 +253,8 @@ When the presence of a contact changes, the following event is fired:
...
rainbowSDK.events.on('rainbow_oncontactpresencechanged', function(contact) {
// do something when the presence of a contact changes
var presence = contact.presence; // Presence information
var status = contact.status; // Additionnal information if exists
let presence = contact.presence; // Presence information
let status = contact.status; // Additionnal information if exists
});
```

Expand Down Expand Up @@ -316,7 +316,7 @@ Once connected, the Rainbow SDK will automatically retrieve the list of bubbles
...
rainbowSDK.events.on('rainbow_onconnectionok', function() {
// do something when the connection to Rainbow is up
var bubbles = rainbowSDK.bubbles.getAll();
let bubbles = rainbowSDK.bubbles.getAll();
});
```

Expand All @@ -330,7 +330,7 @@ Accessing individually an existing bubble can be done using the API `getBubbleBy
```js
...
// Retrieve the bubble information when receiving a message in that bubble
var bubble = rainbowSDK.bubbles.getBubbleByJid(message.fromBubbleJid);
let bubble = rainbowSDK.bubbles.getBubbleByJid(message.fromBubbleJid);
});
```

Expand All @@ -341,7 +341,8 @@ A new bubble can be created by calling the following API

```js
...
rainbowSDK.bubbles.createBubble("My new Bubble", "A little description of my bubble").then(function(bubble) {
let withHistory = true // Allow newcomers to have access to the bubble messages since the creation of the bubble
rainbowSDK.bubbles.createBubble("My new Bubble", "A little description of my bubble", withHistory).then(function(bubble) {
// do something with the bubble created
...
}).catch(function(err) {
Expand All @@ -358,9 +359,9 @@ Once you have created a bubble, you can invite a contact. Insert the following c
```js
...

var invitedAsModerator = false; // To set to true if you want to invite someone as a moderator
var sendAnInvite = true; // To set to false if you want to add someone to a bubble without having to invite him first
var inviteReason = "bot-invite"; // Define a reason for the invite (part of the invite received by the recipient)
let invitedAsModerator = false; // To set to true if you want to invite someone as a moderator
let sendAnInvite = true; // To set to false if you want to add someone to a bubble without having to invite him first
let inviteReason = "bot-invite"; // Define a reason for the invite (part of the invite received by the recipient)

rainbowSDK.bubbles.inviteContactToBubble(aContact, aBubble, invitedAsModerator, sendAnInvite, inviteReason).then(function(bubbleUpdated) {
// do something with the invite sent
Expand Down
13 changes: 11 additions & 2 deletions lib/connection/RESTService.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,23 @@ class RESTService {
});
}

createBubble(name, description) {
createBubble(name, description, withHistory) {
var that = this;

return new Promise(function(resolve, reject) {

that.logger.log("debug", LOG_ID + "(createBubble) _entering_");

that.http.post("/api/rainbow/enduser/v1.0/rooms", getRequestHeader(), { name: name, topic: description } ).then(function(json) {
let history = "none";
if (withHistory) {
history = "all";
}

that.http.post("/api/rainbow/enduser/v1.0/rooms", getRequestHeader(), {
name: name,
topic: description,
history: history }
).then(function(json) {
that.logger.log("info", LOG_ID + "(createBubble) successfull");
that.logger.log("info", LOG_ID + "(createBubble) REST bubble created", json.data);
that.logger.log("debug", LOG_ID + "(createBubble) _exiting_");
Expand Down
13 changes: 8 additions & 5 deletions lib/services/Bubbles.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,22 @@ class Bubbles {
* @method createBubble
* @param {string} strName The name of the bubble to create
* @param {string} strDescription The description of the bubble to create
* @param {boolean} boolWithHistory If true, a newcomer will have the complete messages history since the beginning of the bubble. False if omitted
* @return {Bubble} A bubble
* @description
* Create a new bubble
*/
createBubble(strName, strDescription) {
createBubble(strName, strDescription, boolWithHistory) {

var that = this;

return new Promise((resolve, reject) => {

that._logger.log("debug", LOG_ID + "(createBubble) _entering_");

if (typeof boolWithHistory === "undefined") {
boolWithHistory = false;
}

if (!strName) {
that._logger.log("warn", LOG_ID + "(createBubble) bad or empty 'strName' parameter", strName);
Expand All @@ -49,7 +54,7 @@ class Bubbles {
reject(ErrorCase.BAD_REQUEST);
throw new Error(ErrorCase.BAD_REQUEST.msg);
} else {
that._rest.createBubble(strName, strDescription).then((bubble) => {
that._rest.createBubble(strName, strDescription, boolWithHistory).then((bubble) => {
that._logger.log("debug", LOG_ID + "(createBubble) creation successfull");

that._eventEmitter.once("rainbow_onbubblepresencechanged", () => {
Expand Down Expand Up @@ -170,9 +175,7 @@ class Bubbles {
reject(err);
});
}

resolve();

resolve();
});
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"grunt-contrib-watch": "^1.0.0",
"grunt-eslint": "^19.0.0",
"grunt-jsdoc-to-markdown": "^3.0.0",
"mocha": "^3.3.0"
"mocha": "^3.4.1"
},
"dependencies": {
"btoa": "^1.1.2",
Expand Down

0 comments on commit 4c2ea12

Please sign in to comment.