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

Update for thread colors #785

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
38 changes: 20 additions & 18 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ to empty string if you want the default.
Note: the color needs to start with a "#".

__Arguments__
* `color`: String representing a hex color code (eg: "#0000ff") preceded by "#".
* `color`: String representing a theme ID (a list of theme ID can be found at `api.threadColors`).
* `threadID`: String representing the ID of the thread.
* `callback(err)`: A callback called when the change is done (either with an error or null).

Expand Down Expand Up @@ -950,23 +950,25 @@ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, ap
<a name="threadColors"></a>
### api.threadColors

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.

- 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 dictionary mapping names of all currently valid thread themes to their theme ID that are accepted by [`api.changeThreadColor`](#changeThreadColor). These themes, listed below, are the ones present in the palette UI used for selecting thread themes on the Messenger client.

- DefaultBlue: `196241301102133`
- HotPink: `169463077092846`
- AquaBlue: `2442142322678320`
- BrightPurple: `234137870477637`
- CoralPink: `980963458735625`
- Orange: `175615189761153`
- Green: `2136751179887052`
- LavenderPurple: `2058653964378557`
- Red: `2129984390566328`
- Yellow: `174636906462322`
- TealBlue: `1928399724138152`
- Aqua: `417639218648241`
- Mango: `930060997172551`
- Berry: `164535220883264`
- Citrus: `370940413392601`
- Candy: `205488546921017`
- StarWars: `809305022860427`

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

Expand Down
34 changes: 19 additions & 15 deletions src/changeThreadColor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,30 @@ module.exports = function(defaultFuncs, api, ctx) {
}

var form = {
color_choice: validatedColor,
thread_or_other_fbid: threadID
dpr: 1,
queries: JSON.stringify({
o0: {
//This doc_id is valid as of January 31, 2020
doc_id: "1727493033983591",
query_params: {
data: {
actor_id: ctx.userID,
client_mutation_id: "0",
source: "SETTINGS",
theme_id: validatedColor,
thread_id: threadID
}
}
}
})
};

defaultFuncs
.post(
"https://www.facebook.com/messaging/save_thread_color/?source=thread_settings&dpr=1",
ctx.jar,
form
)
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
.then(function(resData) {
if (resData.error === 1357031) {
throw {
error:
"Trying to change colors of a chat that doesn't exist. Have at least one message in the thread before trying to change the colors."
};
}
if (resData.error) {
throw resData;
if (resData[resData.length - 1].error_results > 0) {
throw resData[0].o0.errors;
}

return callback();
Expand Down
49 changes: 33 additions & 16 deletions src/threadColors.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
"use strict";

module.exports = function(defaultFuncs, api, ctx) {
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"
////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"
Copy link
Owner

@Schmavery Schmavery Jan 31, 2020

Choose a reason for hiding this comment

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

Are these the same colors with different names? This is a really breaking change...

Everything else looks great but I wonder if we can keep some of the same names?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

umm, those are some old color which have been commented. also facebook uses theme id now, so those old colors can't be used anymore.
and no, we can't keep them.

Copy link
Owner

Choose a reason for hiding this comment

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

I understand that the api has changed, but clearly some of these colors must be similar MessengerBlue vs DefaultBlue for example.. I remember the original names came from the messenger code somewhere, where did you get the new names?
I'm sure you understand that this change break anyone who currently uses this api

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I get these names from this
image
and yes, I understand that this change will break compatibility.

Copy link
Contributor

Choose a reason for hiding this comment

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

@lequanglam you should put new ids in place of old hex colours (instead of commenting them). This way we can maintain backward compatibility.

Copy link
Contributor Author

@BadAimWeeb BadAimWeeb Jun 14, 2020

Choose a reason for hiding this comment

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

@ravkr I will try to make it backward-compatible, but i'm currently busy at listenMqtt's bugs.

DefaultBlue: "196241301102133",
HotPink: "169463077092846",
AquaBlue: "2442142322678320",
BrightPurple: "234137870477637",
CoralPink: "980963458735625",
Orange: "175615189761153",
Green: "2136751179887052",
LavenderPurple: "2058653964378557",
Red: "2129984390566328",
Yellow: "174636906462322",
TealBlue: "1928399724138152",
Aqua: "417639218648241",
Mango: "930060997172551",
Berry: "164535220883264",
Citrus: "370940413392601",
Candy: "205488546921017",
StarWars: "809305022860427"
};
};