Changeset ce81acd for protocols/twitter
- Timestamp:
- 2011-03-28T23:28:46Z (14 years ago)
- Branches:
- master
- Children:
- 4f50ea5
- Parents:
- f01bc6f
- Location:
- protocols/twitter
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter.c
rf01bc6f rce81acd 245 245 s->flags |= ACC_SET_OFFLINE_ONLY; 246 246 247 s = set_add( &acc->set, "show_ids", "false", set_eval_bool, acc ); 248 s->flags |= ACC_SET_OFFLINE_ONLY; 249 247 250 s = set_add( &acc->set, "oauth", def_oauth, set_eval_bool, acc ); 248 251 } … … 291 294 imcb_buddy_status( ic, name, OPT_LOGGED_IN, NULL, NULL ); 292 295 296 if( set_getbool( &acc->set, "show_ids" ) ) 297 td->log = g_new0( struct twitter_log_data, TWITTER_LOG_LENGTH ); 298 293 299 imcb_log( ic, "Connecting" ); 294 300 … … 319 325 g_free( td->url_path ); 320 326 g_free( td->pass ); 327 g_free( td->log ); 321 328 g_free( td ); 322 329 } -
protocols/twitter/twitter.h
rf01bc6f rce81acd 38 38 } twitter_flags_t; 39 39 40 struct twitter_log_data; 41 40 42 struct twitter_data 41 43 { … … 56 58 57 59 char *prefix; /* Used to generate contact + channel name. */ 60 61 struct twitter_log_data *log; 62 int log_id; 58 63 }; 59 64 … … 62 67 guint64 last_id; 63 68 time_t last_time; 69 }; 70 71 #define TWITTER_LOG_LENGTH 100 72 struct twitter_log_data 73 { 74 guint64 id; 75 struct bee_user *bu; 64 76 }; 65 77 -
protocols/twitter/twitter_lib.c
rf01bc6f rce81acd 67 67 char *text; 68 68 struct twitter_xml_user *user; 69 guint64 id ;69 guint64 id, reply_to; 70 70 }; 71 71 … … 409 409 { 410 410 txs->id = g_ascii_strtoull (child->text, NULL, 10); 411 } 412 else if (g_strcasecmp( "in_reply_to_status_id", child->name ) == 0) 413 { 414 txs->reply_to = g_ascii_strtoull (child->text, NULL, 10); 411 415 } 412 416 } … … 502 506 } 503 507 508 static char *twitter_msg_add_id(struct im_connection *ic, 509 struct twitter_xml_status *txs, const char *prefix) 510 { 511 struct twitter_data *td = ic->proto_data; 512 char *ret = NULL; 513 514 if (!set_getbool(&ic->acc->set, "show_ids")) 515 { 516 if (*prefix) 517 return g_strconcat(prefix, txs->text, NULL); 518 else 519 return NULL; 520 } 521 522 td->log[td->log_id].id = txs->id; 523 td->log[td->log_id].bu = bee_user_by_handle(ic->bee, ic, txs->user->screen_name); 524 if (txs->reply_to) 525 { 526 int i; 527 for (i = 0; i < TWITTER_LOG_LENGTH; i ++) 528 if (td->log[i].id == txs->reply_to) 529 { 530 ret = g_strdup_printf( "\002[\002%02d->%02d\002]\002 %s%s", 531 td->log_id, i, prefix, txs->text); 532 break; 533 } 534 } 535 if (ret == NULL) 536 ret = g_strdup_printf( "\002[\002%02d\002]\002 %s%s", 537 td->log_id, prefix, txs->text); 538 td->log_id = (td->log_id + 1) % TWITTER_LOG_LENGTH; 539 540 return ret; 541 } 542 504 543 static void twitter_groupchat_init(struct im_connection *ic) 505 544 { … … 543 582 for ( l = list; l ; l = g_slist_next(l) ) 544 583 { 584 char *msg; 585 545 586 status = l->data; 546 587 if (status->user == NULL || status->text == NULL) … … 550 591 551 592 strip_html(status->text); 593 msg = twitter_msg_add_id(ic, status, ""); 552 594 553 595 // Say it! 554 596 if (g_strcasecmp(td->user, status->user->screen_name) == 0) 555 imcb_chat_log (gc, "You: %s",status->text);597 imcb_chat_log(gc, "You: %s", msg ? msg : status->text); 556 598 else 557 imcb_chat_msg (gc, status->user->screen_name, status->text, 0, status->created_at ); 599 imcb_chat_msg(gc, status->user->screen_name, 600 msg ? msg : status->text, 0, status->created_at ); 601 602 g_free(msg); 558 603 559 604 // Update the home_timeline_id to hold the highest id, so that by the next request 560 // we won't pick up the updates al lready in the list.561 td->home_timeline_id = td->home_timeline_id < status->id ? status->id : td->home_timeline_id;605 // we won't pick up the updates already in the list. 606 td->home_timeline_id = MAX(td->home_timeline_id, status->id); 562 607 } 563 608 } … … 584 629 for ( l = list; l ; l = g_slist_next(l) ) 585 630 { 586 char * text = NULL;631 char *prefix = NULL, *text = NULL; 587 632 588 633 status = l->data; … … 590 635 strip_html( status->text ); 591 636 if( mode_one ) 592 text = g_strdup_printf( "\002<\002%s\002>\002 %s",593 status->user->screen_name, status->text);637 prefix = g_strdup_printf("\002<\002%s\002>\002 ", 638 status->user->screen_name); 594 639 else 595 640 twitter_add_buddy(ic, status->user->screen_name, status->user->name); 596 641 642 text = twitter_msg_add_id(ic, status, prefix ? prefix : ""); 643 597 644 imcb_buddy_msg( ic, 598 645 mode_one ? from : status->user->screen_name, 599 mode_one? text : status->text,646 text ? text : status->text, 600 647 0, status->created_at ); 601 648 602 649 // Update the home_timeline_id to hold the highest id, so that by the next request 603 // we won't pick up the updates al lready in the list.604 td->home_timeline_id = td->home_timeline_id < status->id ? status->id : td->home_timeline_id;650 // we won't pick up the updates already in the list. 651 td->home_timeline_id = MAX(td->home_timeline_id, status->id); 605 652 606 653 g_free( text ); 654 g_free( prefix ); 607 655 } 608 656 }
Note: See TracChangeset
for help on using the changeset viewer.