Tue, 17 Sep 2024 00:55:06 -0500
Clean up some stuff in the typing code
This includes plugging a memory leak, using g_timeout_add*_once, and
G_CONNECT_DEFAULT.
Testing Done:
Called in the turtles.
Reviewed at https://reviews.imfreedom.org/r/3495/
| libpurple/purpleconversation.c | file | annotate | diff | comparison | revisions | |
| meson.build | file | annotate | diff | comparison | revisions |
--- a/libpurple/purpleconversation.c Tue Sep 17 00:49:55 2024 -0500 +++ b/libpurple/purpleconversation.c Tue Sep 17 00:55:06 2024 -0500 @@ -209,7 +209,7 @@ g_signal_connect_object(account, "notify::connected", G_CALLBACK(purple_conversation_account_connected_cb), - conversation, 0); + conversation, G_CONNECT_DEFAULT); } obj = G_OBJECT(conversation); @@ -349,7 +349,7 @@ * To avoid this, we just set the typing_state_source to 0 which will make * purple_conversation_set_typing_state not try to cancel the source. */ -static gboolean +static void purple_conversation_typing_state_typing_cb(gpointer data) { PurpleConversation *conversation = data; @@ -357,8 +357,6 @@ purple_conversation_set_typing_state(conversation, PURPLE_TYPING_STATE_PAUSED); - - return G_SOURCE_REMOVE; } /* @@ -376,7 +374,7 @@ * To avoid this, we just set the typing_state_source to 0 which will make * purple_conversation_set_typing_state not try to cancel the source. */ -static gboolean +static void purple_conversation_typing_state_paused_cb(gpointer data) { PurpleConversation *conversation = data; @@ -384,8 +382,6 @@ purple_conversation_set_typing_state(conversation, PURPLE_TYPING_STATE_NONE); - - return G_SOURCE_REMOVE; } /************************************************************************** @@ -1809,8 +1805,8 @@ /* We set some default timeouts based on the state. If the new state is * TYPING, we use a 6 second timeout that will change the state to PAUSED. - * When the state changes to PAUSED we will set a 30 second time that will - * change the state to NONE. + * When the state changes to PAUSED we will set a 30 second timeout that + * will change the state to NONE. * * This allows the user interface to just tell libpurple when the user is * typing, and the rest happens automatically. @@ -1819,11 +1815,15 @@ GDateTime *now = NULL; conversation->typing_state_source = - g_timeout_add_seconds(6, - purple_conversation_typing_state_typing_cb, - conversation); + g_timeout_add_seconds_once(6, + purple_conversation_typing_state_typing_cb, + conversation); - /* Use local time because this is local to the user and we might want + /* We don't want to spam services with typing notifications, so we only + * send them if it's been at least 3 seconds since the last one was + * sent. + * + * Use local time because this is local to the user and we might want * to output this during debug or something, and a local time stamp * will make a lot more sense then. */ @@ -1832,8 +1832,9 @@ GTimeSpan difference = 0; difference = g_date_time_difference(now, conversation->last_typing); + birb_date_time_clear(&conversation->last_typing); - if(difference > 3 * G_TIME_SPAN_SECOND) { + if(difference >= 3 * G_TIME_SPAN_SECOND) { send = TRUE; } } @@ -1841,9 +1842,11 @@ conversation->last_typing = now; } else if(typing_state == PURPLE_TYPING_STATE_PAUSED) { conversation->typing_state_source = - g_timeout_add_seconds(30, - purple_conversation_typing_state_paused_cb, - conversation); + g_timeout_add_seconds_once(30, + purple_conversation_typing_state_paused_cb, + conversation); + } else if(typing_state == PURPLE_TYPING_STATE_NONE) { + birb_date_time_clear(&conversation->last_typing); } if(conversation->typing_state != typing_state) {
--- a/meson.build Tue Sep 17 00:49:55 2024 -0500 +++ b/meson.build Tue Sep 17 00:55:06 2024 -0500 @@ -174,13 +174,13 @@ ####################################################################### # Once we require >= 2.74.0, remove the hack in the if(TRUE) block in # libpurple/core.c. -glib = dependency('glib-2.0', version : '>= 2.76.0') +glib = dependency('glib-2.0', version : '>= 2.78.0') gio = dependency('gio-2.0') gnome = import('gnome') add_project_arguments( - '-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_76', - '-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_76', + '-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_78', + '-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_78', language : 'c',) #######################################################################