Fri, 30 Sep 2022 03:12:09 -0500
Remove auto-replies
Auto-replies only work if the protocol supports them, and at the time of this
writing the only protocol that sets that flag is Zephyr which is barely used.
Testing Done:
Opened the preferences and verified the away page loaded fine.
Bugs closed: PIDGIN-17684
Reviewed at https://reviews.imfreedom.org/r/1867/
--- a/libpurple/prefs.c Fri Sep 30 03:11:02 2022 -0500 +++ b/libpurple/prefs.c Fri Sep 30 03:12:09 2022 -0500 @@ -1454,31 +1454,6 @@ purple_prefs_add_bool("/purple/away/away_when_idle", TRUE); purple_prefs_add_int("/purple/away/mins_before_away", 5); - /* Away -> Auto-Reply */ - if (!purple_prefs_exists("/purple/away/auto_response/enabled") || - !purple_prefs_exists("/purple/away/auto_response/idle_only")) - { - purple_prefs_add_string("/purple/away/auto_reply", "awayidle"); - } - else - { - if (!purple_prefs_get_bool("/purple/away/auto_response/enabled")) - { - purple_prefs_add_string("/purple/away/auto_reply", "never"); - } - else - { - if (purple_prefs_get_bool("/purple/away/auto_response/idle_only")) - { - purple_prefs_add_string("/purple/away/auto_reply", "awayidle"); - } - else - { - purple_prefs_add_string("/purple/away/auto_reply", "away"); - } - } - } - /* Buddies */ purple_prefs_add_none("/purple/buddies");
--- a/libpurple/server.c Fri Sep 30 03:11:02 2022 -0500 +++ b/libpurple/server.c Fri Sep 30 03:12:09 2022 -0500 @@ -44,9 +44,6 @@ #include "util.h" #include "xfer.h" -#define SECS_BEFORE_RESENDING_AUTORESPONSE 600 -#define SEX_BEFORE_RESENDING_AUTORESPONSE "Only after you're married" - unsigned int purple_serv_send_typing(PurpleConnection *gc, const char *name, PurpleIMTypingState state) { @@ -60,74 +57,13 @@ return 0; } -static GSList *last_auto_responses = NULL; -struct last_auto_response { - PurpleConnection *gc; - char name[80]; - time_t sent; -}; - -static gboolean -expire_last_auto_responses(gpointer data) -{ - GSList *tmp, *cur; - struct last_auto_response *lar; - - tmp = last_auto_responses; - - while (tmp) { - cur = tmp; - tmp = tmp->next; - lar = (struct last_auto_response *)cur->data; - - if ((time(NULL) - lar->sent) > SECS_BEFORE_RESENDING_AUTORESPONSE) { - last_auto_responses = g_slist_delete_link(last_auto_responses, cur); - g_free(lar); - } - } - - return FALSE; /* do not run again */ -} - -static struct last_auto_response * -get_last_auto_response(PurpleConnection *gc, const char *name) -{ - GSList *tmp; - struct last_auto_response *lar; - - /* because we're modifying or creating a lar, schedule the - * function to expire them as the pref dictates */ - g_timeout_add_seconds((SECS_BEFORE_RESENDING_AUTORESPONSE + 1), expire_last_auto_responses, NULL); - - tmp = last_auto_responses; - - while (tmp) { - lar = (struct last_auto_response *)tmp->data; - - if (gc == lar->gc && !strncmp(name, lar->name, sizeof(lar->name))) - return lar; - - tmp = tmp->next; - } - - lar = g_new0(struct last_auto_response, 1); - g_snprintf(lar->name, sizeof(lar->name), "%s", name); - lar->gc = gc; - lar->sent = 0; - last_auto_responses = g_slist_prepend(last_auto_responses, lar); - - return lar; -} - int purple_serv_send_im(PurpleConnection *gc, PurpleMessage *msg) { PurpleAccount *account = NULL; PurpleConversation *im = NULL; PurpleConversationManager *manager = NULL; - PurplePresence *presence = NULL; PurpleProtocol *protocol = NULL; int val = -EINVAL; - const gchar *auto_reply_pref = NULL; const gchar *recipient; g_return_val_if_fail(gc != NULL, val); @@ -139,7 +75,6 @@ g_return_val_if_fail(PURPLE_IS_PROTOCOL_IM(protocol), val); account = purple_connection_get_account(gc); - presence = purple_account_get_presence(account); recipient = purple_message_get_recipient(msg); manager = purple_conversation_manager_get_default(); @@ -155,20 +90,6 @@ val = purple_protocol_im_send(pim, gc, msg); } - /* - * XXX - If "only auto-reply when away & idle" is set, then shouldn't - * this only reset lar->sent if we're away AND idle? - */ - auto_reply_pref = purple_prefs_get_string("/purple/away/auto_reply"); - if((purple_connection_get_flags(gc) & PURPLE_CONNECTION_FLAG_AUTO_RESP) && - !purple_presence_is_available(presence) && - !purple_strequal(auto_reply_pref, "never")) { - - struct last_auto_response *lar; - lar = get_last_auto_response(gc, recipient); - lar->sent = time(NULL); - } - if(im && purple_im_conversation_get_send_typed_timeout(PURPLE_IM_CONVERSATION(im))) purple_im_conversation_stop_send_typed_timeout(PURPLE_IM_CONVERSATION(im)); @@ -561,85 +482,6 @@ g_free(message); g_object_unref(G_OBJECT(pmsg)); - /* - * Don't autorespond if: - * - * - it's not supported on this connection - * - we are available - * - or it's disabled - * - or we're not idle and the 'only auto respond if idle' pref - * is set - */ - if (purple_connection_get_flags(gc) & PURPLE_CONNECTION_FLAG_AUTO_RESP) - { - PurplePresence *presence; - PurpleStatus *status; - PurpleStatusType *status_type; - PurpleStatusPrimitive primitive; - const gchar *auto_reply_pref; - const char *away_msg = NULL; - gboolean mobile = FALSE; - - auto_reply_pref = purple_prefs_get_string("/purple/away/auto_reply"); - - presence = purple_account_get_presence(account); - status = purple_presence_get_active_status(presence); - status_type = purple_status_get_status_type(status); - primitive = purple_status_type_get_primitive(status_type); - mobile = purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_MOBILE); - if ((primitive == PURPLE_STATUS_AVAILABLE) || - (primitive == PURPLE_STATUS_INVISIBLE) || - mobile || - purple_strequal(auto_reply_pref, "never") || - (!purple_presence_is_idle(presence) && purple_strequal(auto_reply_pref, "awayidle"))) - { - g_free(name); - return; - } - - away_msg = g_value_get_string( - purple_status_get_attr_value(status, "message")); - - if ((away_msg != NULL) && (*away_msg != '\0')) { - struct last_auto_response *lar; - time_t now = time(NULL); - - /* - * This used to be based on the conversation window. But um, if - * you went away, and someone sent you a message and got your - * auto-response, and then you closed the window, and then they - * sent you another one, they'd get the auto-response back too - * soon. Besides that, we need to keep track of this even if we've - * got a queue. So the rest of this block is just the auto-response, - * if necessary. - */ - lar = get_last_auto_response(gc, name); - if ((now - lar->sent) >= SECS_BEFORE_RESENDING_AUTORESPONSE) - { - /* - * We don't want to send an autoresponse in response to the other user's - * autoresponse. We do, however, not want to then send one in response to the - * _next_ message, so we still set lar->sent to now. - */ - lar->sent = now; - - if (!(flags & PURPLE_MESSAGE_AUTO_RESP)) - { - PurpleMessage *msg; - const gchar *me = purple_account_get_name_for_display(account); - - msg = purple_message_new_outgoing(me, name, - away_msg, PURPLE_MESSAGE_AUTO_RESP); - - purple_serv_send_im(gc, msg); - purple_conversation_write_message(PURPLE_CONVERSATION(im), msg); - - g_object_unref(G_OBJECT(msg)); - } - } - } - } - g_free(name); }
--- a/pidgin/prefs/pidginawayprefs.c Fri Sep 30 03:11:02 2022 -0500 +++ b/pidgin/prefs/pidginawayprefs.c Fri Sep 30 03:12:09 2022 -0500 @@ -38,7 +38,6 @@ GtkWidget *mins_before_away; GtkWidget *idle_row; GtkWidget *away_when_idle; - GtkWidget *auto_reply; GtkWidget *startup_current_status; GtkWidget *startup_row; }; @@ -73,24 +72,6 @@ purple_savedstatus_get_creation_time(status)); } -static gchar * -auto_reply_expression_cb(GObject *self, G_GNUC_UNUSED gpointer data) -{ - const gchar *text = ""; - const gchar *value = NULL; - - value = gtk_string_object_get_string(GTK_STRING_OBJECT(self)); - if(purple_strequal(value, "never")) { - text = _("Never"); - } else if(purple_strequal(value, "away")) { - text = _("When away"); - } else if(purple_strequal(value, "awayidle")) { - text = _("When both away and idle"); - } - - return g_strdup(text); -} - static void set_startupstatus(PurpleSavedStatus *status) { @@ -122,10 +103,6 @@ gtk_widget_class_bind_template_child(widget_class, PidginAwayPrefs, idle_row); gtk_widget_class_bind_template_child(widget_class, PidginAwayPrefs, - auto_reply); - gtk_widget_class_bind_template_callback(widget_class, - auto_reply_expression_cb); - gtk_widget_class_bind_template_child(widget_class, PidginAwayPrefs, startup_current_status); gtk_widget_class_bind_template_child(widget_class, PidginAwayPrefs, startup_row); @@ -159,9 +136,6 @@ menu, "sensitive", G_BINDING_SYNC_CREATE); - /* Away stuff */ - pidgin_prefs_bind_combo_row("/purple/away/auto_reply", prefs->auto_reply); - /* Signon status stuff */ pidgin_prefs_bind_switch("/purple/savedstatus/startup_current_status", prefs->startup_current_status);
--- a/pidgin/resources/Prefs/away.ui Fri Sep 30 03:11:02 2022 -0500 +++ b/pidgin/resources/Prefs/away.ui Fri Sep 30 03:12:09 2022 -0500 @@ -86,30 +86,6 @@ </child> <child> <object class="AdwPreferencesGroup"> - <property name="title" translatable="1">Away</property> - <child> - <object class="AdwComboRow" id="auto_reply"> - <property name="title" translatable="1">_Auto-reply</property> - <property name="use-subtitle">1</property> - <property name="use-underline">1</property> - <property name="model"> - <object class="GtkStringList"> - <items> - <item>never</item> - <item>away</item> - <item>awayidle</item> - </items> - </object> - </property> - <property name="expression"> - <closure type="gchararray" function="auto_reply_expression_cb"/> - </property> - </object> - </child> - </object> - </child> - <child> - <object class="AdwPreferencesGroup"> <property name="title" translatable="1">Status at Startup</property> <child> <object class="AdwActionRow">