Mercurial > pidgin-twitter
comparison pidgin-twitter.c @ 220:1ebef23bbccb
- made parrot buffers lists so that delayed echo back message can be properly blocked.
- reduced the frequency of scanning lists.
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Sun, 31 Aug 2008 15:01:02 +0900 |
parents | 739ed7a4426c |
children | b5fa0c295ff5 |
comparison
equal
deleted
inserted
replaced
219:739ed7a4426c | 220:1ebef23bbccb |
---|---|
30 static gboolean suppress_oops = FALSE; | 30 static gboolean suppress_oops = FALSE; |
31 static GHashTable *icon_hash[NUM_SERVICES]; | 31 static GHashTable *icon_hash[NUM_SERVICES]; |
32 static GHashTable *conv_hash = NULL; | 32 static GHashTable *conv_hash = NULL; |
33 static GList *statuseslist = NULL; | 33 static GList *statuseslist = NULL; |
34 static GList *postedlist = NULL; | 34 static GList *postedlist = NULL; |
35 static gchar *wassr_post = NULL; | 35 static GList *wassr_parrot_list = NULL; |
36 static gchar *identica_post = NULL; | 36 static GList *identica_parrot_list = NULL; |
37 #ifdef _WIN32 | 37 #ifdef _WIN32 |
38 static gboolean blink_state = FALSE; | 38 static gboolean blink_state = FALSE; |
39 static gboolean blink_modified = FALSE; | 39 static gboolean blink_modified = FALSE; |
40 #endif | 40 #endif |
41 | 41 |
451 } | 451 } |
452 | 452 |
453 static gboolean | 453 static gboolean |
454 is_posted_message(status_t *status, guint lastid) | 454 is_posted_message(status_t *status, guint lastid) |
455 { | 455 { |
456 GList *pp; | 456 GList *pp = g_list_first(postedlist); |
457 gboolean rv = FALSE; | 457 gboolean rv = FALSE; |
458 | 458 |
459 for(pp = postedlist; pp; pp=pp->next) { | 459 while(pp) { |
460 GList *next; | |
460 status_t *posted = (status_t *)pp->data; | 461 status_t *posted = (status_t *)pp->data; |
462 | |
463 next = g_list_next(pp); | |
464 | |
461 if(posted->id == status->id) { | 465 if(posted->id == status->id) { |
462 rv = TRUE; | 466 rv = TRUE; |
463 } | 467 } |
464 | 468 |
465 if(posted->id <= lastid) { | 469 if(posted->id <= lastid) { |
466 free_status(posted); | 470 free_status(posted); |
467 g_free(pp->data); | 471 g_free(pp->data); |
468 pp->data = NULL; | 472 postedlist = g_list_delete_link(postedlist, pp); |
469 } | 473 } |
470 } | 474 |
471 | 475 pp = next; |
472 postedlist = g_list_remove_all(postedlist, NULL); | 476 } |
473 | 477 |
474 return rv; | 478 return rv; |
475 } | 479 } |
476 | 480 |
477 static void | 481 static void |
528 | 532 |
529 xmlFreeDoc(doc); | 533 xmlFreeDoc(doc); |
530 xmlCleanupParser(); | 534 xmlCleanupParser(); |
531 | 535 |
532 /* process statuseslist */ | 536 /* process statuseslist */ |
533 for(stp = statuseslist; stp; stp=stp->next) { | 537 stp = g_list_first(statuseslist); |
538 while(stp) { | |
539 GList *next; | |
534 status_t *st = (status_t *)stp->data; | 540 status_t *st = (status_t *)stp->data; |
541 | |
542 next = g_list_next(stp); | |
535 | 543 |
536 if(st->id > lastid && !is_posted_message(st, lastid)) { | 544 if(st->id > lastid && !is_posted_message(st, lastid)) { |
537 gchar *msg = NULL; | 545 gchar *msg = NULL; |
538 gchar *sender = NULL; | 546 gchar *sender = NULL; |
539 | 547 |
559 g_free(msg); | 567 g_free(msg); |
560 } | 568 } |
561 | 569 |
562 free_status(st); | 570 free_status(st); |
563 g_free(stp->data); | 571 g_free(stp->data); |
564 stp->data = NULL; | 572 statuseslist = g_list_delete_link(statuseslist, stp); |
573 | |
574 stp = next; | |
565 } | 575 } |
566 | |
567 statuseslist = g_list_remove_all(statuseslist, NULL); | |
568 } | 576 } |
569 | 577 |
570 /* status fetching function. it will be called periodically. */ | 578 /* status fetching function. it will be called periodically. */ |
571 static gboolean | 579 static gboolean |
572 get_status_with_api(gpointer data) | 580 get_status_with_api(gpointer data) |
611 g_free(request); | 619 g_free(request); |
612 | 620 |
613 return TRUE; | 621 return TRUE; |
614 } | 622 } |
615 | 623 |
616 /***************************/ | 624 /****************************/ |
617 /* API base post functions */ | 625 /* API based post functions */ |
618 /***************************/ | 626 /****************************/ |
619 static void | 627 static void |
620 post_status_with_api_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, | 628 post_status_with_api_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, |
621 const gchar *url_text, size_t len, | 629 const gchar *url_text, size_t len, |
622 const gchar *error_message) | 630 const gchar *error_message) |
623 { | 631 { |
827 #endif | 835 #endif |
828 plain = tmp; | 836 plain = tmp; |
829 | 837 |
830 if(wassr_ac) { | 838 if(wassr_ac) { |
831 /* store sending message to address parrot problem */ | 839 /* store sending message to address parrot problem */ |
832 g_utf8_strncpy(wassr_post, plain, WASSR_POST_LEN); | 840 wassr_parrot_list = |
841 g_list_prepend(wassr_parrot_list, g_strdup(plain)); | |
833 twitter_debug("wassr parrot pushed:%s\n", plain); | 842 twitter_debug("wassr parrot pushed:%s\n", plain); |
834 } | 843 } |
835 else if(identica_ac) { | 844 else if(identica_ac) { |
836 /* store sending message to address parrot problem */ | 845 /* store sending message to address parrot problem */ |
837 g_utf8_strncpy(identica_post, plain, IDENTICA_POST_LEN); | 846 identica_parrot_list = |
847 g_list_prepend(identica_parrot_list, g_strdup(plain)); | |
838 twitter_debug("identica parrot pushed:%s\n", plain); | 848 twitter_debug("identica parrot pushed:%s\n", plain); |
839 } | 849 } |
840 | 850 |
841 g_free(*buffer); | 851 g_free(*buffer); |
842 *buffer = g_markup_escape_text(plain, -1); | 852 *buffer = g_markup_escape_text(plain, -1); |
1246 | 1256 |
1247 if(data->request_list) | 1257 if(data->request_list) |
1248 mark_list = data->request_list; | 1258 mark_list = data->request_list; |
1249 | 1259 |
1250 /* remove the marks in its GtkTextBuffers */ | 1260 /* remove the marks in its GtkTextBuffers */ |
1251 for(current = g_list_first(mark_list); current; | 1261 current = g_list_first(mark_list); |
1252 current = g_list_next(current)) { | 1262 while(current) { |
1253 GtkTextMark *current_mark = current->data; | 1263 GtkTextMark *current_mark = current->data; |
1254 GtkTextBuffer *current_text_buffer = gtk_text_mark_get_buffer( | 1264 GtkTextBuffer *current_text_buffer = |
1255 current_mark); | 1265 gtk_text_mark_get_buffer(current_mark); |
1266 GList *next; | |
1267 | |
1268 next = g_list_next(current); | |
1256 | 1269 |
1257 if(!current_text_buffer) | 1270 if(!current_text_buffer) |
1258 continue; | 1271 continue; |
1259 | 1272 |
1260 if(text_buffer) { | 1273 if(text_buffer) { |
1261 if(current_text_buffer == text_buffer) { | 1274 if(current_text_buffer == text_buffer) { |
1262 /* the mark will be freed in this function */ | 1275 /* the mark will be freed in this function */ |
1263 gtk_text_buffer_delete_mark(current_text_buffer, | 1276 gtk_text_buffer_delete_mark(current_text_buffer, |
1264 current_mark); | 1277 current_mark); |
1265 current->data = NULL; | 1278 current->data = NULL; |
1279 mark_list = g_list_delete_link(mark_list, current); | |
1266 } | 1280 } |
1267 } | 1281 } |
1268 else { | 1282 else { |
1269 gtk_text_buffer_delete_mark(current_text_buffer, current_mark); | 1283 gtk_text_buffer_delete_mark(current_text_buffer, current_mark); |
1270 current->data = NULL; | 1284 current->data = NULL; |
1271 } | 1285 mark_list = g_list_delete_link(mark_list, current); |
1272 } /* end of for */ | 1286 } |
1273 | 1287 |
1274 mark_list = g_list_remove_all(mark_list, NULL); | 1288 current = next; |
1289 } | |
1290 | |
1275 data->request_list = mark_list; | 1291 data->request_list = mark_list; |
1276 } | 1292 } |
1277 | 1293 |
1278 static void | 1294 static void |
1279 delete_requested_icon_marks(PidginConversation *conv, GHashTable *table) { | 1295 delete_requested_icon_marks(PidginConversation *conv, GHashTable *table) { |
1661 twitter_debug("clearing sender and buffer\n"); | 1677 twitter_debug("clearing sender and buffer\n"); |
1662 g_free(*sender); *sender = NULL; | 1678 g_free(*sender); *sender = NULL; |
1663 g_free(*buffer); *buffer = NULL; | 1679 g_free(*buffer); *buffer = NULL; |
1664 } | 1680 } |
1665 /* discard parrot message */ | 1681 /* discard parrot message */ |
1666 else if(wassr_post && | 1682 else { |
1667 strlen(wassr_post) && | 1683 GList *current = g_list_first(wassr_parrot_list); |
1668 strstr(stripped, wassr_post)) { | 1684 while(current) { |
1669 twitter_debug("parrot clearing: buf = %s post = %s\n", *buffer, wassr_post); | 1685 GList *next = g_list_next(current); |
1670 g_free(*sender); *sender = NULL; | 1686 |
1671 g_free(*buffer); *buffer = NULL; | 1687 if(strstr(stripped, current->data)) { |
1688 twitter_debug("parrot clearing: buf = %s post = %s\n", | |
1689 *buffer, (char *)current->data); | |
1690 g_free(*sender); *sender = NULL; | |
1691 g_free(*buffer); *buffer = NULL; | |
1692 g_free(current->data); | |
1693 current->data = NULL; | |
1694 wassr_parrot_list = | |
1695 g_list_delete_link(wassr_parrot_list, current); | |
1696 break; | |
1697 } | |
1698 | |
1699 current = next; | |
1700 } | |
1672 } | 1701 } |
1673 g_free(stripped); | 1702 g_free(stripped); |
1674 } | 1703 } |
1675 | 1704 |
1676 if(service == identica_service) { | 1705 if(service == identica_service) { |
1677 /* discard parrot message */ | 1706 /* discard parrot message */ |
1678 gchar *stripped = strip_html_markup(*buffer); | 1707 gchar *stripped = strip_html_markup(*buffer); |
1679 if(identica_post && | 1708 GList *current = g_list_first(identica_parrot_list); |
1680 strlen(identica_post) && | 1709 while(current) { |
1681 strstr(stripped, identica_post)) { | 1710 GList *next = g_list_next(current); |
1682 twitter_debug("identica parrot clearing: buf = %s post = %s\n", | 1711 |
1683 *buffer, identica_post); | 1712 if(strstr(stripped, current->data)) { |
1684 g_free(*sender); *sender = NULL; | 1713 twitter_debug("identica parrot clearing: buf = %s post = %s\n", |
1685 g_free(*buffer); *buffer = NULL; | 1714 *buffer, (char *)current->data); |
1715 g_free(*sender); *sender = NULL; | |
1716 g_free(*buffer); *buffer = NULL; | |
1717 g_free(current->data); | |
1718 current->data = NULL; | |
1719 identica_parrot_list = | |
1720 g_list_delete_link(identica_parrot_list, current); | |
1721 break; | |
1722 } | |
1723 | |
1724 current = next; | |
1686 } | 1725 } |
1687 g_free(stripped); | 1726 g_free(stripped); |
1688 } | 1727 } |
1689 | 1728 |
1690 /* filtering */ | 1729 /* filtering */ |
2325 if(!data) { | 2364 if(!data) { |
2326 data = g_new0(icon_data, 1); | 2365 data = g_new0(icon_data, 1); |
2327 g_hash_table_insert(hash, g_strdup(user_name), data); | 2366 g_hash_table_insert(hash, g_strdup(user_name), data); |
2328 } | 2367 } |
2329 | 2368 |
2330 data->request_list = g_list_append(data->request_list, mark); | 2369 data->request_list = g_list_prepend(data->request_list, mark); |
2331 } | 2370 } |
2332 | 2371 |
2333 static gboolean | 2372 static gboolean |
2334 displaying_im_cb(PurpleAccount *account, const char *who, char **message, | 2373 displaying_im_cb(PurpleAccount *account, const char *who, char **message, |
2335 PurpleConversation *conv, PurpleMessageFlags flags, | 2374 PurpleConversation *conv, PurpleMessageFlags flags, |
2575 /* attach counter to the existing twitter window */ | 2614 /* attach counter to the existing twitter window */ |
2576 if(purple_prefs_get_bool(OPT_COUNTER)) { | 2615 if(purple_prefs_get_bool(OPT_COUNTER)) { |
2577 attach_to_window(); | 2616 attach_to_window(); |
2578 } | 2617 } |
2579 | 2618 |
2580 /* allocate wassr_post */ | |
2581 wassr_post = g_new0(gchar, 4 * WASSR_POST_LEN + 1); | |
2582 | |
2583 /* allocate identica_post */ | |
2584 identica_post = g_new0(gchar, 4 * IDENTICA_POST_LEN + 1); | |
2585 | |
2586 return TRUE; | 2619 return TRUE; |
2587 } | 2620 } |
2588 | 2621 |
2589 static void | 2622 static void |
2590 cancel_fetch_func(gpointer key, gpointer value, gpointer user_data) | 2623 cancel_fetch_func(gpointer key, gpointer value, gpointer user_data) |
2613 | 2646 |
2614 static gboolean | 2647 static gboolean |
2615 unload_plugin(PurplePlugin *plugin) | 2648 unload_plugin(PurplePlugin *plugin) |
2616 { | 2649 { |
2617 int i; | 2650 int i; |
2651 GList *current; | |
2618 | 2652 |
2619 twitter_debug("called\n"); | 2653 twitter_debug("called\n"); |
2620 | 2654 |
2621 /* disconnect from signal */ | 2655 /* disconnect from signal */ |
2622 purple_signal_disconnect(purple_conversations_get_handle(), | 2656 purple_signal_disconnect(purple_conversations_get_handle(), |
2662 g_hash_table_destroy(conv_hash); | 2696 g_hash_table_destroy(conv_hash); |
2663 | 2697 |
2664 /* detach from twitter window */ | 2698 /* detach from twitter window */ |
2665 detach_from_window(); | 2699 detach_from_window(); |
2666 | 2700 |
2667 /* free wassr_post */ | 2701 /* free wassr_parrot_list */ |
2668 g_free(wassr_post); | 2702 current = g_list_first(wassr_parrot_list); |
2669 wassr_post = NULL; | 2703 while(current) { |
2670 | 2704 GList *next; |
2671 /* free identica_post */ | 2705 |
2672 g_free(identica_post); | 2706 next = g_list_next(current); |
2673 identica_post = NULL; | 2707 g_free(current->data); |
2708 wassr_parrot_list = | |
2709 g_list_delete_link(wassr_parrot_list, current); | |
2710 | |
2711 current = next; | |
2712 } | |
2713 g_list_free(wassr_parrot_list); | |
2714 wassr_parrot_list = NULL; | |
2715 | |
2716 /* free identica_parot_list */ | |
2717 current = g_list_first(identica_parrot_list); | |
2718 while(current) { | |
2719 GList *next; | |
2720 | |
2721 next = g_list_next(current); | |
2722 g_free(current->data); | |
2723 identica_parrot_list = | |
2724 g_list_delete_link(identica_parrot_list, current); | |
2725 | |
2726 current = next; | |
2727 } | |
2728 g_list_free(identica_parrot_list); | |
2729 identica_parrot_list = NULL; | |
2674 | 2730 |
2675 return TRUE; | 2731 return TRUE; |
2676 } | 2732 } |
2677 | 2733 |
2678 static void | 2734 static void |