CVKNewsItem* CVkProto::GetVkNotificationsItem(const JSONNode &jnItem, OBJLIST<CVkUserInfo> &vkUsers) { debugLogA("CVkProto::GetVkNotificationsItem"); if (!jnItem) return NULL; CMString tszType(jnItem["type"].as_mstring()); VKObjType vkFeedbackType = vkNull, vkParentType = vkNull; CMString tszNotificationTranslate = SpanVKNotificationType(tszType, vkFeedbackType, vkParentType); const JSONNode &jnFeedback = jnItem["feedback"]; const JSONNode &jnParent = jnItem["parent"]; if (!jnFeedback || !jnParent) return NULL; CVkUserInfo *vkUser = NULL; CMString tszFeedback = GetVkFeedback(jnFeedback, vkFeedbackType, vkUsers, vkUser); CVKNewsItem* vkNotification = GetVkParent(jnParent, vkParentType); if (!vkNotification) return NULL; if (vkNotification && !tszFeedback.IsEmpty()) { CMString tszNotificaton; tszNotificaton.AppendFormat(tszFeedback, tszNotificationTranslate, vkNotification->tszText); vkNotification->tszText = tszNotificaton; tszFeedback = RemoveBBC(tszFeedback); int idx = tszFeedback.Find(_T(" %s %s")); vkNotification->tszPopupTitle.AppendFormat(_T("%s %s"), tszFeedback.Mid(0, idx), tszNotificationTranslate); if (tszFeedback.GetLength() > idx + 7) { if (!vkNotification->tszPopupText.IsEmpty()) vkNotification->tszPopupText += _T("\n>> "); vkNotification->tszPopupText += tszFeedback.Mid(idx + 7, tszFeedback.GetLength() - idx - 7); } vkNotification->tszType = tszType; vkNotification->tDate = jnItem["date"].as_int(); vkNotification->vkFeedbackType = vkFeedbackType; vkNotification->vkParentType = vkParentType; vkNotification->vkUser = vkUser; return vkNotification; } delete vkNotification; return NULL; }
CVKNewsItem* CVkProto::GetVkNotificationsItem(const JSONNode &jnItem, OBJLIST<CVkUserInfo> &vkUsers) { debugLogA("CVkProto::GetVkNotificationsItem"); if (!jnItem) return NULL; CMString tszType(jnItem["type"].as_mstring()); VKObjType vkFeedbackType = vkNull, vkParentType = vkNull; CMString tszNotificationTranslate = SpanVKNotificationType(tszType, vkFeedbackType, vkParentType); const JSONNode &jnFeedback = jnItem["feedback"]; const JSONNode &jnParent = jnItem["parent"]; if (!jnFeedback || !jnParent) return NULL; CVkUserInfo *vkUser = NULL; CMString tszFeedback = GetVkFeedback(jnFeedback, vkFeedbackType, vkUsers, vkUser); CVKNewsItem* vkNotification = GetVkParent(jnParent, vkParentType); if (!vkNotification) return NULL; if (vkNotification && !tszFeedback.IsEmpty()) { CMString tszNotificaton; tszNotificaton.AppendFormat(tszFeedback, tszNotificationTranslate, vkNotification->tszText); vkNotification->tszText = tszNotificaton; vkNotification->tszType = tszType; vkNotification->tDate = jnItem["date"].as_int(); vkNotification->vkFeedbackType = vkFeedbackType; vkNotification->vkParentType = vkParentType; vkNotification->vkUser = vkUser; return vkNotification; } delete vkNotification; return NULL; }
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; }