diff options
author | Sergey Bolhovskoy <elzorfox@ya.ru> | 2014-09-22 10:15:26 +0000 |
---|---|---|
committer | Sergey Bolhovskoy <elzorfox@ya.ru> | 2014-09-22 10:15:26 +0000 |
commit | ca1562ad51acda18f36e2602a94483e33ff445b3 (patch) | |
tree | 9522694999ab68cdc1ed4483c02823f030c2060a | |
parent | 3b6d9082dd535d49e489c2edeb3abae8dfddef17 (diff) |
VKontakte:
fix for contact’s sex
reworked ListeningTo sending
git-svn-id: http://svn.miranda-ng.org/main/trunk@10554 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/VKontakte/src/vk_proto.h | 6 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_thread.cpp | 68 |
2 files changed, 57 insertions, 17 deletions
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index cd362baac6..e206287497 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -211,15 +211,15 @@ struct CVkProto : public PROTO<CVkProto> //==== Misc ==========================================================================
TCHAR* GetUserStoredPassword(void);
+
+ void RetrieveStatusMsg(const CMString &StatusMsg);
+ void RetrieveStatusMusic(const CMString &StatusMsg);
void RetrieveMyInfo(void);
void OnReceiveMyInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
-
- void RetrieveStatusMsg(const CMString &StatusMsg);
void RetrieveUserInfo(LONG userId);
void RetrieveUsersInfo(bool flag = false);
void OnReceiveUserInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
-
void RetrieveFriends();
void OnReceiveFriends(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index beb71850ad..dc258cdb89 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -96,9 +96,11 @@ void CVkProto::SetServerStatus(int iNewStatus) return;
int iOldStatus = m_iStatus;
+ CMString oldStatusMsg = db_get_tsa(0, m_szModuleName, "OldStatusMsg");
if (iNewStatus == ID_STATUS_OFFLINE) {
- m_iStatus = ID_STATUS_OFFLINE;
+ m_iStatus = ID_STATUS_OFFLINE;
+ RetrieveStatusMsg(oldStatusMsg);
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/account.setOffline.json", true, &CVkProto::OnReceiveSmth)
<< VER_API);
}
@@ -107,7 +109,10 @@ void CVkProto::SetServerStatus(int iNewStatus) Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/account.setOnline.json", true, &CVkProto::OnReceiveSmth)
<< VER_API);
}
- else m_iStatus = ID_STATUS_INVISIBLE;
+ else {
+ m_iStatus = ID_STATUS_INVISIBLE;
+ RetrieveStatusMsg(oldStatusMsg);
+ }
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)iOldStatus, m_iStatus);
}
@@ -304,7 +309,9 @@ void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe if (!tszNick.IsEmpty())
setTString(hContact, "Nick", tszNick);
- setByte(hContact, "Gender", json_as_int( json_get(pRecord, "sex")) == 2 ? 'M' : 'F');
+ int sex = json_as_int(json_get(pRecord, "sex"));
+ if (sex)
+ setByte(hContact, "Gender", sex == 2 ? 'M' : 'F');
if (szValue = json_as_string( json_get(pRecord, "bdate"))) {
int d, m, y;
@@ -334,14 +341,16 @@ void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe szValue = json_as_string(json_get(pRecord, "status"));
if (szValue && *szValue) {
- ptrT tszOldStatus(db_get_tsa(hContact, "CList", "StatusMsg"));
+ ptrT tszOldStatus(db_get_tsa(hContact, hContact ? "CList" : m_szModuleName, "StatusMsg"));
if (!tszOldStatus)
- db_set_ts(hContact, "CList", "StatusMsg", szValue);
+ db_set_ts(hContact, hContact ? "CList" : m_szModuleName, "StatusMsg", szValue);
else if (_tcscmp(tszOldStatus, szValue))
- db_set_ts(hContact, "CList", "StatusMsg", szValue);
+ db_set_ts(hContact, hContact ? "CList" : m_szModuleName, "StatusMsg", szValue);
}
else
- db_set_ts(hContact, "CList", "StatusMsg", _T(""));
+ db_set_ts(hContact, hContact ? "CList" : m_szModuleName, "StatusMsg", _T(""));
+ if (!hContact)
+ setTString("OldStatusMsg", db_get_tsa(0, m_szModuleName, "StatusMsg"));
szValue = json_as_string(json_get(pRecord, "about"));
if (szValue && *szValue)
@@ -765,6 +774,8 @@ void CVkProto::OnReceivePollingInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest * m_hPollingThread = ForkThreadEx(&CVkProto::PollingThread, NULL, NULL);
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
void CVkProto::RetrieveStatusMsg(const CMString &StatusMsg)
{
debugLogA("CVkProto::RetrieveStatusMsg");
@@ -775,6 +786,35 @@ void CVkProto::RetrieveStatusMsg(const CMString &StatusMsg) << VER_API);
}
+void CVkProto::RetrieveStatusMusic(const CMString &StatusMsg)
+{
+ debugLogA("CVkProto::RetrieveStatusMusic");
+ if (!IsOnline() || (m_iStatus == ID_STATUS_INVISIBLE))
+ return;
+
+ CMString code;
+ CMString oldStatusMsg = db_get_tsa(0, m_szModuleName, "OldStatusMsg");
+ if (StatusMsg.IsEmpty()){
+ if (oldStatusMsg.IsEmpty())
+ code = "API.audio.setBroadcast();return null;";
+ else{
+ CMString codeformat("API.status.set({text:\"%s\"});return null;");
+ code.AppendFormat(codeformat, oldStatusMsg);
+ }
+ }
+ else {
+ CMString codeformat("var userID=%d;var StatusMsg=\"%s\";var oldStatus=API.status.get({\"user_id\":userID});"
+ "var Track=API.audio.search({\"q\":StatusMsg,\"count\":1});if(Track.count=0){API.status.set({\"text\":StatusMsg});"
+ "return oldStatus;}else{var owner=Track.items[0].owner_id;var trackID=Track.items[0].id;var audioTxt=owner+\"_\"+trackID;"
+ "var ids=API.audio.setBroadcast({\"audio\":audioTxt});if(userID=ids[0]){return null;}else{"
+ "API.status.set({\"text\":StatusMsg });return oldStatus;};};");
+ code.AppendFormat(codeformat, m_myUserId, StatusMsg);
+ }
+ Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.json", true, &CVkProto::OnReceiveSmth)
+ << TCHAR_PARAM("code", code)
+ << VER_API);
+}
+
INT_PTR __cdecl CVkProto::SvcSetListeningTo(WPARAM wParam, LPARAM lParam)
{
LISTENINGTOINFO *pliInfo = (LISTENINGTOINFO*)lParam;
@@ -783,19 +823,19 @@ INT_PTR __cdecl CVkProto::SvcSetListeningTo(WPARAM wParam, LPARAM lParam) db_unset(NULL, m_szModuleName, "ListeningTo");
else if (pliInfo->dwFlags & LTI_UNICODE) {
if (ServiceExists(MS_LISTENINGTO_GETPARSEDTEXT))
- wszListeningTo = ptrT((LPWSTR)CallService(MS_LISTENINGTO_GETPARSEDTEXT, (WPARAM)L"%track%. %title% - %artist% - %player%", (LPARAM)pliInfo));
+ wszListeningTo = ptrT((LPWSTR)CallService(MS_LISTENINGTO_GETPARSEDTEXT, (WPARAM)L"%artist% - %title%", (LPARAM)pliInfo));
else
- wszListeningTo.Format(L"%s. %s - %s - %s",
- pliInfo->ptszTrack ? pliInfo->ptszTrack : _T(""),
- pliInfo->ptszTitle ? pliInfo->ptszTitle : _T(""),
- pliInfo->ptszArtist ? pliInfo->ptszArtist : _T(""),
- pliInfo->ptszPlayer ? pliInfo->ptszPlayer : _T(""));
+ wszListeningTo.Format(L"%s - %s",
+ pliInfo->ptszArtist ? pliInfo->ptszArtist : _T(""),
+ pliInfo->ptszTitle ? pliInfo->ptszTitle : _T(""));
setTString("ListeningTo", wszListeningTo);
}
- RetrieveStatusMsg(wszListeningTo);
+ RetrieveStatusMusic(wszListeningTo);
return 0;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
INT_PTR __cdecl CVkProto::SvcVisitProfile(WPARAM hContact, LPARAM)
{
LONG userID = getDword(hContact, "ID", -1);
|