summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Kramlich <grim@reaperworld.com>2023-03-21 02:37:23 -0500
committerGary Kramlich <grim@reaperworld.com>2023-03-21 02:37:23 -0500
commit14d0b20a044d5496a97eb88f5da4e8aaac4c0a93 (patch)
treee05e441883e9f5e8f6823212e82343539af3f532
parent26eb56e7957480a4d6a506cf9250d092b924f6f6 (diff)
downloadpidgin-14d0b20a044d5496a97eb88f5da4e8aaac4c0a93.tar.gz
Use the new status api in the demo protocol plugin
We had to add the new properties to the compatibility layer in PurpleContactManager but everything seems to be fine. Testing Done: Connected a demo account and verified the display was right in the contact list. Note, we don't currently display the primitive nor the idle time. Reviewed at https://reviews.imfreedom.org/r/2376/
-rw-r--r--libpurple/protocols/demo/purpledemocontacts.c81
-rw-r--r--libpurple/protocols/demo/resources/contacts.json14
-rw-r--r--libpurple/purplecontactmanager.c12
-rw-r--r--pidgin/pidgincontactlist.c2
4 files changed, 62 insertions, 47 deletions
diff --git a/libpurple/protocols/demo/purpledemocontacts.c b/libpurple/protocols/demo/purpledemocontacts.c
index 07ad1a9fd5..03a3f9cf7c 100644
--- a/libpurple/protocols/demo/purpledemocontacts.c
+++ b/libpurple/protocols/demo/purpledemocontacts.c
@@ -26,58 +26,62 @@
* Helpers
*****************************************************************************/
static void
-purple_demo_protocol_load_status(PurpleAccount *account,
- G_GNUC_UNUSED PurpleGroup *group,
- G_GNUC_UNUSED PurpleMetaContact *contact,
- PurpleBuddy *buddy, JsonObject *buddy_object)
+purple_demo_protocol_load_status(PurpleBuddy *buddy, JsonObject *buddy_object)
{
+ PurplePresence *presence = NULL;
JsonObject *status_object = NULL;
- const gchar *id = NULL;
if(!json_object_has_member(buddy_object, "status")) {
return;
}
+ presence = purple_buddy_get_presence(buddy);
+
status_object = json_object_get_object_member(buddy_object, "status");
- if(json_object_has_member(status_object, "id")) {
- id = json_object_get_string_member(status_object, "id");
- }
+ if(json_object_has_member(status_object, "primitive")) {
+ PurplePresencePrimitive primitive = PURPLE_PRESENCE_PRIMITIVE_OFFLINE;
+ const char *name = NULL;
+
+ name = json_object_get_string_member(status_object, "primitive");
+ if(!purple_strempty(name)) {
+ GEnumClass *klass = NULL;
+ GEnumValue *value = NULL;
+
+ klass = g_type_class_ref(PURPLE_TYPE_PRESENCE_PRIMITIVE);
+ value = g_enum_get_value_by_nick(klass, name);
- if(id != NULL) {
- if(json_object_has_member(status_object, "message")) {
- const gchar *message = NULL;
-
- message = json_object_get_string_member(status_object, "message");
-
- purple_protocol_got_user_status(account,
- purple_buddy_get_name(buddy),
- id,
- "message", message,
- NULL);
- } else {
- purple_protocol_got_user_status(account,
- purple_buddy_get_name(buddy),
- id,
- NULL);
+ if(value != NULL) {
+ primitive = value->value;
+ }
+
+ g_type_class_unref(klass);
}
- if(json_object_has_member(status_object, "idle")) {
- PurplePresence *presence = NULL;
- GDateTime *now = NULL;
- GDateTime *idle_since = NULL;
- gint idle_minutes = 0;
+ purple_presence_set_primitive(presence, primitive);
+ }
- idle_minutes = json_object_get_int_member(status_object, "idle");
- now = g_date_time_new_now_local();
- idle_since = g_date_time_add_minutes(now, -1 * idle_minutes);
+ if(json_object_has_member(status_object, "message")) {
+ const gchar *message = NULL;
- presence = purple_buddy_get_presence(buddy);
- purple_presence_set_idle(presence, TRUE, idle_since);
+ message = json_object_get_string_member(status_object, "message");
- g_date_time_unref(idle_since);
- g_date_time_unref(now);
- }
+ purple_presence_set_message(presence, message);
+ }
+
+ if(json_object_has_member(status_object, "idle")) {
+ GDateTime *now = NULL;
+ GDateTime *idle_since = NULL;
+ gint idle_minutes = 0;
+
+ idle_minutes = json_object_get_int_member(status_object, "idle");
+ now = g_date_time_new_now_local();
+ idle_since = g_date_time_add_minutes(now, -1 * idle_minutes);
+
+ purple_presence_set_idle(presence, TRUE, idle_since);
+
+ g_date_time_unref(idle_since);
+ g_date_time_unref(now);
}
}
@@ -132,8 +136,7 @@ purple_demo_protocol_load_buddies(PurpleAccount *account, PurpleGroup *group,
}
purple_demo_protocol_load_icon(account, name);
- purple_demo_protocol_load_status(account, group, contact, buddy,
- buddy_object);
+ purple_demo_protocol_load_status(buddy, buddy_object);
if (purple_strequal(name, "Echo")) {
purple_protocol_got_media_caps(account, name);
}
diff --git a/libpurple/protocols/demo/resources/contacts.json b/libpurple/protocols/demo/resources/contacts.json
index 1d284c6163..a89ea2e516 100644
--- a/libpurple/protocols/demo/resources/contacts.json
+++ b/libpurple/protocols/demo/resources/contacts.json
@@ -4,7 +4,7 @@
"buddies": [{
"name": "Gary",
"status": {
- "id": "available",
+ "primitive": "available",
"message": "💤 Sleeping... 😴",
"idle": 1337
}
@@ -15,7 +15,7 @@
"name": "John",
"alias": "Rekkanoryo",
"status": {
- "id": "away"
+ "primitive": "away"
}
}]
}],
@@ -23,7 +23,7 @@
"buddies": [{
"name": "Elliott",
"status": {
- "id": "away",
+ "primitive": "away",
"message": "Coding..."
}
}]
@@ -31,7 +31,7 @@
"buddies": [{
"name": "Richard",
"status": {
- "id": "available"
+ "primitive": "available"
}
}]
}],
@@ -39,7 +39,7 @@
"buddies": [{
"name": "Eion",
"status": {
- "id": "available",
+ "primitive": "available",
"message": "Writing crazy patches!"
}
}]
@@ -47,7 +47,7 @@
"buddies": [{
"name": "Markus",
"status": {
- "id": "extended_away",
+ "primitive": "extended_away",
"message": "Running all the things in valgrind..."
}
}]
@@ -56,7 +56,7 @@
"buddies": [{
"name": "Echo",
"status": {
- "id": "available",
+ "primitive": "available",
"message": "Cursed to speak the last words spoken to me"
}
}]
diff --git a/libpurple/purplecontactmanager.c b/libpurple/purplecontactmanager.c
index 82e623d4b9..bc7025531c 100644
--- a/libpurple/purplecontactmanager.c
+++ b/libpurple/purplecontactmanager.c
@@ -620,6 +620,18 @@ purple_contact_manager_add_buddy(PurpleContactManager *manager,
g_object_bind_property(buddy_presence, "active-status", contact_presence,
"active-status",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+ g_object_bind_property(buddy_presence, "message", contact_presence,
+ "message",
+ G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+ g_object_bind_property(buddy_presence, "emoji", contact_presence,
+ "emoji",
+ G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+ g_object_bind_property(buddy_presence, "mobile", contact_presence,
+ "mobile",
+ G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+ g_object_bind_property(buddy_presence, "primitive", contact_presence,
+ "primitive",
+ G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
g_object_bind_property_full(buddy, "icon", contact, "avatar",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL,
diff --git a/pidgin/pidgincontactlist.c b/pidgin/pidgincontactlist.c
index 37d8fee340..6d84032ca3 100644
--- a/pidgin/pidgincontactlist.c
+++ b/pidgin/pidgincontactlist.c
@@ -162,7 +162,7 @@ pidgin_contact_list_message_visible_cb(G_GNUC_UNUSED GtkListItem *item,
/* If we have a message, return TRUE because this is bound to the label's
* visibility.
*/
- return (message != NULL);
+ return !purple_strempty(message);
}
/******************************************************************************