File size: 1,656 Bytes
91d9d20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var utils = require("../utils");

module.exports = function (http, apis, ctx) {
  return function changeBio(bio, publish, callback) {
    var pCallback;
    var returnPromise = new Promise(function (resolve, reject) {
      pCallback = error => error ? reject(error) : resolve();
    });

    if (typeof bio === "function") {
      callback = bio;
      bio = "";
    }
    if (typeof bio === "boolean") {
      publish = bio;
      bio = "";
    }
    if (typeof publish === "function") {
      callback = publish;
      publish = false;
    }
    if (typeof publish !== "boolean") 
        publish = false;
    if (typeof callback !== "function") 
        callback = pCallback;

    var form = {
      fb_api_caller_class: "RelayModern",
      fb_api_req_friendly_name: "ProfileCometSetBioMutation",
      doc_id: "2725043627607610",
      variables: JSON.stringify({
        input: {
          bio,
          publish_bio_feed_story: publish,
          actor_id: ctx.userID,
          client_mutation_id: Math.round(Math.random() * 1024).toString()
        },
        hasProfileTileViewID: false,
        profileTileViewID: null,
        scale: 1
      })
    }

    http
      .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
      .then(utils.parseAndCheckLogin(ctx, http))
      .then(function (res) {
        if (res.error || res.errors) 
            throw res;
        return callback();
      })
      .catch(function (error) {
        if (error.type === "logout.") 
            ctx.isLogin = false;

        return callback(error);
      });

    return returnPromise;
  }
}