/soc/2015/jgeboski/facebook: 6545b86a0705: facebook: refactored ...
James Geboski
jgeboski at gmail.com
Tue Aug 18 19:14:02 EDT 2015
Changeset: 6545b86a0705fa12e4d0a9c44f2cac6b536b3c9d
Author: James Geboski <jgeboski at gmail.com>
Date: 2015-08-18 19:11 -0400
Branch: facebook
URL: https://hg.pidgin.im/soc/2015/jgeboski/facebook/rev/6545b86a0705
Description:
facebook: refactored for future inline images
diffstat:
libpurple/protocols/facebook/api.c | 9 +-
libpurple/protocols/facebook/api.h | 17 +-
libpurple/protocols/facebook/data.c | 261 +++++++++++++++++++++----------
libpurple/protocols/facebook/data.h | 164 +++++++++++++++----
libpurple/protocols/facebook/facebook.c | 81 ++++-----
5 files changed, 361 insertions(+), 171 deletions(-)
diffs (truncated from 750 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
@@ -1387,12 +1387,11 @@ fb_api_cb_publish_ms(FbApi *api, GByteAr
oid = fb_json_values_next_int(values, 0);
msg.tid = fb_json_values_next_int(values, 0);
- if (uid != priv->uid) {
- msg.isself = FALSE;
+ if (uid == priv->uid) {
+ msg.flags |= FB_API_MESSAGE_FLAG_SELF;
+ msg.uid = oid;
+ } else {
msg.uid = uid;
- } else {
- msg.isself = TRUE;
- msg.uid = oid;
}
if (msg.uid == 0) {
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
@@ -255,7 +255,7 @@ typedef enum
* @FB_API_EVENT_TYPE_THREAD_USER_ADDED: A thread user was added.
* @FB_API_EVENT_TYPE_THREAD_USER_REMOVED: A thread user was removed.
*
- * The FbApiEvent types.
+ * The #FbApiEvent types.
*/
typedef enum
{
@@ -264,6 +264,17 @@ typedef enum
} FbApiEventType;
/**
+ * FbApiMessageFlags:
+ * @FB_API_MESSAGE_FLAG_SELF: The text is from the #FbApi user.
+ *
+ * The #FbApiMessage flags.
+ */
+typedef enum
+{
+ FB_API_MESSAGE_FLAG_SELF = 1 << 0
+} FbApiMessageFlags;
+
+/**
* FbApi:
*
* Represents a Facebook Messenger connection.
@@ -303,19 +314,19 @@ struct _FbApiEvent
/**
* FbApiMessage:
+ * @flags: The #FbApiMessageFlags.
* @uid: The user #FbId.
* @tid: The thread #FbId.
* @text: The message text.
- * @isself: #TRUE if the user is the #FbApi user, otherwise #FALSE.
*
* Represents a Facebook user message.
*/
struct _FbApiMessage
{
+ FbApiMessageFlags flags;
FbId uid;
FbId tid;
gchar *text;
- gboolean isself;
};
/**
diff --git a/libpurple/protocols/facebook/data.c b/libpurple/protocols/facebook/data.c
--- a/libpurple/protocols/facebook/data.c
+++ b/libpurple/protocols/facebook/data.c
@@ -33,12 +33,23 @@ struct _FbDataPrivate
PurpleConnection *gc;
PurpleRoomlist *roomlist;
GQueue *msgs;
- GHashTable *icons;
- GHashTable *icona;
+ GHashTable *imgs;
GHashTable *unread;
GHashTable *evs;
};
+struct _FbDataImagePrivate
+{
+ FbData *fata;
+ gchar *url;
+ FbDataImageFunc func;
+ gpointer data;
+
+ gboolean active;
+ const guint8 *image;
+ gsize size;
+};
+
static const gchar *fb_props_strs[] = {
"cid",
"did",
@@ -46,10 +57,8 @@ static const gchar *fb_props_strs[] = {
"token"
};
-static void
-fb_data_icon_free(FbDataIcon *icon);
-
G_DEFINE_TYPE(FbData, fb_data, G_TYPE_OBJECT);
+G_DEFINE_TYPE(FbDataImage, fb_data_image, G_TYPE_OBJECT);
static void
fb_data_dispose(GObject *obj)
@@ -70,8 +79,7 @@ fb_data_dispose(GObject *obj)
g_queue_free_full(priv->msgs, (GDestroyNotify) fb_api_message_free);
- g_hash_table_destroy(priv->icons);
- g_hash_table_destroy(priv->icona);
+ g_hash_table_destroy(priv->imgs);
g_hash_table_destroy(priv->unread);
g_hash_table_destroy(priv->evs);
}
@@ -94,16 +102,42 @@ fb_data_init(FbData *fata)
fata->priv = priv;
priv->msgs = g_queue_new();
- priv->icons = g_hash_table_new_full(g_direct_hash, g_direct_equal,
- (GDestroyNotify) fb_data_icon_free,
- NULL);
- priv->icona = g_hash_table_new_full(g_direct_hash, g_direct_equal,
- (GDestroyNotify) fb_data_icon_free,
- NULL);
- priv->unread = g_hash_table_new_full(fb_id_hash, fb_id_equal, g_free,
- NULL);
- priv->evs = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
- NULL);
+ priv->imgs = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+ g_object_unref, NULL);
+ priv->unread = g_hash_table_new_full(fb_id_hash, fb_id_equal,
+ g_free, NULL);
+ priv->evs = g_hash_table_new_full(g_str_hash, g_str_equal,
+ g_free, NULL);
+}
+
+static void
+fb_data_image_dispose(GObject *obj)
+{
+ FbDataImage *img = FB_DATA_IMAGE(obj);
+ FbDataImagePrivate *priv = img->priv;
+ FbData *fata = priv->fata;
+
+ g_free(priv->url);
+ g_hash_table_steal(fata->priv->imgs, img);
+}
+
+static void
+fb_data_image_class_init(FbDataImageClass *klass)
+{
+ GObjectClass *gklass = G_OBJECT_CLASS(klass);
+
+ gklass->dispose = fb_data_image_dispose;
+ g_type_class_add_private(klass, sizeof (FbDataImagePrivate));
+}
+
+static void
+fb_data_image_init(FbDataImage *img)
+{
+ FbDataImagePrivate *priv;
+
+ priv = G_TYPE_INSTANCE_GET_PRIVATE(img, FB_TYPE_DATA_IMAGE,
+ FbDataImagePrivate);
+ img->priv = priv;
}
FbData *
@@ -376,101 +410,162 @@ fb_data_take_messages(FbData *fata, FbId
return msgs;
}
-FbDataIcon *
-fb_data_icon_add(FbData *fata, PurpleBuddy *buddy, const gchar *url,
- PurpleHttpCallback func)
+FbDataImage *
+fb_data_image_add(FbData *fata, const gchar *url, FbDataImageFunc func,
+ gpointer data)
{
- FbDataIcon *icon;
- FbDataPrivate *priv;
+ FbDataImage *img;
+ FbDataImagePrivate *priv;
g_return_val_if_fail(FB_IS_DATA(fata), NULL);
- g_return_val_if_fail(PURPLE_IS_BUDDY(buddy), NULL);
g_return_val_if_fail(url != NULL, NULL);
- priv = fata->priv;
+ g_return_val_if_fail(func != NULL, NULL);
- icon = g_new(FbDataIcon, 1);
- icon->fata = fata;
- icon->buddy = buddy;
- icon->url = g_strdup(url);
- icon->func = func;
+ img = g_object_new(FB_TYPE_DATA_IMAGE, NULL);
+ priv = img->priv;
- g_hash_table_replace(priv->icons, icon, icon);
- return icon;
+ priv->fata = fata;
+ priv->url = g_strdup(url);
+ priv->func = func;
+ priv->data = data;
+
+ g_hash_table_insert(fata->priv->imgs, img, img);
+ return img;
+}
+
+gboolean
+fb_data_image_get_active(FbDataImage *img)
+{
+ FbDataImagePrivate *priv;
+
+ g_return_val_if_fail(FB_IS_DATA_IMAGE(img), NULL);
+ priv = img->priv;
+
+ return priv->active;
+}
+
+gpointer
+fb_data_image_get_data(FbDataImage *img)
+{
+ FbDataImagePrivate *priv;
+
+ g_return_val_if_fail(FB_IS_DATA_IMAGE(img), NULL);
+ priv = img->priv;
+
+ return priv->data;
+}
+
+FbData *
+fb_data_image_get_fata(FbDataImage *img)
+{
+ FbDataImagePrivate *priv;
+
+ g_return_val_if_fail(FB_IS_DATA_IMAGE(img), NULL);
+ priv = img->priv;
+
+ return priv->fata;
+}
+
+const guint8 *
+fb_data_image_get_image(FbDataImage *img, gsize *size)
+{
+ FbDataImagePrivate *priv;
+
+ g_return_val_if_fail(FB_IS_DATA_IMAGE(img), NULL);
+ priv = img->priv;
+
+ if (size != NULL) {
+ *size = priv->size;
+ }
+
+ return priv->image;
+}
+
+guint8 *
+fb_data_image_dup_image(FbDataImage *img, gsize *size)
+{
+ FbDataImagePrivate *priv;
+
+ g_return_val_if_fail(FB_IS_DATA_IMAGE(img), NULL);
+ priv = img->priv;
+
+ if (size != NULL) {
+ *size = priv->size;
+ }
+
+ if (priv->size < 1) {
+ return NULL;
+ }
+
+ return g_memdup(priv->image, priv->size);
+}
+
+const gchar *
+fb_data_image_get_url(FbDataImage *img)
+{
+ FbDataImagePrivate *priv;
+
+ g_return_val_if_fail(FB_IS_DATA_IMAGE(img), NULL);
+ priv = img->priv;
+
+ return priv->url;
}
static void
-fb_data_icon_free(FbDataIcon *icon)
+fb_data_image_cb(PurpleHttpConnection *con, PurpleHttpResponse *res,
+ gpointer data)
{
More information about the Commits
mailing list