Esempio n. 1
0
void CVkProto::OnReceiveUnreadNews(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
    debugLogA("CVkProto::OnReceiveUnreadNews %d", reply->resultCode);
    db_unset(NULL, m_szModuleName, "LastNewsReqTime");
    if (reply->resultCode != 200)
        return;

    JSONNode jnRoot;
    const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
    if (!jnResponse)
        return;

    OBJLIST<CVkUserInfo> vkUsers(5, NumericKeySortT);
    CreateVkUserInfoList(vkUsers, jnResponse);

    const JSONNode &jnItems = jnResponse["items"];

    OBJLIST<CVKNewsItem> vkNews(5, sttCompareVKNewsItems);
    if (jnItems)
        for (auto it = jnItems.begin(); it != jnItems.end(); ++it) {
            CVKNewsItem *vkNewsItem = GetVkNewsItem((*it), vkUsers);
            if (!vkNewsItem)
                continue;
            CVKNewsItem *vkNewsFoundItem = vkNews.find(vkNewsItem);
            if (vkNewsFoundItem == NULL)
                vkNews.insert(vkNewsItem);
            else if (vkNewsFoundItem->tszType == _T("wall_photo") && vkNewsItem->tszType == _T("post")) {
                vkNews.remove(vkNewsFoundItem);
                vkNews.insert(vkNewsItem);
            }
            else
                delete vkNewsItem;
        }

    bool bNewsAdded = false;
    for (int i = 0; i < vkNews.getCount(); i++)
        if (!(m_bNewsSourceNoReposts && vkNews[i].bIsRepost)) {
            AddFeedEvent(vkNews[i]);
            bNewsAdded = true;
        }

    if (bNewsAdded)
        AddCListEvent(true);

    setDword("LastNewsTime", time(NULL));

    vkNews.destroy();
    vkUsers.destroy();
}
Esempio n. 2
0
void CVkProto::OnReceiveUnreadNotifications(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
	debugLogA("CVkProto::OnReceiveUnreadNotifications %d", reply->resultCode);
	db_unset(NULL, m_szModuleName, "LastNotificationsReqTime");
	if (reply->resultCode != 200)
		return;

	JSONNode jnRoot;
	const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
	if (!jnResponse)
		return;

	const JSONNode &jnNotifications = jnResponse["notifications"];
	const JSONNode &jnGroupInvates = jnResponse["groupinvates"];

	OBJLIST<CVkUserInfo> vkUsers(5, NumericKeySortT);
	OBJLIST<CVKNewsItem> vkNotification(5, sttCompareVKNotificationItems);
	
	CreateVkUserInfoList(vkUsers, jnNotifications);
	CreateVkUserInfoList(vkUsers, jnGroupInvates);
	
	if (!jnNotifications.isnull()) {
		const JSONNode &jnItems = jnNotifications["items"];

		if (!jnItems.isnull())
			for (auto it = jnItems.begin(); it != jnItems.end(); ++it) {
				CVKNewsItem *vkNotificationItem = GetVkNotificationsItem((*it), vkUsers);
				if (!vkNotificationItem)
					continue;
				if (vkNotification.find(vkNotificationItem) == NULL)
					vkNotification.insert(vkNotificationItem);
				else
					delete vkNotificationItem;
			}

	}

	if (!jnGroupInvates.isnull()) {
		const JSONNode &jnItems = jnGroupInvates["items"];

		if (!jnItems.isnull())
			for (auto it = jnItems.begin(); it != jnItems.end(); ++it) {
				CVKNewsItem *vkNotificationItem = GetVkGroupInvates((*it), vkUsers);				
				if (!vkNotificationItem)
					continue;		
				if (vkNotification.find(vkNotificationItem) == NULL)			
					vkNotification.insert(vkNotificationItem);				
				else
					delete vkNotificationItem;
			}
	}	

	bool bNotificationCommentAdded = false;
	bool bNotificationComment = false;
	for (int i = 0; i < vkNotification.getCount(); i++)
		if (FilterNotification(&vkNotification[i], bNotificationComment)) {			
			AddFeedEvent(vkNotification[i].tszText, vkNotification[i].tDate);
			bNotificationCommentAdded = bNotificationComment || bNotificationCommentAdded;
		}

	setDword("LastNotificationsTime", time(NULL));
	if (m_bNotificationsMarkAsViewed && bNotificationCommentAdded)
		NotificationMarkAsViewed();

	vkNotification.destroy();
	vkUsers.destroy();
}