comparison util.c @ 330:cc41ee1f5d3a

implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Mon, 12 Oct 2009 21:51:13 +0900
parents e2156468f4e5
children b4c846870b3c
comparison
equal deleted inserted replaced
329:300241bd1879 330:cc41ee1f5d3a
1 #include "pidgin-twitter.h" 1 #include "pidgin-twitter.h"
2 2
3 extern GRegex *regp[]; 3 extern GRegex *regp[];
4 extern guint64 reply_to_msgid;
5 extern PurpleAccount *account_for_twitter;
4 6
5 /* prototypes */ 7 /* prototypes */
6 static gchar *twitter_memrchr(const gchar *s, int c, size_t n); 8 static gchar *twitter_memrchr(const gchar *s, int c, size_t n);
9 void fav_with_api(guint64 id);
7 10
8 11
9 /* functions */ 12 /* functions */
10 13
11 /* this function has been taken from autoaccept plugin */ 14 /* this function has been taken from autoaccept plugin */
430 else if(is_ffeed_conv(conv)) 433 else if(is_ffeed_conv(conv))
431 service = ffeed_service; 434 service = ffeed_service;
432 435
433 return service; 436 return service;
434 } 437 }
438
439 gboolean
440 pt_uri_handler(const char *proto, const char *cmd, GHashTable *params)
441 {
442 char *idstr = NULL;
443 const char *acct_id = NULL;
444 PurpleConversation *conv = NULL;
445 PidginConversation *gtkconv = NULL;
446 guint64 msgid = 0;
447 gchar *sender = NULL, *recipient = NULL, *msg = NULL;
448
449 if(g_ascii_strcasecmp(proto, "pt"))
450 return FALSE;
451
452 twitter_debug("params=%p\n", params);
453
454 acct_id = purple_prefs_get_string(OPT_SCREEN_NAME_TWITTER);
455 twitter_debug("acct_id=%s\n", acct_id);
456
457 if(strstr(cmd, "reply-twitter")) {
458 sender = g_hash_table_lookup(params, "user");
459 idstr = g_hash_table_lookup(params, "id");
460 if(idstr)
461 msgid = strtoull(idstr, NULL, 10);
462
463 /* find conv */
464 conv = purple_find_conversation_with_account(
465 PURPLE_CONV_TYPE_ANY, "twitter@twitter.com",
466 account_for_twitter); /* xxx */
467 twitter_debug("conv = %p\n", conv);
468 gtkconv = PIDGIN_CONVERSATION(conv);
469
470 twitter_debug("sender = %s, id = %llu\n", sender, (unsigned long long)msgid);
471
472 recipient = g_strdup_printf("@%s ", sender);
473 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer,
474 recipient, -1);
475
476 gtk_widget_grab_focus(GTK_WIDGET(gtkconv->entry));
477 g_free(recipient);
478 reply_to_msgid = msgid; /* xxx */
479
480 return TRUE;
481 }
482 else if(strstr(cmd, "fav-twitter")) {
483 idstr = g_hash_table_lookup(params, "id");
484 fav_with_api(strtoull(idstr, NULL, 10));
485 return TRUE;
486 }
487 else if(strstr(cmd, "retweet-twitter")) {
488 sender = g_hash_table_lookup(params, "user");
489 idstr = g_hash_table_lookup(params, "id");
490 msg = g_hash_table_lookup(params, "msg");
491 if(idstr)
492 msgid = strtoull(idstr, NULL, 10);
493
494 /* find conv */
495 conv = purple_find_conversation_with_account(
496 PURPLE_CONV_TYPE_ANY, "twitter@twitter.com",
497 account_for_twitter); /* xxx */
498 twitter_debug("conv = %p\n", conv);
499 gtkconv = PIDGIN_CONVERSATION(conv);
500
501 twitter_debug("sender = %s, id = %llu\n", sender, (unsigned long long)msgid);
502
503 recipient = g_strdup_printf("RT @%s: %s", sender, msg);
504 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer,
505 recipient, -1);
506
507 GtkTextIter iter;
508 gtk_text_buffer_get_start_iter(gtkconv->entry_buffer, &iter);
509 gtk_text_buffer_place_cursor(gtkconv->entry_buffer, &iter);
510
511 gtk_widget_grab_focus(GTK_WIDGET(gtkconv->entry));
512 g_free(recipient);
513
514 return TRUE;
515 }
516 return FALSE;
517 }
518
519 void
520 twitter_add_links(gchar **str)
521 {
522 GMatchInfo *match_info = NULL;
523 gchar *tmpstr0 = NULL, *tmpstr = NULL;
524 gchar *newstr = NULL, *match = NULL;
525 gchar *linkstr = NULL;
526 gchar *user = NULL;
527
528 twitter_debug("called\n");
529
530 /* buffer without ptmsgid=123 */
531 tmpstr0 = g_regex_replace(regp[SENDER], *str, -1, 0, "", 0, NULL);
532 tmpstr = g_regex_replace(regp[MESSAGE_ID], tmpstr0, -1, 0, "", 0, NULL);
533 g_free(tmpstr0);
534 tmpstr0 = NULL;
535 twitter_debug("tmpstr = %s\n", tmpstr);
536
537 /* sender */
538 g_regex_match(regp[SENDER], *str, 0, &match_info);
539 if(g_match_info_matches(match_info)) {
540 user = g_match_info_fetch(match_info, 2);
541 twitter_debug("user = %s\n", user);
542 g_match_info_free(match_info);
543 match_info = NULL;
544 }
545
546 /* link string */
547 g_regex_match(regp[MESSAGE_ID], *str, 0, &match_info);
548 if(match_info) {
549 match = g_match_info_fetch(match_info, 1);
550 linkstr = g_strdup_printf(LINK_FORMAT_TWITTER,
551 match, user, /* Reply */
552 match, /* Favorite */
553 match, user, tmpstr); /* Retweet */
554
555 twitter_debug("linkstr = %s\n", linkstr);
556
557 newstr = g_regex_replace(regp[MESSAGE_ID], *str, -1, 0,
558 linkstr,
559 0, NULL);
560
561 twitter_debug("newstr = %s\n", newstr);
562
563 g_free(*str);
564 *str = newstr;
565
566 g_free(linkstr);
567
568 g_free(match);
569 match = NULL;
570
571 g_match_info_free(match_info);
572 match_info = NULL;
573 }
574
575 g_free(user);
576 g_free(tmpstr);
577 }