Skip to content
This repository has been archived by the owner on Jul 9, 2022. It is now read-only.

Add getValidThreadColors #512

Merged
merged 12 commits into from
Aug 10, 2017
24 changes: 24 additions & 0 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* [`api.getThreadPictures`](#getThreadPictures)
* [`api.getUserID`](#getUserID)
* [`api.getUserInfo`](#getUserInfo)
* [`api.validThreadColors`](#validThreadColors)
* [`api.handleMessageRequest`](#handleMessageRequest)
* [`api.listen`](#listen)
* [`api.logout`](#logout)
Expand Down Expand Up @@ -715,6 +716,29 @@ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, ap

---------------------------------------

<a name="validThreadColors"></a>
### api.validThreadColors

Returns a dictionary mapping names of all currently valid thread colors to their hexadecimal values that are accepted by [`api.changeThreadColor`](#changeThreadColor). These colors, listed below, are the ones present in the palette UI used for selecting thread colors on the Messenger client. Due to Facebook backend changes, the thread color can no longer be set to an arbitrary hex value.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can move the note about "Due to Facebook backend changes, the thread color can no longer be set to an arbitrary hex value." to the CHANGELOG.md file and put a link there to this PR? (See the other entries for an example)


- MessengerBlue: `null`
- Viking: `#44bec7`
- GoldenPoppy: `#ffc300`
- RadicalRed: `#fa3c4c`
- Shocking: `#d696bb`
- PictonBlue: `#6699cc`
- FreeSpeechGreen: `#13cf13`
- Pumpkin: `#ff7e29`
- LightCoral: `#e68585`
- MediumSlateBlue: `#7646ff`
- DeepSkyBlue: `#20cef5`
- Fern: `#67b868`
- Cameo: `#d4a88c`
- BrilliantRose: `#ff5ca1`
- BilobaFlower: `#a695c7`

---------------------------------------

<a name="handleMessageRequest"></a>
### api.handleMessageRequest(threadID, accept[, callback])

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function buildAPI(globalOptions, html, jar) {
'getThreadPictures',
'getUserID',
'getUserInfo',
'validThreadColors',
'handleMessageRequest',
'listen',
'logout',
Expand Down
11 changes: 10 additions & 1 deletion src/changeThreadColor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@ module.exports = function(defaultFuncs, api, ctx) {
if(!callback) {
callback = function() {};
}

var validatedColor = (color !== null) ? color.toLowerCase() : color; // API only accepts lowercase letters in hex string
var colorList = Object.keys(api.validThreadColors).map(function(name) {
return api.validThreadColors[name];
});
if(!colorList.includes(validatedColor)) {
throw {error: "The color you are trying to use is not a valid thread color. Use api.validThreadColors to find acceptable values."};
}

var form = {
'color_choice' : color,
'color_choice' : validatedColor,
'thread_or_other_fbid' : threadID
};

Expand Down
22 changes: 22 additions & 0 deletions src/validThreadColors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"use strict";

module.exports = function(defaultFuncs, api, ctx) {
// Currently the only colors that can be passed to api.changeThreadColor(); may change if Facebook adds more
return {
"MessengerBlue": null,
"Viking": "#44bec7",
"GoldenPoppy": "#ffc300",
"RadicalRed": "#fa3c4c",
"Shocking": "#d696bb",
"PictonBlue": "#6699cc",
"FreeSpeechGreen": "#13cf13",
"Pumpkin": "#ff7e29",
"LightCoral": "#e68585",
"MediumSlateBlue": "#7646ff",
"DeepSkyBlue": "#20cef5",
"Fern": "#67b868",
"Cameo": "#d4a88c",
"BrilliantRose": "#ff5ca1",
"BilobaFlower": "#a695c7"
};
};