summaryrefslogtreecommitdiff
path: root/protocols/VKontakte/src/vk_thread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/VKontakte/src/vk_thread.cpp')
-rw-r--r--protocols/VKontakte/src/vk_thread.cpp132
1 files changed, 74 insertions, 58 deletions
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp
index 9d7fc28a48..6df0321fd2 100644
--- a/protocols/VKontakte/src/vk_thread.cpp
+++ b/protocols/VKontakte/src/vk_thread.cpp
@@ -452,64 +452,8 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
int isRead = json_as_int(json_get(pMsg, "read_state"));
JSONNODE *pAttachments = json_get(pMsg, "attachments");
- if (pAttachments != NULL) {
- CMString tszBody(ptszBody);
- tszBody.AppendChar('\n');
- tszBody += TranslateT("Attachments:");
- tszBody.AppendChar('\n');
- JSONNODE *pAttach;
- for (int k = 0; (pAttach = json_at(pAttachments, k)) != NULL; k++) {
- tszBody.AppendChar('\t');
- ptrT ptszType(json_as_string(json_get(pAttach, "type")));
- if (!lstrcmp(ptszType, _T("photo"))) {
- JSONNODE *pPhoto = json_get(pAttach, "photo");
- if (pPhoto == NULL) continue;
-
- ptrT ptszLink;
- for (int i = 0; i < SIZEOF(szImageTypes); i++)
- if ((ptszLink = json_as_string(json_get(pPhoto, szImageTypes[i]))) != NULL)
- break;
-
- int iWidth = json_as_int(json_get(pPhoto, "width"));
- int iHeight = json_as_int(json_get(pPhoto, "height"));
- tszBody.AppendFormat(_T("%s: %s (%dx%d)"), TranslateT("Photo"), ptszLink, iWidth, iHeight);
- }
- else if (!lstrcmp(ptszType, _T("audio"))) {
- JSONNODE *pAudio = json_get(pAttach, "audio");
- if (pAudio == NULL) continue;
-
- int aid = json_as_int(json_get(pAudio, "aid"));
- int ownerID = json_as_int(json_get(pAudio, "owner_id"));
- ptrT ptszArtist(json_as_string(json_get(pAudio, "artist")));
- ptrT ptszTitle(json_as_string(json_get(pAudio, "title")));
- tszBody.AppendFormat(_T("%s: (%s - %s) - http://vk.com/audio%d_%d"),
- TranslateT("Audio"), ptszArtist, ptszTitle, ownerID, aid);
- }
- else if (!lstrcmp(ptszType, _T("video"))) {
- JSONNODE *pVideo = json_get(pAttach, "video");
- if (pVideo == NULL) continue;
-
- ptrT ptszTitle(json_as_string(json_get(pVideo, "title")));
- int vid = json_as_int(json_get(pVideo, "vid"));
- int ownerID = json_as_int(json_get(pVideo, "owner_id"));
- tszBody.AppendFormat(_T("%s: %s - http://vk.com/video%d_%d"),
- TranslateT("Video"), ptszTitle, ownerID, vid);
- }
- else if (!lstrcmp(ptszType, _T("doc"))) {
- JSONNODE *pDoc = json_get(pAttach, "doc");
- if (pDoc == NULL) continue;
-
- ptrT ptszTitle(json_as_string(json_get(pDoc, "title")));
- ptrT ptszUrl(json_as_string(json_get(pDoc, "url")));
- tszBody.AppendFormat(_T("%s: (%s) - %s"),
- TranslateT("Document"), ptszTitle, ptszUrl);
- }
- else tszBody.AppendFormat(TranslateT("Unsupported or unknown attachment type: %s"), ptszType);
-
- tszBody.AppendChar('\n');
- }
- ptszBody = mir_tstrdup(tszBody);
- }
+ if (pAttachments != NULL)
+ ptszBody = mir_tstrdup(CMString(ptszBody) + GetAttachmentDescr(pAttachments));
HANDLE hContact = FindUser(uid, true);
@@ -608,6 +552,13 @@ void CVkProto::PollUpdates(JSONNODE *pUpdates)
if ((hContact = FindUser(uid)) != NULL)
CallService(MS_PROTO_CONTACTISTYPING, (WPARAM)hContact, 5);
break;
+
+ case VKPOLL_CHAT_CHANGED:
+ int chatid = json_as_int(json_at(pChild, 1));
+ int isSelf = json_as_int(json_at(pChild, 2));
+ if (!isSelf)
+ AppendChat(chatid, NULL);
+ break;
}
}
@@ -667,3 +618,68 @@ void CVkProto::PollingThread(void*)
m_pollingConn = NULL;
debugLogA("CVkProto::PollingThread: leaving");
}
+
+CMString CVkProto::GetAttachmentDescr(JSONNODE *pAttachments)
+{
+ CMString res;
+ res.AppendChar('\n');
+ res += TranslateT("Attachments:");
+ res.AppendChar('\n');
+ JSONNODE *pAttach;
+ for (int k = 0; (pAttach = json_at(pAttachments, k)) != NULL; k++) {
+ res.AppendChar('\t');
+ ptrT ptszType(json_as_string(json_get(pAttach, "type")));
+ if (!lstrcmp(ptszType, _T("photo"))) {
+ JSONNODE *pPhoto = json_get(pAttach, "photo");
+ if (pPhoto == NULL) continue;
+
+ ptrT ptszLink;
+ for (int i = 0; i < SIZEOF(szImageTypes); i++) {
+ JSONNODE *n = json_get(pPhoto, szImageTypes[i]);
+ if (n != NULL) {
+ ptszLink = json_as_string(n);
+ break;
+ }
+ }
+
+ int iWidth = json_as_int(json_get(pPhoto, "width"));
+ int iHeight = json_as_int(json_get(pPhoto, "height"));
+ res.AppendFormat(_T("%s: %s (%dx%d)"), TranslateT("Photo"), ptszLink, iWidth, iHeight);
+ }
+ else if (!lstrcmp(ptszType, _T("audio"))) {
+ JSONNODE *pAudio = json_get(pAttach, "audio");
+ if (pAudio == NULL) continue;
+
+ int aid = json_as_int(json_get(pAudio, "aid"));
+ int ownerID = json_as_int(json_get(pAudio, "owner_id"));
+ ptrT ptszArtist(json_as_string(json_get(pAudio, "artist")));
+ ptrT ptszTitle(json_as_string(json_get(pAudio, "title")));
+ res.AppendFormat(_T("%s: (%s - %s) - http://vk.com/audio%d_%d"),
+ TranslateT("Audio"), ptszArtist, ptszTitle, ownerID, aid);
+ }
+ else if (!lstrcmp(ptszType, _T("video"))) {
+ JSONNODE *pVideo = json_get(pAttach, "video");
+ if (pVideo == NULL) continue;
+
+ ptrT ptszTitle(json_as_string(json_get(pVideo, "title")));
+ int vid = json_as_int(json_get(pVideo, "vid"));
+ int ownerID = json_as_int(json_get(pVideo, "owner_id"));
+ res.AppendFormat(_T("%s: %s - http://vk.com/video%d_%d"),
+ TranslateT("Video"), ptszTitle, ownerID, vid);
+ }
+ else if (!lstrcmp(ptszType, _T("doc"))) {
+ JSONNODE *pDoc = json_get(pAttach, "doc");
+ if (pDoc == NULL) continue;
+
+ ptrT ptszTitle(json_as_string(json_get(pDoc, "title")));
+ ptrT ptszUrl(json_as_string(json_get(pDoc, "url")));
+ res.AppendFormat(_T("%s: (%s) - %s"),
+ TranslateT("Document"), ptszTitle, ptszUrl);
+ }
+ else res.AppendFormat(TranslateT("Unsupported or unknown attachment type: %s"), ptszType);
+
+ res.AppendChar('\n');
+ }
+
+ return res;
+}