Ejemplo n.º 1
0
void WhatsAppProto::onGroupNewSubject(const std::string &gjid, const std::string &author, const std::string &newSubject, int ts)
{
	WAChatInfo *pInfo = SafeGetChat(gjid);
	if (pInfo == NULL)
		return;

	ptrT tszText(str2t(newSubject));
	ptrT tszTextDb(getTStringA(pInfo->hContact, WHATSAPP_KEY_NICK));
	if (!mir_tstrcmp(tszText, tszTextDb)) // notify about subject change only if differs from the stored one
		return;

	ptrT tszUID(str2t(author));
	ptrT tszNick(GetChatUserNick(author));

	GCDEST gcd = { m_szModuleName, pInfo->tszJid, GC_EVENT_TOPIC };

	GCEVENT gce = { sizeof(gce), &gcd };
	gce.dwFlags = GCEF_ADDTOLOG + ((ts == 0) ? GCEF_NOTNOTIFY : 0);
	gce.ptszUID = tszUID;
	gce.ptszNick = tszNick;
	gce.time = ts;
	gce.ptszText = tszText;
	CallServiceSync(MS_GC_EVENT, NULL, (LPARAM)&gce);

	setTString(pInfo->hContact, WHATSAPP_KEY_NICK, tszText);
}
Ejemplo n.º 2
0
CMString CVkProto::GetVkFeedback(const JSONNode &jnFeedback, VKObjType vkFeedbackType, OBJLIST<CVkUserInfo> &vkUsers, CVkUserInfo *vkUser)
{
	debugLogA("CVkProto::GetVkFeedback");
	CMString tszRes;
	if (!jnFeedback || !vkFeedbackType)
		return tszRes;

	CMString tszFormat;
	LONG iUserId = 0;

	if (vkFeedbackType == vkComment) {
		iUserId = jnFeedback["from_id"].as_int();
		tszFormat = _T("%s %%s %%s\n%s");		
	}
	else if (vkFeedbackType == vkPost) {		
		iUserId = jnFeedback["owner_id "].as_int();
		tszFormat = _T("%s %%s %%s\n%s");		
	}
	else if (vkFeedbackType == VKObjType::vkUsers || vkFeedbackType == vkCopy) {
		const JSONNode &jnUsers = jnFeedback["items"];
		
		CMString tszUsers;
		for (auto it = jnUsers.begin(); it != jnUsers.end(); ++it) {
			const JSONNode &jnUserItem = (*it);
			if (!jnUserItem["from_id"])
				continue;
			iUserId = jnUserItem["from_id"].as_int();			
			vkUser = GetVkUserInfo(iUserId, vkUsers);
			if (!tszUsers.IsEmpty())
				tszUsers += _T(", ");
			tszUsers += SetBBCString(vkUser->m_tszUserNick, m_iBBCForNews, vkbbcUrl, vkUser->m_tszLink);
		}
		tszRes.AppendFormat(_T("%s %%s %%s"), tszUsers);
		vkUser = NULL;
		iUserId = 0;
	}

	if (iUserId) {
		vkUser = GetVkUserInfo(iUserId, vkUsers);
		CMString tszText(jnFeedback["text"].as_mstring());
		tszText.Replace(_T("%"), _T("%%"));
		tszRes.AppendFormat(tszFormat, SetBBCString(vkUser->m_tszUserNick, m_iBBCForNews, vkbbcUrl, vkUser->m_tszLink), ClearFormatNick(tszText));
	}

	return tszRes;
}
Ejemplo n.º 3
0
	void btnOk_OnClick(CCtrlButton*)
	{
		m_proto->m_szInviteJids.clear();

		// invite users from clist
		for (MCONTACT hContact = db_find_first(m_proto->m_szModuleName); hContact; hContact = db_find_next(hContact, m_proto->m_szModuleName)) {
			if (m_proto->isChatRoom(hContact))
				continue;

			if (HANDLE hItem = m_clc.FindContact(hContact)) {
				if (m_clc.GetCheck(hItem)) {
					ptrA jid(m_proto->getStringA(hContact, "ID"));
					if (jid != NULL)
						m_proto->m_szInviteJids.push_back((char*)jid);
				}
			}
		}

		ptrA tszText(m_entry.GetTextA());
		if (tszText != NULL)
			m_proto->m_szInviteJids.push_back(string(tszText));
	}
