示例#1
0
MCONTACT TwitterProto::AddToClientList(const char *name, const char *status)
{
	// First, check if this contact exists
	MCONTACT hContact = UsernameToHContact(name);
	if (hContact)
		return hContact;

	if (in_chat_)
		AddChatContact(name);

	// If not, make a new contact!
	hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
	if (hContact) {
		if (Proto_AddToContact(hContact, m_szModuleName) == 0) {
			setString(hContact, TWITTER_KEY_UN, name);
			setWord(hContact, "Status", ID_STATUS_ONLINE);
			db_set_utf(hContact, "CList", "StatusMsg", status);

			std::string url = profile_base_url(twit_.get_base_url()) + http::url_encode(name);
			setString(hContact, "Homepage", url.c_str());

			DBVARIANT dbv;
			if (!getTString(TWITTER_KEY_GROUP, &dbv)) {
				db_set_ts(hContact, "CList", "Group", dbv.ptszVal);
				db_free(&dbv);
			}

			return hContact;
		}
		CallService(MS_DB_CONTACT_DELETE, hContact, 0);
	}

	return 0;
}
示例#2
0
int TwitterProto::OnChatOutgoing(WPARAM, LPARAM lParam)
{
	GCHOOK *hook = reinterpret_cast<GCHOOK*>(lParam);
	if (mir_strcmp(hook->pDest->pszModule, m_szModuleName))
		return 0;

	switch (hook->pDest->iType) {
	case GC_USER_MESSAGE:
		debugLog(_T("**Chat - Outgoing message: %s"), hook->ptszText);
		{
			T2Utf text(hook->ptszText);

			std::string tweet(text);
			replaceAll(tweet, "%%", "%"); // the chat plugin will turn "%" into "%%", so we have to change it back :/

			char *varTweet = mir_strdup(tweet.c_str());
			ForkThread(&TwitterProto::SendTweetWorker, varTweet);
		}
		break;

	case GC_USER_PRIVMESS:
	{
		ptrA text(mir_t2a(hook->ptszUID));
		CallService(MS_MSG_SENDMESSAGE, WPARAM(UsernameToHContact(text)), 0);
	}
	break;
	}

	return 0;
}
示例#3
0
void TwitterProto::UpdateChat(const twitter_user &update)
{
	GCDEST gcd = { m_szModuleName, m_tszUserName, GC_EVENT_MESSAGE };
	GCEVENT gce = { sizeof(gce), &gcd };
	gce.pDest = &gcd;
	gce.bIsMe = (update.username == twit_.get_username());
	gce.dwFlags = GCEF_ADDTOLOG;
	gce.ptszUID = mir_a2t(update.username.c_str());
	//TODO: write code here to replace % with %% in update.status.text (which is a std::string)

	std::string chatText = update.status.text;

	replaceAll(chatText, "%", "%%");

	gce.ptszText = mir_a2t_cp(chatText.c_str(), CP_UTF8);
	//gce.ptszText = mir_a2t_cp(update.status.text.c_str(),CP_UTF8);
	gce.time = static_cast<DWORD>(update.status.time);

	DBVARIANT nick;
	MCONTACT hContact = UsernameToHContact(update.username.c_str());
	if (hContact && !db_get_s(hContact, "CList", "MyHandle", &nick)) {
		gce.ptszNick = mir_a2t(nick.pszVal);
		db_free(&nick);
	}
	else
		gce.ptszNick = mir_a2t(update.username.c_str());

	CallServiceSync(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce));

	mir_free(const_cast<TCHAR*>(gce.ptszNick));
	mir_free(const_cast<TCHAR*>(gce.ptszUID));
	mir_free(const_cast<TCHAR*>(gce.ptszText));
}
示例#4
0
void TwitterProto::AddToListWorker(void *pArg)
{
	// TODO: what happens if there is an error?
	if (pArg == 0)
		return;

	char *name = static_cast<char*>(pArg);

	try {
		twitter_user user;
		{
			mir_cslock s(twitter_lock_);
			user = twit_.add_friend(name);
		}

		MCONTACT hContact = UsernameToHContact(name);
		UpdateAvatar(hContact, user.profile_image_url);
	}
	catch (const std::exception &e) {
		ShowPopup((std::string("While adding a friend, an error occurred: ") + e.what()).c_str());
		debugLogA("***** Error adding friend: %s", e.what());
	}
	mir_free(name);
}