void TwitterProto::UpdateStatuses(bool pre_read,bool popups) { try { ScopedLock s(twitter_lock_); twitter::status_list updates = twit_.get_statuses(200,since_id_); s.Unlock(); if(!updates.empty()) since_id_ = std::max(since_id_, updates[0].status.id); for(twitter::status_list::reverse_iterator i=updates.rbegin(); i!=updates.rend(); ++i) { if(!pre_read && in_chat_) UpdateChat(*i); if(i->username == twit_.get_username()) continue; HANDLE hContact = AddToClientList(i->username.c_str(),""); DBEVENTINFO dbei = {sizeof(dbei)}; dbei.pBlob = (BYTE*)(i->status.text.c_str()); dbei.cbBlob = i->status.text.size()+1; dbei.eventType = TWITTER_DB_EVENT_TYPE_TWEET; dbei.flags = DBEF_UTF; //dbei.flags = DBEF_READ; dbei.timestamp = static_cast<DWORD>(i->status.time); dbei.szModule = m_szModuleName; CallService(MS_DB_EVENT_ADD, (WPARAM)hContact, (LPARAM)&dbei); DBWriteContactSettingUTF8String(hContact,"CList","StatusMsg", i->status.text.c_str()); if(!pre_read && popups) ShowContactPopup(hContact,i->status.text); } db_pod_set(0,m_szModuleName,TWITTER_KEY_SINCEID,since_id_); LOG("***** Status messages updated"); } catch(const bad_response &) { LOG("***** Bad response from server, signing off"); SetStatus(ID_STATUS_OFFLINE); } catch(const std::exception &e) { ShowPopup( (std::string("While updating status messages, an error occurred: ") +e.what()).c_str() ); LOG("***** Error updating status messages: %s",e.what()); } }
int CIcqProto::setSettingStringUtf(HANDLE hContact, const char *szModule, const char *szSetting, const char *szValue) { return DBWriteContactSettingUTF8String(hContact, szModule, szSetting, (char*)szValue); }
bool facebook_client::home( ) { handle_entry( "home" ); http::response resp = flap( FACEBOOK_REQUEST_HOME ); // Process result data validate_response(&resp); switch ( resp.code ) { case HTTP_CODE_OK: { if ( resp.data.find( "id=\"navAccountName\"" ) != std::string::npos ) { // Backup for old fb version // Get real_name this->self_.real_name = utils::text::remove_html( utils::text::special_expressions_decode( utils::text::source_get_value( &resp.data, 2, " id=\"navAccountName\">", "</a" ) ) ); DBWriteContactSettingUTF8String(NULL,parent->m_szModuleName,FACEBOOK_KEY_NAME,this->self_.real_name.c_str()); DBWriteContactSettingUTF8String(NULL,parent->m_szModuleName,FACEBOOK_KEY_NICK,this->self_.real_name.c_str()); parent->Log(" Got self real name: %s", this->self_.real_name.c_str()); } else if ( resp.data.find("id=\"pageNav\"") != std::string::npos ) { // Get real_name this->self_.real_name = utils::text::remove_html( utils::text::special_expressions_decode( utils::text::source_get_value( &resp.data, 3, " class=\"headerTinymanName\"", ">", "</a" ) ) ); DBWriteContactSettingUTF8String(NULL,parent->m_szModuleName,FACEBOOK_KEY_NAME,this->self_.real_name.c_str()); DBWriteContactSettingUTF8String(NULL,parent->m_szModuleName,FACEBOOK_KEY_NICK,this->self_.real_name.c_str()); parent->Log(" Got self real name: %s", this->self_.real_name.c_str()); } else { client_notify(TranslateT("Something happened to Facebook. Maybe there was some major update so you should wait for an update.")); return handle_error( "home", FORCE_DISCONNECT ); } // Get avatar std::string avatar = utils::text::source_get_value( &resp.data, 3, "class=\\\"fbxWelcomeBoxImg", "src=\\\"", "\\\"" ); if (avatar.empty()) avatar = utils::text::source_get_value( &resp.data, 3, "class=\"fbxWelcomeBoxImg", "src=\"", "\"" ); this->self_.image_url = utils::text::trim( utils::text::special_expressions_decode( avatar ) ); parent->Log(" Got self avatar: %s", this->self_.image_url.c_str()); parent->CheckAvatarChange(NULL, this->self_.image_url); // Get post_form_id this->post_form_id_ = utils::text::source_get_value( &resp.data, 3, "name=\"post_form_id\"", "value=\"", "\"" ); parent->Log(" Got self post form id: %s", this->post_form_id_.c_str()); // Get dtsg this->dtsg_ = utils::text::source_get_value( &resp.data, 3, "name=\"fb_dtsg\"", "value=\"", "\"" ); parent->Log(" Got self dtsg: %s", this->dtsg_.c_str()); // Get logout hash this->logout_hash_ = utils::text::source_get_value( &resp.data, 2, "<input type=\"hidden\" autocomplete=\"off\" name=\"h\" value=\"", "\"" ); parent->Log(" Got self logout hash: %s", this->logout_hash_.c_str()); // TODO: DIrectly get that friend requests // Get friend requests count and notify it std::string str_count = utils::text::source_get_value( &resp.data, 2, "<span id=\"requestsCountValue\">", "</span>" ); if ( str_count.length() && str_count != std::string( "0" ) ) { std::string message = Translate("Got new friend requests: ") + str_count; TCHAR* tmessage = mir_a2t(message.c_str()); parent->NotifyEvent( parent->m_tszUserName, tmessage, NULL, FACEBOOK_EVENT_OTHER, TEXT(FACEBOOK_URL_REQUESTS) ); mir_free( tmessage ); } if (!DBGetContactSettingByte(NULL,parent->m_szModuleName,FACEBOOK_KEY_PARSE_MESSAGES, DEFAULT_PARSE_MESSAGES)) { str_count = utils::text::source_get_value( &resp.data, 2, "<span id=\"messagesCountValue\">", "</span>" ); if ( str_count.length() && str_count != std::string( "0" ) ) { std::string message = Translate("Got new messages: ") + str_count; TCHAR* tmessage = mir_a2t(message.c_str()); parent->NotifyEvent( parent->m_tszUserName, tmessage, NULL, FACEBOOK_EVENT_OTHER, TEXT(FACEBOOK_URL_MESSAGES) ); mir_free( tmessage ); } } str_count = utils::text::source_get_value( &resp.data, 2, "<span id=\"notificationsCountValue\">", "</span>" ); if ( str_count.length() && str_count != std::string( "0" ) ) { // Parse notifications directly to popups ForkThread( &FacebookProto::ProcessNotifications, this->parent, NULL ); } if (DBGetContactSettingByte(NULL, parent->m_szModuleName, FACEBOOK_KEY_ENABLE_GROUPCHATS, DEFAULT_ENABLE_GROUPCHATS)) { // Get group chats std::string favorites = utils::text::source_get_value( &resp.data, 2, "<div id=\"leftCol\"", "<div id=\"contentCol\"" ); std::string::size_type pos = 0; while ((pos = favorites.find("href=\"/groups/",pos)) != std::string::npos) { pos += 14; std::string item = favorites.substr(pos, favorites.find("</a>", pos) - pos); std::string id = item.substr(0, item.find("/")); if (!id.empty()) { std::string name = utils::text::source_get_value( &item, 3, "class=\"linkWrap", ">", "</div>" ); name = utils::text::special_expressions_decode(utils::text::slashu_to_utf8( name ) ); parent->Log(" Got new group chat: %s (id: %s)", name.c_str(), id.c_str()); if (!name.empty()) parent->AddChat(id.c_str(), name.c_str()); } } } return handle_success( "home" ); } case HTTP_CODE_FOUND: // Work-around for replica_down, f**king hell what's that? parent->Log(" REPLICA_DOWN is back in force!"); return this->home(); default: return handle_error( "home", FORCE_DISCONNECT ); } }