/soc/2015/jgeboski/facebook: 4c091ac7c55a: facebook: implemented...
James Geboski
jgeboski at gmail.com
Sat Aug 8 22:01:54 EDT 2015
Changeset: 4c091ac7c55add5807c84e9e87d03310d535b9ad
Author: James Geboski <jgeboski at gmail.com>
Date: 2015-08-08 22:01 -0400
Branch: facebook
URL: https://hg.pidgin.im/soc/2015/jgeboski/facebook/rev/4c091ac7c55a
Description:
facebook: implemented the invisible presence state
diffstat:
libpurple/protocols/facebook/api.c | 157 ++++++++++++++++++-------------
libpurple/protocols/facebook/api.h | 6 +-
libpurple/protocols/facebook/facebook.c | 40 +++++++-
3 files changed, 133 insertions(+), 70 deletions(-)
diffs (truncated from 337 to 300 lines):
diff --git a/libpurple/protocols/facebook/api.c b/libpurple/protocols/facebook/api.c
--- a/libpurple/protocols/facebook/api.c
+++ b/libpurple/protocols/facebook/api.c
@@ -60,6 +60,7 @@ struct _FbApiPrivate
gchar *token;
GHashTable *msgids;
+ gboolean invisible;
guint unread;
};
@@ -615,13 +616,13 @@ fb_api_cb_mqtt_open(FbMqtt *mqtt, gpoint
fb_thrift_write_field(thft, FB_THRIFT_TYPE_I32, 9);
fb_thrift_write_i32(thft, 1);
- /* Write the UNKNOWN ("chat_on"?) */
+ /* Write the UNKNOWN ("no_auto_fg"?) */
fb_thrift_write_field(thft, FB_THRIFT_TYPE_BOOL, 10);
fb_thrift_write_bool(thft, TRUE);
- /* Write the UNKNOWN ("no_auto_fg"?) */
+ /* Write the visibility state */
fb_thrift_write_field(thft, FB_THRIFT_TYPE_BOOL, 11);
- fb_thrift_write_bool(thft, TRUE);
+ fb_thrift_write_bool(thft, !priv->invisible);
/* Write the device identifier */
fb_thrift_write_field(thft, FB_THRIFT_TYPE_STRING, 12);
@@ -666,6 +667,70 @@ fb_api_cb_mqtt_open(FbMqtt *mqtt, gpoint
}
static void
+fb_api_connect_queue(FbApi *api)
+{
+ FbApiPrivate *priv = api->priv;
+ gchar *json;
+ JsonBuilder *bldr;
+
+ bldr = fb_json_bldr_new(JSON_NODE_OBJECT);
+ fb_json_bldr_add_int(bldr, "delta_batch_size", 125);
+ fb_json_bldr_add_int(bldr, "max_deltas_able_to_process", 1250);
+ fb_json_bldr_add_int(bldr, "sync_api_version", 3);
+ fb_json_bldr_add_str(bldr, "encoding", "JSON");
+
+ if (priv->stoken == NULL) {
+ fb_json_bldr_add_int(bldr, "initial_titan_sequence_id",
+ priv->sid);
+ fb_json_bldr_add_str(bldr, "device_id", priv->did);
+ fb_json_bldr_add_int(bldr, "entity_fbid", priv->uid);
+
+ fb_json_bldr_obj_begin(bldr, "device_params");
+ fb_json_bldr_add_str(bldr, "animated_image_format", "GIF");
+
+ fb_json_bldr_obj_begin(bldr, "animated_image_sizes");
+ fb_json_bldr_add_str(bldr, "0", "9001x9001");
+ fb_json_bldr_obj_end(bldr);
+
+ fb_json_bldr_obj_begin(bldr, "image_sizes");
+ fb_json_bldr_add_str(bldr, "0", "9001x9001");
+ fb_json_bldr_obj_end(bldr);
+ fb_json_bldr_obj_end(bldr);
+
+ fb_json_bldr_obj_begin(bldr, "queue_params");
+ fb_json_bldr_add_str(bldr, "buzz_on_deltas_enabled", "false");
+
+ fb_json_bldr_obj_begin(bldr, "graphql_query_hashes");
+ fb_json_bldr_add_str(bldr, "xma_query_id", FB_API_QRYID_XMA);
+ fb_json_bldr_obj_end(bldr);
+
+ fb_json_bldr_obj_begin(bldr, "graphql_query_params");
+ fb_json_bldr_obj_begin(bldr, FB_API_QRYID_XMA);
+ fb_json_bldr_add_str(bldr, "xma_id", "<ID>");
+ fb_json_bldr_add_str(bldr, "small_preview_size", "9001");
+ fb_json_bldr_add_str(bldr, "large_preview_size", "9001");
+ fb_json_bldr_obj_end(bldr);
+ fb_json_bldr_obj_end(bldr);
+ fb_json_bldr_obj_end(bldr);
+
+ json = fb_json_bldr_close(bldr, JSON_NODE_OBJECT, NULL);
+ fb_api_publish(api, "/messenger_sync_create_queue", "%s",
+ json);
+ g_free(json);
+ return;
+ }
+
+ fb_json_bldr_add_int(bldr, "last_seq_id", priv->sid);
+ fb_json_bldr_add_str(bldr, "sync_token", priv->stoken);
+
+ json = fb_json_bldr_close(bldr, JSON_NODE_OBJECT, NULL);
+ fb_api_publish(api, "/messenger_sync_get_diffs", "%s", json);
+ g_signal_emit_by_name(api, "connect");
+ g_free(json);
+
+}
+
+static void
fb_api_cb_seqid(PurpleHttpConnection *con, PurpleHttpResponse *res,
gpointer data)
{
@@ -673,9 +738,7 @@ fb_api_cb_seqid(PurpleHttpConnection *co
FbApi *api = data;
FbApiPrivate *priv = api->priv;
FbJsonValues *values;
- gchar *json;
GError *err = NULL;
- JsonBuilder *bldr;
JsonNode *root;
if (!fb_api_http_chk(api, con, res, &root)) {
@@ -698,69 +761,17 @@ fb_api_cb_seqid(PurpleHttpConnection *co
str = fb_json_values_next_str(values, "0");
priv->sid = g_ascii_strtoll(str, NULL, 10);
priv->unread = fb_json_values_next_int(values, 0);
+
+ fb_api_connect_queue(api);
fb_json_values_free(values);
json_node_free(root);
-
- bldr = fb_json_bldr_new(JSON_NODE_OBJECT);
- fb_json_bldr_add_int(bldr, "delta_batch_size", 125);
- fb_json_bldr_add_int(bldr, "max_deltas_able_to_process", 1250);
- fb_json_bldr_add_int(bldr, "sync_api_version", 3);
- fb_json_bldr_add_str(bldr, "encoding", "JSON");
-
- if (priv->stoken == NULL) {
- fb_json_bldr_add_int(bldr, "initial_titan_sequence_id",
- priv->sid);
- fb_json_bldr_add_str(bldr, "device_id", priv->did);
- fb_json_bldr_add_int(bldr, "entity_fbid", priv->uid);
-
- fb_json_bldr_obj_begin(bldr, "device_params");
- fb_json_bldr_add_str(bldr, "animated_image_format", "GIF");
-
- fb_json_bldr_obj_begin(bldr, "animated_image_sizes");
- fb_json_bldr_add_str(bldr, "0", "9001x9001");
- fb_json_bldr_obj_end(bldr);
-
- fb_json_bldr_obj_begin(bldr, "image_sizes");
- fb_json_bldr_add_str(bldr, "0", "9001x9001");
- fb_json_bldr_obj_end(bldr);
- fb_json_bldr_obj_end(bldr);
-
- fb_json_bldr_obj_begin(bldr, "queue_params");
- fb_json_bldr_add_str(bldr, "buzz_on_deltas_enabled", "false");
-
- fb_json_bldr_obj_begin(bldr, "graphql_query_hashes");
- fb_json_bldr_add_str(bldr, "xma_query_id", FB_API_QRYID_XMA);
- fb_json_bldr_obj_end(bldr);
-
- fb_json_bldr_obj_begin(bldr, "graphql_query_params");
- fb_json_bldr_obj_begin(bldr, FB_API_QRYID_XMA);
- fb_json_bldr_add_str(bldr, "xma_id", "<ID>");
- fb_json_bldr_add_str(bldr, "small_preview_size", "9001");
- fb_json_bldr_add_str(bldr, "large_preview_size", "9001");
- fb_json_bldr_obj_end(bldr);
- fb_json_bldr_obj_end(bldr);
- fb_json_bldr_obj_end(bldr);
-
- json = fb_json_bldr_close(bldr, JSON_NODE_OBJECT, NULL);
- fb_api_publish(api, "/messenger_sync_create_queue", "%s",
- json);
- g_free(json);
- return;
- }
-
- fb_json_bldr_add_int(bldr, "last_seq_id", priv->sid);
- fb_json_bldr_add_str(bldr, "sync_token", priv->stoken);
-
- json = fb_json_bldr_close(bldr, JSON_NODE_OBJECT, NULL);
- fb_api_publish(api, "/messenger_sync_get_diffs", "%s", json);
- g_signal_emit_by_name(api, "connect");
- g_free(json);
}
static void
fb_api_cb_mqtt_connect(FbMqtt *mqtt, gpointer data)
{
FbApi *api = data;
+ FbApiPrivate *priv = api->priv;
gchar *json;
JsonBuilder *bldr;
@@ -797,10 +808,14 @@ fb_api_cb_mqtt_connect(FbMqtt *mqtt, gpo
/* Notifications seem to lead to some sort of sending rate limit */
fb_mqtt_unsubscribe(mqtt, "/orca_message_notifications", NULL);
- /* See fb_api_thread_list() for key mapping */
- bldr = fb_json_bldr_new(JSON_NODE_OBJECT);
- fb_json_bldr_add_str(bldr, "1", "0");
- fb_api_http_graph(api, &info, bldr, FB_API_QRYID_THREAD_LIST);
+ if (priv->sid == 0) {
+ /* See fb_api_thread_list() for key mapping */
+ bldr = fb_json_bldr_new(JSON_NODE_OBJECT);
+ fb_json_bldr_add_str(bldr, "1", "0");
+ fb_api_http_graph(api, &info, bldr, FB_API_QRYID_THREAD_LIST);
+ } else {
+ fb_api_connect_queue(api);
+ }
}
static void
@@ -1334,6 +1349,17 @@ fb_api_rehash(FbApi *api)
}
}
+gboolean
+fb_api_is_invisible(FbApi *api)
+{
+ FbApiPrivate *priv;
+
+ g_return_val_if_fail(FB_IS_API(api), FALSE);
+ priv = api->priv;
+
+ return priv->invisible;
+}
+
void
fb_api_error(FbApi *api, FbApiError error, const gchar *format, ...)
{
@@ -1555,13 +1581,14 @@ fb_api_contacts_after(FbApi *api, const
}
void
-fb_api_connect(FbApi *api)
+fb_api_connect(FbApi *api, gboolean invisible)
{
FbApiPrivate *priv;
g_return_if_fail(FB_IS_API(api));
priv = api->priv;
+ priv->invisible = invisible;
fb_mqtt_open(priv->mqtt, FB_MQTT_HOST, FB_MQTT_PORT);
}
diff --git a/libpurple/protocols/facebook/api.h b/libpurple/protocols/facebook/api.h
--- a/libpurple/protocols/facebook/api.h
+++ b/libpurple/protocols/facebook/api.h
@@ -164,8 +164,8 @@ fb_api_new(PurpleConnection *gc);
void
fb_api_rehash(FbApi *api);
-void
-fb_api_free(FbApi *api);
+gboolean
+fb_api_is_invisible(FbApi *api);
void
fb_api_error(FbApi *api, FbApiError err, const gchar *fmt, ...)
@@ -181,7 +181,7 @@ void
fb_api_contacts(FbApi *api);
void
-fb_api_connect(FbApi *api);
+fb_api_connect(FbApi *api, gboolean invisible);
void
fb_api_disconnect(FbApi *api);
diff --git a/libpurple/protocols/facebook/facebook.c b/libpurple/protocols/facebook/facebook.c
--- a/libpurple/protocols/facebook/facebook.c
+++ b/libpurple/protocols/facebook/facebook.c
@@ -139,6 +139,9 @@ fb_cb_api_contacts(FbApi *api, GSList *u
PurpleConnection *gc;
PurpleConnectionState state;
PurpleGroup *grp;
+ PurpleStatus *status;
+ PurpleStatusPrimitive pstat;
+ PurpleStatusType *type;
gc = fb_data_get_connection(fata);
acct = purple_connection_get_account(gc);
@@ -183,8 +186,12 @@ fb_cb_api_contacts(FbApi *api, GSList *u
fb_data_icon_queue(fata);
if (complete && (state != PURPLE_CONNECTION_CONNECTED)) {
+ status = purple_account_get_active_status(acct);
+ type = purple_status_get_status_type(status);
+ pstat = purple_status_type_get_primitive(type);
+
purple_connection_update_progress(gc, _("Connecting"), 3, 4);
- fb_api_connect(api);
+ fb_api_connect(api, pstat == PURPLE_STATUS_INVISIBLE);
}
}
@@ -595,6 +602,10 @@ fb_status_types(PurpleAccount *acct)
NULL, NULL, TRUE);
types = g_list_prepend(types, type);
+ type = purple_status_type_new(PURPLE_STATUS_INVISIBLE,
+ NULL, NULL, TRUE);
+ types = g_list_prepend(types, type);
+
type = purple_status_type_new(PURPLE_STATUS_OFFLINE,
NULL, NULL, TRUE);
types = g_list_prepend(types, type);
@@ -660,6 +671,31 @@ fb_client_offline_message(const PurpleBu
return TRUE;
}
More information about the Commits
mailing list