Beispiel #1
0
void CVkProto::AddFeedSpecialUser()
{
	bool bSpecialContact = m_bNewsEnabled || m_bNotificationsEnabled || m_bSpecialContactAlwaysEnabled;
	
	MCONTACT hContact = FindUser(VK_FEED_USER);
	if (!bSpecialContact) {
		if (hContact)
			CallService(MS_DB_CONTACT_DELETE, (WPARAM)hContact);
		return;
	}
	
	if (!hContact) {
		hContact = FindUser(VK_FEED_USER, true);

		setTString(hContact, "Nick", TranslateT("VKontakte"));
		CMString tszUrl = _T("https://vk.com/press/Simple.png");
		SetAvatarUrl(hContact, tszUrl);
		ReloadAvatarInfo(hContact);

		setTString(hContact, "domain", _T("feed"));
		setTString(hContact, "Homepage", _T("https://vk.com/feed"));
	} 
	
	if (getWord(hContact, "Status") != ID_STATUS_ONLINE)
		setWord(hContact, "Status", ID_STATUS_ONLINE);
	SetMirVer(hContact, 7);

}
Beispiel #2
0
void CSkypeProto::UpdateProfileAvatar(const JSONNode &root, MCONTACT hContact)
{
	CMString province = root["avatarUrl"].as_mstring();
	if (!province.IsEmpty() && province != "null")
	{
		SetAvatarUrl(hContact, province);
		ReloadAvatarInfo(hContact);
	}
}
Beispiel #3
0
MCONTACT CVkProto::SetContactInfo(const JSONNode &jnItem, bool flag, bool self)
{
	if (!jnItem) {
		debugLogA("CVkProto::SetContactInfo pItem == NULL");
		return INVALID_CONTACT_ID;
	}

	LONG userid = jnItem["id"].as_int();
	debugLogA("CVkProto::SetContactInfo %d", userid);
	if (userid == 0 || userid == VK_FEED_USER)
		return NULL;

	MCONTACT hContact = FindUser(userid, flag);

	if (userid == m_myUserId) {
		if (hContact != NULL)
			if (self)
				hContact = NULL;
			else
				SetContactInfo(jnItem, flag, true);
	}
	else if (hContact == NULL)
		return NULL;

	CMString tszNick, tszValue;
	int iValue;

	tszValue = jnItem["first_name"].as_mstring();
	if (!tszValue.IsEmpty()) {
		setTString(hContact, "FirstName", tszValue);
		tszNick.Append(tszValue);
		tszNick.AppendChar(' ');
	}

	tszValue = jnItem["last_name"].as_mstring();
	if (!tszValue.IsEmpty()) {
		setTString(hContact, "LastName", tszValue);
		tszNick.Append(tszValue);
	}

	if (!tszNick.IsEmpty())
		setTString(hContact, "Nick", tszNick);

	int sex = jnItem["sex"].as_int();
	if (sex)
		setByte(hContact, "Gender", sex == 2 ? 'M' : 'F');

	tszValue = jnItem["bdate"].as_mstring();
	if (!tszValue.IsEmpty()) {
		int d, m, y, iReadCount;
		iReadCount = _stscanf(tszValue, _T("%d.%d.%d"), &d, &m, &y);
		if (iReadCount > 1) {
			if (iReadCount == 3)
				setWord(hContact, "BirthYear", y);
			setByte(hContact, "BirthDay", d);
			setByte(hContact, "BirthMonth", m);
		}
	}

	tszValue = jnItem["photo_100"].as_mstring();
	if (!tszValue.IsEmpty()) {
		SetAvatarUrl(hContact, tszValue);
		ReloadAvatarInfo(hContact);
	}

	int iNewStatus = (jnItem["online"].as_int() == 0) ? ID_STATUS_OFFLINE : ID_STATUS_ONLINE;
	if (getWord(hContact, "Status", ID_STATUS_OFFLINE) != iNewStatus)
		setWord(hContact, "Status", iNewStatus);

	if (iNewStatus == ID_STATUS_ONLINE) {
		int online_app = _ttoi(jnItem["online_app"].as_mstring());
		int online_mobile = jnItem["online_mobile"].as_int();
		
		if (online_app == 0 && online_mobile == 0)
			SetMirVer(hContact, 7); // vk.com
		else if (online_app != 0)
			SetMirVer(hContact, online_app); // App
		else 
			SetMirVer(hContact, 1); // m.vk.com
	}
	else
		SetMirVer(hContact, -1); // unset MinVer

	if ((iValue = jnItem["timezone"].as_int()) != 0)
		setByte(hContact, "Timezone", iValue * -2);

	tszValue = jnItem["mobile_phone"].as_mstring();
	if (!tszValue.IsEmpty())
		setTString(hContact, "Cellular", tszValue);

	tszValue = jnItem["home_phone"].as_mstring();
	if (!tszValue.IsEmpty())
		setTString(hContact, "Phone", tszValue);

	tszValue = jnItem["status"].as_mstring();
	CMString tszOldStatus(ptrT(db_get_tsa(hContact, hContact ? "CList" : m_szModuleName, "StatusMsg")));
	if (tszValue != tszOldStatus)
		db_set_ts(hContact, hContact ? "CList" : m_szModuleName, "StatusMsg", tszValue);

	CMString tszOldListeningTo(ptrT(db_get_tsa(hContact, m_szModuleName, "ListeningTo")));
	const JSONNode &jnAudio = jnItem["status_audio"];
	if (jnAudio) {
		CMString tszListeningTo(FORMAT, _T("%s - %s"), jnAudio["artist"].as_mstring(), jnAudio["title"].as_mstring());
		if (tszListeningTo != tszOldListeningTo) {
			setTString(hContact, "ListeningTo", tszListeningTo);
			setTString(hContact, "AudioUrl", jnAudio["url"].as_mstring());
		}
	}
	else if (tszValue[0] == TCHAR(9835) && tszValue.GetLength() > 2) {
		setTString(hContact, "ListeningTo", &(tszValue.GetBuffer())[2]);
		db_unset(hContact, m_szModuleName, "AudioUrl");
	}
	else {
		db_unset(hContact, m_szModuleName, "ListeningTo");
		db_unset(hContact, m_szModuleName, "AudioUrl");
	}

	tszValue = jnItem["about"].as_mstring();
	if (!tszValue.IsEmpty())
		setTString(hContact, "About", tszValue);

	tszValue = jnItem["domain"].as_mstring();
	if (!tszValue.IsEmpty()) {
		setTString(hContact, "domain", tszValue);
		CMString tszUrl("https://vk.com/");
		tszUrl.Append(tszValue);
		setTString(hContact, "Homepage", tszUrl);
	}

	return hContact;
}
Beispiel #4
0
void CSkypeProto::LoadContactList(const NETLIBHTTPREQUEST *response)
{
	if (response == NULL)
		return;

	JSONNode root = JSONNode::parse(response->pData);
	if (!root)
		return;

	LIST<char> skypenames(1);
	bool loadAll = getBool("LoadAllContacts", false);
	const JSONNode &items = root["contacts"].as_array();
	for (size_t i = 0; i < items.size(); i++)
	{
		const JSONNode &item = items.at(i);
		if (!item)
			break;

		const JSONNode &name = item["name"];
		const JSONNode &phones = item["phones"];

		std::string skypename = item["id"].as_string();
		CMString display_name = item["display_name"].as_mstring();
		CMString first_name = name["first"].as_mstring();
		CMString last_name = name["surname"].as_mstring();
		CMString avatar_url = item["avatar_url"].as_mstring();
		std::string type = item["type"].as_string();
		
		if (type == "skype" || loadAll)
		{
			MCONTACT hContact = AddContact(skypename.c_str());
			if (hContact)
			{
				if (item["authorized"].as_bool())
				{
					delSetting(hContact, "Auth");
					delSetting(hContact, "Grant");
				}
				else setByte(hContact, "Grant", 1);

				if (item["blocked"].as_bool())
				{
					db_set_dw(hContact, "Ignore", "Mask1", 127);
					db_set_b(hContact, "CList", "Hidden", 1);
					setByte(hContact, "IsBlocked", 1);
				}
				else
				{
					if (db_get_b(hContact, m_szModuleName, "IsBlocked", 0))
					{
						db_set_dw(hContact, "Ignore", "Mask1", 0);
						db_set_b(hContact, "CList", "Hidden", 0);
						setByte(hContact, "IsBlocked", 0);
					}
				}

				setString(hContact, "Type", type.c_str());

				if (display_name) 
					setTString(hContact, "Nick", display_name); 
				if (first_name) 
					setTString(hContact, "FirstName", first_name); 
				if (last_name)
					setTString(hContact, "LastName", last_name); 

				SetAvatarUrl(hContact, avatar_url);
				ReloadAvatarInfo(hContact);

				for (size_t j = 0; j < phones.size(); j++)
				{
					const JSONNode &phone = phones.at(j);
					if (!phone)
						break;

					CMString number = phone["number"].as_mstring();

					switch (phone["type"].as_int())
					{
					case 0:
						setTString(hContact, "Phone", number);
						break;
					case 2:
						setTString(hContact, "Cellular", number);
						break;
					}
				}

				if (type == "skype") skypenames.insert(mir_strdup(skypename.c_str()));
			}
		}
	}

	if (skypenames.getCount() > 0)
	{
		int i = 0;
		do
		{
			LIST<char> users(1);
			for (; i < skypenames.getCount() && users.getCount() <= 50; i++)
				users.insert(skypenames[i]);
			PushRequest(new GetContactsInfoRequest(li, users), &CSkypeProto::LoadContactsInfo);
		}
		while(i < skypenames.getCount());

		FreeList(skypenames);
		skypenames.destroy();
	}
	PushRequest(new GetContactsAuthRequest(li), &CSkypeProto::LoadContactsAuth);
}