# HG changeset patch # User Yoshiki Yazawa # Date 1219666622 -32400 # Node ID e13103257b33701b39cdf021e1600eba9f707766 # Parent 00e26402de03a64d5e47f4fd86304cddc9adad8f implemented filtering functionality. diff -r 00e26402de03 -r e13103257b33 pidgin-twitter.c --- a/pidgin-twitter.c Sat Aug 23 04:17:49 2008 +0900 +++ b/pidgin-twitter.c Mon Aug 25 21:17:02 2008 +0900 @@ -518,13 +518,25 @@ if(st->id > lastid && !is_posted_message(st, lastid)) { gchar *msg = NULL; + gchar *sender = NULL; + + sender = g_strdup("twitter@twitter.com"); + + PurpleMessageFlags flag = PURPLE_MESSAGE_RECV; msg = g_strdup_printf("%s: %s", st->screen_name, st->text); - purple_conv_im_write(conv->u.im, - "twitter@twitter.com", - msg, - PURPLE_MESSAGE_RECV, - st->time); + + /* apply filter*/ + if(purple_prefs_get_bool(OPT_FILTER)) { + apply_filter(&sender, &msg, &flag, twitter_service); + } + if(sender && msg) { + purple_conv_im_write(conv->u.im, + sender, + msg, + flag, + st->time); + } lastid = st->id; g_free(msg); @@ -951,13 +963,13 @@ playsound(gchar **str, gint which) { GMatchInfo *match_info; - const gchar *list; + const gchar *list = NULL; gchar **candidates = NULL, **candidate = NULL; list = purple_prefs_get_string(which ? OPT_USERLIST_SENDER : OPT_USERLIST_RECIPIENT); g_return_if_fail(list != NULL); - if(!strcmp(list, DEFAULT_LIST)) + if(strstr(list, DEFAULT_LIST)) return; candidates = g_strsplit_set(list, " ,:;", 0); @@ -1003,7 +1015,7 @@ if(service == unknown_service) return FALSE; - /* Add screen_name if the current message is posted by owner */ + /* add screen_name if the current message is posted by myself */ if (flags & PURPLE_MESSAGE_SEND) { gchar *m = NULL; const char *screen_name = NULL; @@ -1054,7 +1066,7 @@ translate(buffer, TAG_IDENTICA, service); } - /* escape pseudo command (to show same result to sending message) */ + /* escape pseudo command (to show the same result as sending message) */ if(service == twitter_service && purple_prefs_get_bool(OPT_ESCAPE_PSEUDO)) { escape(buffer); @@ -1497,6 +1509,63 @@ delete_requested_icon_marks(gtkconv, hash); } +static void +apply_filter(gchar **sender, gchar **buffer, PurpleMessageFlags *flags, int service) +{ + GMatchInfo *match_info; + const gchar *list = NULL; + gchar **candidates = NULL, **candidate = NULL; + + gchar *plain = strip_html_markup(*buffer); + + switch(service) { + case twitter_service: + list = purple_prefs_get_string(OPT_FILTER_TWITTER); + break; + case wassr_service: + list = purple_prefs_get_string(OPT_FILTER_WASSR); + break; + case identica_service: + list = purple_prefs_get_string(OPT_FILTER_IDENTICA); + break; + } + g_return_if_fail(list != NULL); + if(strstr(list, DEFAULT_LIST)) + return; + + candidates = g_strsplit_set(list, " ,:;", 0); + g_return_if_fail(candidates != NULL); + + g_regex_match(regp[SENDER], plain, 0, &match_info); + while(g_match_info_matches(match_info)) { + gchar *user = NULL; + user = g_match_info_fetch(match_info, 2); + twitter_debug("user = %s\n", user); + + for(candidate = candidates; *candidate; candidate++) { + if(!strcmp(*candidate, "")) + continue; + twitter_debug("candidate = %s\n", *candidate); + if(!strcmp(user, *candidate)) { + twitter_debug("match. filter %s\n", user); + *flags |= PURPLE_MESSAGE_INVISIBLE; /* pidgin should handle this flag properly --yaz */ +#if 1 + /* temporal workaround */ + g_free(*sender); *sender = NULL; + g_free(*buffer); *buffer = NULL; +#endif + break; + } + } + g_free(user); + g_match_info_next(match_info, NULL); + } + g_free(plain); + g_strfreev(candidates); + g_match_info_free(match_info); +} + + static gboolean receiving_im_cb(PurpleAccount *account, char **sender, char **buffer, PurpleConversation *conv, PurpleMessageFlags *flags, void *data) @@ -1506,21 +1575,20 @@ gint service = get_service_type(conv); - if(service != unknown_service) { - /* suppress notification of incoming messages. */ - if(purple_prefs_get_bool(OPT_PREVENT_NOTIFICATION)) - *flags |= PURPLE_MESSAGE_SYSTEM; - } - - /* quick hack to suppress annoying completion message from wassr */ + /* suppress notification of incoming messages. */ + if(service != unknown_service && + purple_prefs_get_bool(OPT_PREVENT_NOTIFICATION)) + *flags |= PURPLE_MESSAGE_SYSTEM; + if(service == wassr_service) { + /* suppress annoying completion message from wassr */ if(strstr(*buffer, "投稿完了:") || strstr(*buffer, "チャンネル投稿完了:")) { twitter_debug("clearing sender and buffer\n"); g_free(*sender); *sender = NULL; g_free(*buffer); *buffer = NULL; } - /* fix for parrot problem during post to a channel */ + /* discard parrot message */ else if(wassr_post && strlen(wassr_post) && strstr(*buffer, wassr_post)) { @@ -1531,6 +1599,7 @@ } if(service == identica_service) { + /* discard parrot message */ gchar *stripped = strip_html_markup(*buffer); if(identica_post && strlen(identica_post) && @@ -1543,6 +1612,12 @@ g_free(stripped); } + /* filtering */ + if(purple_prefs_get_bool(OPT_FILTER)) { + apply_filter(sender, buffer, flags, service); + } + + /* return here if it is not twitter */ if(service != twitter_service) { return FALSE; } @@ -2764,6 +2839,39 @@ + /***************/ + /* filter page */ + /***************/ + e = GTK_WIDGET(gtk_builder_get_object (builder, "filter_check")); + g_object_set_data(G_OBJECT(e), "pref", OPT_FILTER); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e), + purple_prefs_get_bool(OPT_FILTER)); + g_signal_connect(e, "toggled", + G_CALLBACK(bool_toggled_cb), &e); + + e = GTK_WIDGET(gtk_builder_get_object (builder, "filter_twitter")); + g_object_set_data(G_OBJECT(e), "pref", OPT_FILTER_TWITTER); + text = purple_prefs_get_string(OPT_FILTER_TWITTER); + gtk_entry_set_text(GTK_ENTRY(e), text); + g_signal_connect(e, "changed", + G_CALLBACK(text_changed_cb), &e); + + e = GTK_WIDGET(gtk_builder_get_object (builder, "filter_wassr")); + g_object_set_data(G_OBJECT(e), "pref", OPT_FILTER_WASSR); + text = purple_prefs_get_string(OPT_FILTER_WASSR); + gtk_entry_set_text(GTK_ENTRY(e), text); + g_signal_connect(e, "changed", + G_CALLBACK(text_changed_cb), &e); + + e = GTK_WIDGET(gtk_builder_get_object (builder, "filter_identica")); + g_object_set_data(G_OBJECT(e), "pref", OPT_FILTER_IDENTICA); + text = purple_prefs_get_string(OPT_FILTER_IDENTICA); + gtk_entry_set_text(GTK_ENTRY(e), text); + g_signal_connect(e, "changed", + G_CALLBACK(text_changed_cb), &e); + + + /*************/ /* icon page */ /*************/ @@ -2968,7 +3076,7 @@ PURPLE_PRIORITY_DEFAULT, /**< priority */ PLUGIN_ID, /**< id */ "Pidgin-Twitter", /**< name */ - "0.7.0", /**< version */ + "0.8.0d1", /**< version */ "provides useful features for twitter", /** summary */ "provides useful features for twitter", /** desc */ "Yoshiki Yazawa, mikanbako, \nKonosuke Watanabe, IWATA Ray, \nmojin, umq, \nthe pidging-twitter team", /**< author */ @@ -3024,6 +3132,11 @@ purple_prefs_add_int(OPT_ICON_MAX_COUNT, DEFAULT_ICON_MAX_COUNT); purple_prefs_add_int(OPT_ICON_MAX_DAYS, DEFAULT_ICON_MAX_DAYS); purple_prefs_add_bool(OPT_LOG_OUTPUT, FALSE); + + purple_prefs_add_bool(OPT_FILTER, TRUE); + purple_prefs_add_string(OPT_FILTER_TWITTER, DEFAULT_LIST); + purple_prefs_add_string(OPT_FILTER_WASSR, DEFAULT_LIST); + purple_prefs_add_string(OPT_FILTER_IDENTICA, DEFAULT_LIST); } PURPLE_INIT_PLUGIN(pidgin_twitter, init_plugin, info) diff -r 00e26402de03 -r e13103257b33 pidgin-twitter.h --- a/pidgin-twitter.h Sat Aug 23 04:17:49 2008 +0900 +++ b/pidgin-twitter.h Mon Aug 25 21:17:02 2008 +0900 @@ -121,6 +121,10 @@ #define OPT_ICON_MAX_DAYS OPT_PIDGINTWITTER "/icon_max_days" #define OPT_API_BASE_GET_INTERVAL OPT_PIDGINTWITTER "/api_base_get_interval" #define OPT_LOG_OUTPUT OPT_PIDGINTWITTER "/log_output" +#define OPT_FILTER OPT_PIDGINTWITTER "/filter" +#define OPT_FILTER_TWITTER OPT_PIDGINTWITTER "/filter_twitter" +#define OPT_FILTER_WASSR OPT_PIDGINTWITTER "/filter_wassr" +#define OPT_FILTER_IDENTICA OPT_PIDGINTWITTER "/filter_identica" /* formats and templates */ #define RECIPIENT_FORMAT_TWITTER "@%s" @@ -247,5 +251,6 @@ static void combo_changed_cb(gpointer *data); static void disconnect_prefs_cb(GtkObject *object, gpointer data); static GtkWidget *prefs_get_frame(PurplePlugin *plugin); +static void apply_filter(gchar **sender, gchar **buffer, PurpleMessageFlags *flags, int service); #endif diff -r 00e26402de03 -r e13103257b33 prefs.ui --- a/prefs.ui Sat Aug 23 04:17:49 2008 +0900 +++ b/prefs.ui Mon Aug 25 21:17:02 2008 +0900 @@ -453,6 +453,222 @@ + + True + + + True + 0 + 4 + 4 + 4 + + + True + 0 + <b>Filter</b> + True + + + + + False + False + + + + + True + 0 + 20 + + + True + True + Apply filters + 0 + True + + + + + False + False + 2 + 1 + + + + + True + 0 + 4 + 4 + 4 + + + True + 0 + <b>User list for filtering</b> + True + + + + + False + False + 2 + + + + + True + + + True + 20 + + + True + 0 + twitter + 10 + + + + + + + True + 1 + 4 + + + True + True + 35 + + + + + False + False + 1 + + + + + False + False + 2 + 3 + + + + + True + + + True + 20 + + + True + 0 + wassr + + + + + + + True + 1 + 4 + + + True + True + 35 + + + + + False + False + 1 + + + + + False + False + 2 + 4 + + + + + True + + + True + 20 + + + True + 0 + identi.ca + 10 + + + + + + + True + 1 + 4 + + + True + True + 35 + + + + + False + False + 1 + + + + + False + False + 2 + 5 + + + + + 2 + False + + + + + True + <b>Filter</b> + True + + + 2 + False + + + True @@ -498,46 +714,41 @@ True 4 - - True - - - - - - 2 - 3 - - - + + + + + + + + + + + + + - - True - - - - - - 1 - 2 - - + + + + - + + + + True - 20 + 40 - + True - pixel + Icon size - 3 - 4 @@ -564,17 +775,46 @@ - + True - 40 + 20 - + True - Icon size + pixel + 3 + 4 + + + + + + + True + + + + + + 1 + 2 + + + + + + True + + + + + + 2 + 3 @@ -629,72 +869,60 @@ True 6 - - True - - - - - - 1 - 2 - - + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + True - 40 + 20 - + True - Update every + days + 5 + 6 - - True - 4 - - - True - True - 1 - True - True - - - - - 2 - 3 - - - - - - - True - - - True - times or - - - - - 3 - 4 - - - - True 4 @@ -717,23 +945,71 @@ - + True - 20 - + True - days + times or + + + + + 3 + 4 + + + + + + True + 4 + + + True + True + 1 + True + True - 5 - 6 + 2 + 3 + + + True + 40 + + + True + Update every + + + + + + + + + + + True + + + + + + 1 + 2 + + + False @@ -743,7 +1019,7 @@ - 2 + 3 @@ -753,7 +1029,7 @@ True - 4 + 3 False @@ -822,7 +1098,7 @@ True True - 30 + 35 @@ -954,7 +1230,7 @@ True True - 30 + 35 @@ -1025,7 +1301,7 @@ - 3 + 4 @@ -1035,7 +1311,7 @@ True - 3 + 4 False @@ -1170,7 +1446,7 @@ - 4 + 5 @@ -1180,7 +1456,7 @@ True - 4 + 5 False