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());
	}
}
Exemple #2
0
void TwitterProto::UpdateStatuses(bool pre_read, bool popups, bool tweetToMsg)
{
	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(),"");
			UpdateAvatar(hContact,i->profile_image_url); // as UpdateFriends() doesn't work at the moment, i'm going to update the avatars here

			// i think we maybe should just do that DBEF_READ line instead of stopping ALL this code.  have to test.
			if (tweetToMsg) {
				DBEVENTINFO dbei = {sizeof(dbei)};
				dbei.pBlob = (BYTE*)(i->status.text.c_str());
				dbei.cbBlob = (int)i->status.text.size()+1;
				dbei.eventType = TWITTER_DB_EVENT_TYPE_TWEET;
				dbei.flags = DBEF_UTF | DBEF_READ;
				dbei.timestamp = static_cast<DWORD>(i->status.time);
				dbei.szModule = m_szModuleName;
				db_event_add(hContact, &dbei);
			}

			db_set_utf(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_);
		disconnectionCount = 0;
		debugLogA( _T("***** Status messages updated"));
	}
	catch(const bad_response &)
	{
		++disconnectionCount;
		debugLogA( _T("***** UpdateStatuses - Bad response from server, this has happened %d time(s)"), disconnectionCount);
		if (disconnectionCount > 2) {
			debugLogA( _T("***** UpdateStatuses - Too many bad responses from the 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());
		debugLogA( _T("***** Error updating status messages: %s"), e.what());
	}
}