Ejemplo n.º 4
0
void WhatsAppProto::onGroupMessage(const FMessage &pMsg)
{
	// we need to add a contact, so there's no difference at all
	if (pMsg.media_wa_type == FMessage::WA_TYPE_CONTACT) {
		onMessageForMe(pMsg);
		return;
	}

	WAChatInfo *pInfo = SafeGetChat(pMsg.key.remote_jid);
	if (pInfo == NULL) {
		pInfo = InitChat(pMsg.key.remote_jid, "");
		pInfo->bActive = true;
	}

	std::string msg(pMsg.data);
	if (!pMsg.media_url.empty()) {
		if (!msg.empty())
			msg.append("\n");
		msg += pMsg.media_url;
	}

	ptrT tszText(str2t(msg));
	ptrT tszUID(str2t(pMsg.remote_resource));
	ptrT tszNick(GetChatUserNick(pMsg.remote_resource));

	GCDEST gcd = { m_szModuleName, pInfo->tszJid, GC_EVENT_MESSAGE };

	GCEVENT gce = { sizeof(gce), &gcd };
	gce.dwFlags = GCEF_ADDTOLOG;
	gce.ptszUID = tszUID;
	gce.ptszNick = tszNick;
	gce.time = pMsg.timestamp;
	gce.ptszText = tszText;
	gce.bIsMe = m_szJid == pMsg.remote_resource;
	CallServiceSync(MS_GC_EVENT, NULL, (LPARAM)&gce);

	if (isOnline())
		m_pConnection->sendMessageReceived(pMsg);
}
Ejemplo n.º 5
0
CVKNewsItem* CVkProto::GetVkParent(const JSONNode &jnParent, VKObjType vkParentType, LPCTSTR ptszReplyText, LPCTSTR ptszReplyLink)
{
	debugLogA("CVkProto::GetVkParent");
	CMString tszRes;
	if (!jnParent || !vkParentType)
		return NULL;

	CVKNewsItem * vkNotificationItem = new CVKNewsItem();
			
	if (vkParentType == vkPhoto) {
		CMString tszPhoto = GetVkPhotoItem(jnParent, m_iBBCForNews);
		LONG iOwnerId = jnParent["owner_id"].as_int();
		LONG iId = jnParent["id"].as_int();
		vkNotificationItem->tszId.AppendFormat(_T("%d_%d"), iOwnerId, iId);
		vkNotificationItem->tszLink.AppendFormat(_T("https://vk.com/photo%s"), vkNotificationItem->tszId);
		vkNotificationItem->tszText.AppendFormat(_T("\n%s"), tszPhoto);

		if (ptszReplyText)
			vkNotificationItem->tszText.AppendFormat(_T("\n>> %s"), SetBBCString(ptszReplyText, m_iBBCForNews, vkbbcI));
		
		vkNotificationItem->tszText.AppendFormat(_T("\n%s"), SetBBCString(TranslateT("Link"), m_iBBCForNews, vkbbcUrl, vkNotificationItem->tszLink));
	}
	else if (vkParentType == vkVideo) {
		LONG iOwnerId = jnParent["owner_id"].as_int();
		LONG iId = jnParent["id"].as_int();
		CMString tszTitle(jnParent["title"].as_mstring());
		vkNotificationItem->tszId.AppendFormat(_T("%d_%d"), iOwnerId, iId);
		vkNotificationItem->tszLink.AppendFormat(_T("https://vk.com/video%s"), vkNotificationItem->tszId);
		
		CMString tszText(jnParent["text"].as_mstring());
		ClearFormatNick(tszText);
		
		if (!tszText.IsEmpty())
			vkNotificationItem->tszText.AppendFormat(_T("\n%s: %s"), SetBBCString(TranslateT("Video description:"), m_iBBCForNews, vkbbcB), SetBBCString(tszText, m_iBBCForNews, vkbbcI));

		if (ptszReplyText)
			vkNotificationItem->tszText.AppendFormat(_T("\n>> %s"), SetBBCString(ptszReplyText, m_iBBCForNews, vkbbcI));
		
		vkNotificationItem->tszText.AppendFormat(_T("\n%s"), SetBBCString(tszTitle, m_iBBCForNews, vkbbcUrl, vkNotificationItem->tszLink));
	}
	else if (vkParentType == vkPost) {
		LONG iToId = jnParent["to_id"].as_int();
		LONG iId = jnParent["id"].as_int();
		vkNotificationItem->tszId.AppendFormat(_T("%d_%d"), iToId, iId);
		vkNotificationItem->tszLink.AppendFormat(_T("https://vk.com/wall%s%s"), vkNotificationItem->tszId, ptszReplyLink ? ptszReplyLink : _T(""));
		
		CMString tszText(jnParent["text"].as_mstring());
		ClearFormatNick(tszText);
		
		if (!tszText.IsEmpty())
			vkNotificationItem->tszText.AppendFormat(_T("\n%s: %s"), SetBBCString(TranslateT("Post text:"), m_iBBCForNews, vkbbcB), SetBBCString(tszText, m_iBBCForNews, vkbbcI));

		if (ptszReplyText)
			vkNotificationItem->tszText.AppendFormat(_T("\n>> %s"), SetBBCString(ptszReplyText, m_iBBCForNews, vkbbcI));

		vkNotificationItem->tszText.AppendFormat(_T("\n%s"), SetBBCString(TranslateT("Link"), m_iBBCForNews, vkbbcUrl, vkNotificationItem->tszLink));
	}
	else if (vkParentType == vkTopic) {
		LONG iOwnerId = jnParent["owner_id"].as_int();
		LONG iId = jnParent["id"].as_int();
		CMString tszTitle(jnParent["title"].as_mstring());
		vkNotificationItem->tszId.AppendFormat(_T("%d_%d"), iOwnerId, iId);
		vkNotificationItem->tszLink.AppendFormat(_T("https://vk.com/topic%s%s"), 
		vkNotificationItem->tszId, ptszReplyLink ? ptszReplyLink : _T(""));
		
		CMString tszText(jnParent["text"].as_mstring());
		ClearFormatNick(tszText);
		
		if (!tszText.IsEmpty())
			vkNotificationItem->tszText.AppendFormat(_T("\n%s: %s"), SetBBCString(TranslateT("Topic text:"), m_iBBCForNews, vkbbcB), SetBBCString(tszText, m_iBBCForNews, vkbbcI));

		if (ptszReplyText)
			vkNotificationItem->tszText.AppendFormat(_T("\n>> %s"), SetBBCString(ptszReplyText, m_iBBCForNews, vkbbcI));
		
		vkNotificationItem->tszText.AppendFormat(_T("\n%s"), SetBBCString(tszTitle, m_iBBCForNews, vkbbcUrl, vkNotificationItem->tszLink));
	}
	else if (vkParentType == vkComment) {
		CMString tszText(jnParent["text"].as_mstring());
		ClearFormatNick(tszText);

		const JSONNode &jnPhoto = jnParent["photo"];
		if (!jnPhoto.isnull()) {
			delete vkNotificationItem;
			return GetVkParent(jnPhoto, vkPhoto, tszText);
		}

		const JSONNode &jnVideo = jnParent["video"];
		if (!jnVideo.isnull()) {
			delete vkNotificationItem;
			return GetVkParent(jnVideo, vkVideo, tszText);
		}

		LONG iId = jnParent["id"].as_int();

		const JSONNode &jnPost = jnParent["post"];
		if (!jnPost.isnull()) {
			CMString tszRepl;
			tszRepl.AppendFormat(_T("?reply=%d"), iId);		
			delete vkNotificationItem;
			return GetVkParent(jnPost, vkPost, tszText, tszRepl);
		}

		const JSONNode &jnTopic = jnParent["topic"];
		if (!jnTopic.isnull()) {
			CMString tszRepl;		
			tszRepl.AppendFormat(_T("?reply=%d"), iId);
			delete vkNotificationItem;
			return GetVkParent(jnTopic, vkTopic, tszText, tszRepl);
		}
	}

	return vkNotificationItem;
}
Ejemplo n.º 6
0
CVKNewsItem* CVkProto::GetVkNewsItem(const JSONNode &jnItem, OBJLIST<CVkUserInfo> &vkUsers, bool isRepost)
{
	bool bPostLink = true;
	CVKNewsItem *vkNewsItem = new CVKNewsItem();
	if (!jnItem)
		return vkNewsItem;

	LONG iSourceId = jnItem["source_id"].isnull() ? jnItem["owner_id"].as_int() : jnItem["source_id"].as_int();
	LONG iPostId = jnItem["post_id"].as_int();
	CMString tszText(jnItem["text"].as_mstring());

	vkNewsItem->tszType = jnItem["type"].as_mstring();
	vkNewsItem->vkUser = GetVkUserInfo(iSourceId, vkUsers);
	vkNewsItem->bIsGroup = vkNewsItem->vkUser->m_bIsGroup;
	vkNewsItem->tDate = jnItem["date"].as_int();

	if (!tszText.IsEmpty())
		tszText += _T("\n");

	debugLog(_T("CVkProto::GetVkNewsItem %d %d %s"), iSourceId, iPostId, vkNewsItem->tszType);

	if (vkNewsItem->tszType == _T("photo_tag")) {
		bPostLink = false;
		const JSONNode &jnPhotos = jnItem["photo_tags"];
		if (!jnPhotos.isnull()) {			
			const JSONNode &jnPhotoItems = jnPhotos["items"];
			if (!jnPhotoItems.isnull()) {				
				tszText = TranslateT("User was tagged in these photos:");
				for (auto it = jnPhotoItems.begin(); it != jnPhotoItems.end(); ++it)
					tszText += _T("\n") + GetVkPhotoItem((*it), m_iBBCForNews);
			}
		}
	}
	else if (vkNewsItem->tszType == _T("photo") || vkNewsItem->tszType == _T("wall_photo")) {
		bPostLink = false;
		const JSONNode &jnPhotos = jnItem["photos"];
		int i = 0;
		if (!jnPhotos.isnull()) {
			const JSONNode &jnPhotoItems = jnPhotos["items"];
			if (!jnPhotoItems.isnull())
				for (auto it = jnPhotoItems.begin(); it != jnPhotoItems.end(); ++it) {
					const JSONNode &jnPhotoItem = (*it);
					tszText += GetVkPhotoItem(jnPhotoItem, m_iBBCForNews) + _T("\n");
					if (i == 0 && vkNewsItem->tszType == _T("wall_photo")) {						
						if (!jnPhotoItem["post_id"].isnull()) {
							bPostLink = true;
							iPostId = jnPhotoItem["post_id"].as_int();
							break; // max 1 wall_photo when photo post_id !=0
						}					
					}
					i++;
				}
		}
	} 
	else if (vkNewsItem->tszType == _T("post") || vkNewsItem->tszType.IsEmpty()) {
		bPostLink = true;
		const JSONNode &jnRepost = jnItem["copy_history"];
		if (!jnRepost.isnull()) {
			CVKNewsItem *vkRepost = GetVkNewsItem((*jnRepost.begin()), vkUsers, true);
			vkRepost->tszText.Replace(_T("\n"), _T("\n\t"));
			tszText += vkRepost->tszText;
			tszText += _T("\n");
			vkNewsItem->bIsRepost = true;
			delete vkRepost;
		}

		const JSONNode &jnAttachments = jnItem["attachments"];
		if (!jnAttachments.isnull()) {
			if (!tszText.IsEmpty())
				tszText.AppendChar(_T('\n'));
			tszText += GetAttachmentDescr(jnAttachments, m_bUseBBCOnAttacmentsAsNews ? m_iBBCForNews : m_iBBCForAttachments);
		}
	}

	CMString tszResFormat;	

	if (!isRepost)
		tszResFormat = Translate("News from %s\n%s");
	else {
		tszResFormat = Translate("\tRepost from %s\n%s");
		bPostLink = false;
	}
		
	vkNewsItem->tszText.AppendFormat(tszResFormat, 
		SetBBCString(vkNewsItem->vkUser->m_tszUserNick, m_iBBCForNews, vkbbcUrl, 
		vkNewsItem->vkUser->m_tszLink), tszText);
	
	vkNewsItem->tszId.AppendFormat(_T("%d_%d"), vkNewsItem->vkUser->m_UserId, iPostId);
	if (bPostLink) {
		vkNewsItem->tszLink = CMString(_T("https://vk.com/wall")) + vkNewsItem->tszId;
		vkNewsItem->tszText.AppendChar(_T('\n'));
		vkNewsItem->tszText += SetBBCString(TranslateT("Link"), m_iBBCForNews, vkbbcUrl, vkNewsItem->tszLink);
	}

	debugLog(_T("CVkProto::GetVkNewsItem %d %d <\n%s\n>"), iSourceId, iPostId, vkNewsItem->tszText);

	return vkNewsItem;
}