示例#1
0
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());
	}
}
示例#2
0
void TwitterProto::UpdateMessages(bool pre_read)
{
	try
	{
		ScopedLock s(twitter_lock_);
		twitter::status_list messages = twit_.get_direct(dm_since_id_);
		s.Unlock();

		if(messages.size())
			dm_since_id_ = std::max(dm_since_id_, messages[0].status.id);

		for(twitter::status_list::reverse_iterator i=messages.rbegin(); i!=messages.rend(); ++i)
		{
			HANDLE hContact = AddToClientList(i->username.c_str(),"");

			PROTORECVEVENT recv = {};
			CCSDATA ccs = {};

			recv.flags = PREF_UTF;
			if(pre_read)
				recv.flags |= PREF_CREATEREAD;
			recv.szMessage = const_cast<char*>(i->status.text.c_str());
			recv.timestamp = static_cast<DWORD>(i->status.time);

			ccs.hContact = hContact;
			ccs.szProtoService = PSR_MESSAGE;
			ccs.wParam = ID_STATUS_ONLINE;
			ccs.lParam = reinterpret_cast<LPARAM>(&recv);
			CallService(MS_PROTO_CHAINRECV,0,reinterpret_cast<LPARAM>(&ccs));
		}

		db_pod_set(0,m_szModuleName,TWITTER_KEY_DMSINCEID,dm_since_id_);
		LOG("***** Direct 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 direct messages, an error occurred: ")
			+e.what()).c_str() );
		LOG("***** Error updating direct messages: %s",e.what());
	}
}
示例#3
0
void TwitterProto::UpdateMessages(bool pre_read)
{
	try
	{
		ScopedLock s(twitter_lock_);
		twitter::status_list messages = twit_.get_direct(dm_since_id_);
		s.Unlock();

		if(messages.size())
			dm_since_id_ = std::max(dm_since_id_, messages[0].status.id);

		for(twitter::status_list::reverse_iterator i=messages.rbegin(); i!=messages.rend(); ++i)
		{
			HANDLE hContact = AddToClientList(i->username.c_str(),"");

			PROTORECVEVENT recv = { 0 };
			recv.flags = PREF_UTF;
			if(pre_read)
				recv.flags |= PREF_CREATEREAD;
			recv.szMessage = const_cast<char*>(i->status.text.c_str());
			recv.timestamp = static_cast<DWORD>(i->status.time);
			ProtoChainRecvMsg(hContact, &recv);
		}

		db_pod_set(0,m_szModuleName,TWITTER_KEY_DMSINCEID,dm_since_id_);
		disconnectionCount = 0;
		debugLogA( _T("***** Direct messages updated"));
	}
	catch(const bad_response &)
	{
		++disconnectionCount;
		debugLogA( _T("***** UpdateMessages - Bad response from server, this has happened %d time(s)"), disconnectionCount);
		if (disconnectionCount > 2) {
			debugLogA( _T("***** UpdateMessages - Too many bad responses from the server, signing off"));
			SetStatus(ID_STATUS_OFFLINE);
		}
	}
	catch(const std::exception &e)
	{
		ShowPopup( (std::string("While updating direct messages, an error occurred: ")+e.what()).c_str());
		debugLogA( _T("***** Error updating direct messages: %s"), e.what());
	}
}
示例#4
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());
	}
}