summaryrefslogtreecommitdiff
path: root/protocols/VKontakte
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/VKontakte')
-rw-r--r--protocols/VKontakte/src/misc.cpp40
-rw-r--r--protocols/VKontakte/src/version.h2
-rw-r--r--protocols/VKontakte/src/vk_files.cpp89
-rw-r--r--protocols/VKontakte/src/vk_proto.h5
-rw-r--r--protocols/VKontakte/src/vk_struct.cpp1
-rw-r--r--protocols/VKontakte/src/vk_struct.h3
6 files changed, 127 insertions, 13 deletions
diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp
index fb8127a1b6..364acc7a98 100644
--- a/protocols/VKontakte/src/misc.cpp
+++ b/protocols/VKontakte/src/misc.cpp
@@ -1140,17 +1140,29 @@ CMStringW CVkProto::GetVkPhotoItem(const JSONNode &jnPhoto, BBCSupport iBBC)
break;
}
- wszRes.AppendFormat(L"%s (%dx%d)",
- SetBBCString(TranslateT("Photo"), iBBC, vkbbcUrl, vkSizes[iMaxSize].wszUrl).c_str(),
- vkSizes[iMaxSize].iSizeW,
- vkSizes[iMaxSize].iSizeH
- );
- if (m_vkOptions.iIMGBBCSupport && iBBC != bbcNo)
- wszRes.AppendFormat(L"\n\t%s",
- SetBBCString((!wszPreviewLink.IsEmpty() ? wszPreviewLink : (!vkSizes[iMaxSize].wszUrl.IsEmpty() ? vkSizes[iMaxSize].wszUrl : L"")),
- bbcBasic,
- vkbbcImg).c_str()
+ if (m_vkOptions.bBBCNewStorySupport) {
+ wszRes.AppendFormat(L"%s (%dx%d)",
+ TranslateT("Photo"),
+ vkSizes[iMaxSize].iSizeW,
+ vkSizes[iMaxSize].iSizeH
);
+ wszPreviewLink = GetVkFileItem(vkSizes[iMaxSize].wszUrl);
+ wszRes = SetBBCString(wszRes, bbcAdvanced, vkbbcImgE, (!wszPreviewLink.IsEmpty() ? wszPreviewLink : L""));
+ }
+ else {
+ wszRes.AppendFormat(L"%s (%dx%d)",
+ SetBBCString(TranslateT("Photo"), iBBC, vkbbcUrl, vkSizes[iMaxSize].wszUrl).c_str(),
+ vkSizes[iMaxSize].iSizeW,
+ vkSizes[iMaxSize].iSizeH
+ );
+ if (m_vkOptions.iIMGBBCSupport && iBBC != bbcNo)
+ wszRes.AppendFormat(L"\n\t%s",
+ SetBBCString((!wszPreviewLink.IsEmpty() ? wszPreviewLink : (!vkSizes[iMaxSize].wszUrl.IsEmpty() ? vkSizes[iMaxSize].wszUrl : L"")),
+ bbcBasic,
+ vkbbcImg).c_str()
+ );
+ }
+
CMStringW wszText(jnPhoto["text"].as_mstring());
if (!wszText.IsEmpty())
wszRes += L"\n" + wszText;
@@ -1182,6 +1194,9 @@ CMStringW CVkProto::SetBBCString(LPCWSTR pwszString, BBCSupport iBBC, VKBBCType
{ vkbbcUrl, bbcNo, L"%s (%s)" },
{ vkbbcUrl, bbcBasic, L"[i]%s[/i] (%s)" },
{ vkbbcUrl, bbcAdvanced, L"[url=%s]%s[/url]" },
+ { vkbbcImgE, bbcNo, L"%s (%s)" },
+ { vkbbcImgE, bbcBasic, L"[i]%s[/i] (%s)" },
+ { vkbbcImgE, bbcAdvanced, L"[img=%s]%s[/img]" },
{ vkbbcSize, bbcNo, L"%s" },
{ vkbbcSize, bbcBasic, L"%s" },
{ vkbbcSize, bbcAdvanced, L"[size=%s]%s[/size]" },
@@ -1204,13 +1219,16 @@ CMStringW CVkProto::SetBBCString(LPCWSTR pwszString, BBCSupport iBBC, VKBBCType
if (pwszFormat == nullptr)
return CMStringW(pwszString);
- if (bbcType == vkbbcUrl && iBBC != bbcAdvanced)
+ if ((bbcType == vkbbcUrl || bbcType == vkbbcImgE) && iBBC != bbcAdvanced)
res.AppendFormat(pwszFormat, pwszString, wszAddString ? wszAddString : L"");
else if (iBBC == bbcAdvanced && bbcType >= vkbbcUrl)
res.AppendFormat(pwszFormat, wszAddString ? wszAddString : L"", pwszString);
else
res.AppendFormat(pwszFormat, pwszString);
+ if (bbcType == vkbbcImgE && iBBC == bbcAdvanced)
+ res += SetBBCString(pwszString, bbcAdvanced, vkbbcUrl, wszAddString) + L"\n";
+
return res;
}
diff --git a/protocols/VKontakte/src/version.h b/protocols/VKontakte/src/version.h
index 80177e2652..a920ddfc9d 100644
--- a/protocols/VKontakte/src/version.h
+++ b/protocols/VKontakte/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 1
#define __RELEASE_NUM 16
-#define __BUILD_NUM 0
+#define __BUILD_NUM 1
#include <stdver.h>
diff --git a/protocols/VKontakte/src/vk_files.cpp b/protocols/VKontakte/src/vk_files.cpp
index 20f7b2431a..4cd9007fef 100644
--- a/protocols/VKontakte/src/vk_files.cpp
+++ b/protocols/VKontakte/src/vk_files.cpp
@@ -17,6 +17,95 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
+CMStringW CVkProto::GetVkFileItem(CMStringW& _wszUrl, bool bAsync)
+{
+
+ wchar_t buf[MAX_PATH];
+ File::GetReceivedFolder(0, buf, _countof(buf));
+
+ if (_wszUrl.IsEmpty())
+ return _wszUrl;
+
+ CMStringW wszUrl = _wszUrl;
+
+ wszUrl.Replace(L"\\", L"/");
+
+ if (int i = wszUrl.Find('?'))
+ wszUrl.Truncate(i);
+
+ if (int i = wszUrl.ReverseFind('/'))
+ wszUrl = wszUrl.Mid(i + 1);
+
+ wszUrl.Insert(0, buf);
+
+ if (::_waccess(wszUrl.c_str(), 0) && IsOnline())
+ if (bAsync) {
+ AsyncHttpRequest* pReq = new AsyncHttpRequest();
+ pReq->flags = NLHRF_NODUMP | NLHRF_REDIRECT;
+ pReq->m_szUrl = CMStringA(_wszUrl);
+ pReq->pUserInfo = mir_wstrdup(wszUrl.c_str());
+ pReq->m_pFunc = &CVkProto::OnGetVkFileItem;
+ pReq->requestType = REQUEST_GET;
+ pReq->m_bApiReq = false;
+ Push(pReq);
+ }
+ else {
+ MHttpRequest req(REQUEST_GET);
+ req.m_szUrl = CMStringA(_wszUrl);
+ req.flags = VK_NODUMPHEADERS;
+
+ auto* reply = Netlib_HttpTransaction(m_hNetlibUser, &req);
+ if (reply == nullptr)
+ return _wszUrl;
+
+ if (reply->resultCode != 200) {
+ debugLogA("CVkProto::GetVkFileItem: failed with code %d", reply->resultCode);
+ return _wszUrl;
+ }
+
+ FILE* out = _wfopen(wszUrl.c_str(), L"wb");
+ if (out) {
+ fwrite(reply->body, 1, reply->body.GetLength(), out);
+ fclose(out);
+ debugLogW(L"CVkProto::GetVkFileItem file %s saved", wszUrl.c_str());
+ }
+
+ }
+ else
+ debugLogW(L"CVkProto::GetVkFileItem file %s already exist or connection lost", wszUrl.c_str());
+
+ wszUrl.Insert(0, L"file://");
+ wszUrl.Replace(L"\\", L"/");
+
+ return wszUrl;
+}
+
+void CVkProto::OnGetVkFileItem(MHttpResponse* reply, AsyncHttpRequest* pReq)
+{
+ ptrW pwszFileName((wchar_t*)pReq->pUserInfo);
+
+ if (reply->resultCode != 200 || !pReq->pUserInfo) {
+ debugLogW(L"CVkProto::OnGetVkFileItem error load file %s", pwszFileName);
+ return;
+ }
+
+
+ debugLogW(L"CVkProto::OnGetVkFileItem %s", pwszFileName);
+
+ FILE* out = _wfopen(pwszFileName, L"wb");
+ if (out) {
+ fwrite(reply->body, 1, reply->body.GetLength(), out);
+ fclose(out);
+ debugLogW(L"CVkProto::OnGetVkFileItem file %s saved", pwszFileName);
+ }
+ else
+ debugLogW(L"CVkProto::OnGetVkFileItem error open file %s", pwszFileName);
+
+ return;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
HANDLE CVkProto::SendFile(MCONTACT hContact, const wchar_t *desc, wchar_t **files)
{
debugLogA("CVkProto::SendFile");
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h
index 2b05e35bf6..198bad53c5 100644
--- a/protocols/VKontakte/src/vk_proto.h
+++ b/protocols/VKontakte/src/vk_proto.h
@@ -287,6 +287,11 @@ private:
void OnSearch(MHttpResponse*, AsyncHttpRequest*);
void OnSearchByMail(MHttpResponse*, AsyncHttpRequest*);
+ //==== Files Download ================================================================
+
+ CMStringW CVkProto::GetVkFileItem(CMStringW& wszUrl, bool bAsync = false);
+ void OnGetVkFileItem(MHttpResponse* reply, AsyncHttpRequest* pReq);
+
//==== Files Upload ==================================================================
void SendFileFiled(CVkFileUploadParam *fup, int ErrorCode);
diff --git a/protocols/VKontakte/src/vk_struct.cpp b/protocols/VKontakte/src/vk_struct.cpp
index d0901d6f56..d0386bbe3e 100644
--- a/protocols/VKontakte/src/vk_struct.cpp
+++ b/protocols/VKontakte/src/vk_struct.cpp
@@ -213,6 +213,7 @@ CVKOptions::CVKOptions(PROTO_INTERFACE* proto) :
iMusicSendMetod(proto, "MusicSendMetod", MusicSendMetod::sendBroadcastOnly),
bPopupContactsMusic(proto, "PopupContactsMusic", false),
iSyncHistoryMetod(proto, "SyncHistoryMetod", SyncHistoryMetod::syncOff),
+ bBBCNewStorySupport(proto, "BBCNewStorySupport", false),
iIMGBBCSupport(proto, "IMGBBCSupport", IMGBBCSypport::imgNo),
iBBCForNews(proto, "BBCForNews", BBCSupport::bbcBasic),
iBBCForAttachments(proto, "BBCForAttachments", BBCSupport::bbcBasic),
diff --git a/protocols/VKontakte/src/vk_struct.h b/protocols/VKontakte/src/vk_struct.h
index 33fb96de7f..e6e2e42f67 100644
--- a/protocols/VKontakte/src/vk_struct.h
+++ b/protocols/VKontakte/src/vk_struct.h
@@ -190,7 +190,7 @@ struct CVKNewsItem : public MZeroedObject {
bool bIsRepost;
};
-enum VKBBCType : uint8_t { vkbbcB, vkbbcI, vkbbcS, vkbbcU, vkbbcCode, vkbbcImg, vkbbcUrl, vkbbcSize, vkbbcColor };
+enum VKBBCType : uint8_t { vkbbcB, vkbbcI, vkbbcS, vkbbcU, vkbbcCode, vkbbcImg, vkbbcUrl, vkbbcImgE, vkbbcSize, vkbbcColor };
enum BBCSupport : uint8_t { bbcNo, bbcBasic, bbcAdvanced };
struct CVKBBCItem {
@@ -259,6 +259,7 @@ struct CVKOptions {
CMOption<uint8_t> bNotificationsEnabled;
CMOption<uint8_t> bNotificationsMarkAsViewed;
CMOption<uint8_t> bSpecialContactAlwaysEnabled;
+ CMOption<uint8_t> bBBCNewStorySupport;
CMOption<uint8_t> iIMGBBCSupport;
CMOption<uint8_t> iBBCForNews;
CMOption<uint8_t> iBBCForAttachments;