diff options
author | Sergey Bolhovskoy <elzorfox@ya.ru> | 2015-06-26 07:37:59 +0000 |
---|---|---|
committer | Sergey Bolhovskoy <elzorfox@ya.ru> | 2015-06-26 07:37:59 +0000 |
commit | deb05176bf259030db8d5f8ff7c68b5feb325770 (patch) | |
tree | d00388dd336d7ee56e3d60e45dcc218de489299e | |
parent | 3a548ab7449b7c6f444eb7e626636914926380fa (diff) |
VKontakte: code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@14391 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/VKontakte/src/misc.cpp | 27 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_avatars.cpp | 1 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_chats.cpp | 20 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_feed.cpp | 14 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_files.cpp | 1 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_history.cpp | 4 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_messages.cpp | 12 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_pollserver.cpp | 5 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_thread.cpp | 7 |
9 files changed, 36 insertions, 55 deletions
diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index f68d076c5e..5d1f42288a 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -25,20 +25,12 @@ JSONNode nullNode(JSON_NULL); bool IsEmpty(LPCTSTR str)
{
- if (str == NULL)
- return true;
- if (str[0] == 0)
- return true;
- return false;
+ return (str == NULL || str[0] == 0);
}
bool IsEmpty(LPCSTR str)
{
- if (str == NULL)
- return true;
- if (str[0] == 0)
- return true;
- return false;
+ return (str == NULL || str[0] == 0);
}
LPCSTR findHeader(NETLIBHTTPREQUEST *pReq, LPCSTR szField)
@@ -306,11 +298,9 @@ JSONNode& CVkProto::CheckJsonResponse(AsyncHttpRequest *pReq, NETLIBHTTPREQUEST debugLogA("CVkProto::CheckJsonResponse");
root = JSONNode::parse(reply->pData);
- if (!root)
- return nullNode;
if (!CheckJsonResult(pReq, root))
return nullNode;
-
+
return root["response"];
}
@@ -439,10 +429,12 @@ bool CVkProto::AutoFillForm(char *pBody, CMStringA &szAction, CMStringA& szResul szResult.Empty();
char *pFormBeg = strstr(pBody, "<form ");
- if (pFormBeg == NULL) return false;
+ if (pFormBeg == NULL)
+ return false;
char *pFormEnd = strstr(pFormBeg, "</form>");
- if (pFormEnd == NULL) return false;
+ if (pFormEnd == NULL)
+ return false;
*pFormEnd = 0;
@@ -915,10 +907,7 @@ CMString CVkProto::SetBBCString(LPCTSTR ptszString, BBCSupport iBBC, VKBBCType b { vkbbcColor, bbcAdvanced, _T("[color=%s]%s[/color]") },
};
- if (ptszString == NULL)
- return CMString();
-
- if (ptszString[0] == '\0')
+ if (IsEmpty(ptszString))
return CMString();
TCHAR *ptszFormat = NULL;
diff --git a/protocols/VKontakte/src/vk_avatars.cpp b/protocols/VKontakte/src/vk_avatars.cpp index d7fa2e513e..d11bfa8258 100644 --- a/protocols/VKontakte/src/vk_avatars.cpp +++ b/protocols/VKontakte/src/vk_avatars.cpp @@ -66,6 +66,7 @@ void CVkProto::ReloadAvatarInfo(MCONTACT hContact) CallService(MS_AV_REPORTMYAVATARCHANGED, (WPARAM)m_szModuleName);
return;
}
+
PROTO_AVATAR_INFORMATION ai = { 0 };
ai.hContact = hContact;
SvcGetAvatarInfo(0, (LPARAM)&ai);
diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp index e7d94e6a75..fbc2bd10c5 100644 --- a/protocols/VKontakte/src/vk_chats.cpp +++ b/protocols/VKontakte/src/vk_chats.cpp @@ -35,9 +35,8 @@ CVkChatInfo* CVkProto::AppendChat(int id, const JSONNode &jnDlg) return NULL;
MCONTACT chatContact = FindChat(id);
- if (chatContact)
- if (getBool(chatContact, "kicked"))
- return NULL;
+ if (chatContact && getBool(chatContact, "kicked"))
+ return NULL;
CVkChatInfo *c = m_chats.find((CVkChatInfo*)&id);
if (c != NULL)
@@ -81,7 +80,7 @@ CVkChatInfo* CVkProto::AppendChat(int id, const JSONNode &jnDlg) setDword(gci.hContact, "vk_chat_id", id);
db_unset(gci.hContact, m_szModuleName, "off");
- if (jnDlg["left"].as_int() == 1) {
+ if (jnDlg["left"].as_bool()) {
setByte(gci.hContact, "off", 1);
m_chats.remove(c);
return NULL;
@@ -145,7 +144,7 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe if (!jnInfo["title"].isnull())
SetChatTitle(cc, jnInfo["title"].as_mstring());
- if (jnInfo["left"].as_int() == 1 || jnInfo["kicked"].as_int() == 1) {
+ if (jnInfo["left"].as_bool() || jnInfo["kicked"].as_bool()) {
setByte(cc->m_hContact, "kicked", (int)true);
LeaveChat(cc->m_chatid);
return;
@@ -295,7 +294,7 @@ void CVkProto::AppendChatMessage(int id, const JSONNode &jnMsg, bool bIsHistory) CMString tszBody(jnMsg["body"].as_mstring());
const JSONNode &jnFwdMessages = jnMsg["fwd_messages"];
- if (!jnFwdMessages.isnull()){
+ if (!jnFwdMessages.isnull()) {
CMString tszFwdMessages = GetFwdMessages(jnFwdMessages, bbcNo);
if (!tszBody.IsEmpty())
tszFwdMessages = _T("\n") + tszFwdMessages;
@@ -303,14 +302,14 @@ void CVkProto::AppendChatMessage(int id, const JSONNode &jnMsg, bool bIsHistory) }
const JSONNode &jnAttachments = jnMsg["attachments"];
- if (!jnAttachments.isnull()){
+ if (!jnAttachments.isnull()) {
CMString tszAttachmentDescr = GetAttachmentDescr(jnAttachments, bbcNo);
if (!tszBody.IsEmpty())
tszAttachmentDescr = _T("\n") + tszAttachmentDescr;
tszBody += tszAttachmentDescr;
}
- if (tszBody.IsEmpty() && !jnMsg["action"].isnull()){
+ if (tszBody.IsEmpty() && !jnMsg["action"].isnull()) {
bIsAction = true;
CMString tszAction = jnMsg["action"].as_mstring();
@@ -702,9 +701,8 @@ void CVkProto::KickFromChat(int chat_id, int user_id, const JSONNode &jnMsg) debugLogA("CVkProto::KickFromChat (%d)", user_id);
MCONTACT chatContact = FindChat(chat_id);
- if (chatContact)
- if (getBool(chatContact, "off"))
- return;
+ if (chatContact && getBool(chatContact, "off"))
+ return;
if (user_id == m_myUserId)
LeaveChat(chat_id);
diff --git a/protocols/VKontakte/src/vk_feed.cpp b/protocols/VKontakte/src/vk_feed.cpp index b403a15c2e..717f155d79 100644 --- a/protocols/VKontakte/src/vk_feed.cpp +++ b/protocols/VKontakte/src/vk_feed.cpp @@ -202,7 +202,7 @@ CVKNewsItem* CVkProto::GetVkNewsItem(const JSONNode &jnItem, OBJLIST<CVkUserInfo }
const JSONNode &jnAttachments = jnItem["attachments"];
- if (!jnAttachments.isnull()){
+ if (!jnAttachments.isnull()) {
if (!tszText.IsEmpty())
tszText.AppendChar(_T('\n'));
tszText += GetAttachmentDescr(jnAttachments, m_bUseBBCOnAttacmentsAsNews ? m_iBBCForNews : m_iBBCForAttachments);
@@ -408,17 +408,15 @@ CVKNewsItem* CVkProto::GetVkNotificationsItem(const JSONNode &jnItem, OBJLIST<CV CMString tszNotificationTranslate = SpanVKNotificationType(tszType, vkFeedbackType, vkParentType);
const JSONNode &jnFeedback = jnItem["feedback"];
- if (!jnFeedback)
+ const JSONNode &jnParent = jnItem["parent"];
+
+ if (!jnFeedback || !jnParent)
return NULL;
CVkUserInfo *vkUser = NULL;
CMString tszFeedback = GetVkFeedback(jnFeedback, vkFeedbackType, vkUsers, vkUser);
-
- const JSONNode &jnParent = jnItem["parent"];
- if (!jnParent)
- return NULL;
-
CVKNewsItem* vkNotification = GetVkParent(jnParent, vkParentType);
+
if (!vkNotification)
return NULL;
@@ -616,7 +614,7 @@ bool CVkProto::FilterNotification(CVKNewsItem* vkNotificationItem, bool& isComme if (vkNotificationItem->tszType == _T("mention_comments")
|| vkNotificationItem->tszType == _T("mention_comment_photo")
- || vkNotificationItem->tszType == _T("mention_comment_video")){
+ || vkNotificationItem->tszType == _T("mention_comment_video")) {
isCommented = true;
return m_bNotificationFilterMentions;
}
diff --git a/protocols/VKontakte/src/vk_files.cpp b/protocols/VKontakte/src/vk_files.cpp index 0532276b5b..ce3e47326c 100644 --- a/protocols/VKontakte/src/vk_files.cpp +++ b/protocols/VKontakte/src/vk_files.cpp @@ -74,6 +74,7 @@ HANDLE CVkProto::SendFile(MCONTACT hContact, const TCHAR *desc, TCHAR **files) LONG userID = getDword(hContact, "ID", -1);
if (!IsOnline() || userID == -1 || userID == VK_FEED_USER)
return (HANDLE)0;
+
CVkFileUploadParam *fup = new CVkFileUploadParam(hContact, desc, files);
ForkThread(&CVkProto::SendFileThread, (void *)fup);
return (HANDLE)fup;
diff --git a/protocols/VKontakte/src/vk_history.cpp b/protocols/VKontakte/src/vk_history.cpp index ac3965f7dd..20ea678ac1 100644 --- a/protocols/VKontakte/src/vk_history.cpp +++ b/protocols/VKontakte/src/vk_history.cpp @@ -198,7 +198,7 @@ void CVkProto::OnReceiveHistoryMessages(NETLIBHTTPREQUEST *reply, AsyncHttpReque int uid = jnMsg["user_id"].as_int();
const JSONNode &jnFwdMessages = jnMsg["fwd_messages"];
- if (!jnFwdMessages.isnull()){
+ if (!jnFwdMessages.isnull()) {
CMString tszFwdMessages = GetFwdMessages(jnFwdMessages, m_iBBCForAttachments);
if (!tszBody.IsEmpty())
tszFwdMessages = _T("\n") + tszFwdMessages;
@@ -206,7 +206,7 @@ void CVkProto::OnReceiveHistoryMessages(NETLIBHTTPREQUEST *reply, AsyncHttpReque }
const JSONNode &jnAttachments = jnMsg["attachments"];
- if (!jnAttachments.isnull()){
+ if (!jnAttachments.isnull()) {
CMString tszAttachmentDescr = GetAttachmentDescr(jnAttachments, m_iBBCForAttachments);
if (!tszBody.IsEmpty())
tszAttachmentDescr = _T("\n") + tszAttachmentDescr;
diff --git a/protocols/VKontakte/src/vk_messages.cpp b/protocols/VKontakte/src/vk_messages.cpp index 3eed6635d3..657c56471b 100644 --- a/protocols/VKontakte/src/vk_messages.cpp +++ b/protocols/VKontakte/src/vk_messages.cpp @@ -134,9 +134,7 @@ int CVkProto::OnDbEventRead(WPARAM hContact, LPARAM) void CVkProto::MarkMessagesRead(const CMStringA &mids)
{
debugLogA("CVkProto::MarkMessagesRead (mids)");
- if (!IsOnline())
- return;
- if (mids.IsEmpty())
+ if (!IsOnline() || mids.IsEmpty())
return;
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.markAsRead.json", true, &CVkProto::OnReceiveSmth, AsyncHttpRequest::rpLow)
@@ -161,9 +159,7 @@ void CVkProto::MarkMessagesRead(const MCONTACT hContact) void CVkProto::RetrieveMessagesByIds(const CMStringA &mids)
{
debugLogA("CVkProto::RetrieveMessagesByIds");
- if (!IsOnline())
- return;
- if (mids.IsEmpty())
+ if (!IsOnline() || mids.IsEmpty())
return;
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.getById.json", true, &CVkProto::OnReceiveMessages, AsyncHttpRequest::rpHigh)
@@ -212,7 +208,7 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe int uid = jnMsg["user_id"].as_int();
const JSONNode &jnFwdMessages = jnMsg["fwd_messages"];
- if (!jnFwdMessages.isnull()){
+ if (!jnFwdMessages.isnull()) {
CMString tszFwdMessages = GetFwdMessages(jnFwdMessages, m_iBBCForAttachments);
if (!tszBody.IsEmpty())
tszFwdMessages = _T("\n") + tszFwdMessages;
@@ -220,7 +216,7 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe }
const JSONNode &jnAttachments = jnMsg["attachments"];
- if (!jnAttachments.isnull()){
+ if (!jnAttachments.isnull()) {
CMString tszAttachmentDescr = GetAttachmentDescr(jnAttachments, m_iBBCForAttachments);
if (!tszBody.IsEmpty())
tszAttachmentDescr = _T("\n") + tszAttachmentDescr;
diff --git a/protocols/VKontakte/src/vk_pollserver.cpp b/protocols/VKontakte/src/vk_pollserver.cpp index d867a059e3..dd1b4d22db 100644 --- a/protocols/VKontakte/src/vk_pollserver.cpp +++ b/protocols/VKontakte/src/vk_pollserver.cpp @@ -99,9 +99,8 @@ void CVkProto::PollUpdates(const JSONNode &jnUpdates) // skip outgoing messages sent from a client
flags = jnChild[2].as_int();
- if (flags & VKFLAG_MSGOUTBOX && !(flags & VKFLAG_MSGCHAT))
- if (CheckMid(m_sendIds, msgid))
- break;
+ if (flags & VKFLAG_MSGOUTBOX && !(flags & VKFLAG_MSGCHAT) && CheckMid(m_sendIds, msgid))
+ break;
if (!mids.IsEmpty())
mids.AppendChar(',');
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index 2ccaab343f..f609250406 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -181,9 +181,8 @@ void CVkProto::OnOAuthAuthorize(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq pReq->flags = NLHRF_DUMPASTEXT | NLHRF_HTTP11;
pReq->m_szParam = szBody;
pReq->m_szUrl = szAction;
- if (!pReq->m_szUrl.IsEmpty())
- if (pReq->m_szUrl[0] == '/')
- pReq->m_szUrl = VK_LOGIN_DOMAIN + pReq->m_szUrl;
+ if (!pReq->m_szUrl.IsEmpty() && pReq->m_szUrl[0] == '/')
+ pReq->m_szUrl = VK_LOGIN_DOMAIN + pReq->m_szUrl;
m_prevUrl = pReq->m_szUrl;
pReq->m_pFunc = &CVkProto::OnOAuthAuthorize;
pReq->AddHeader("Content-Type", "application/x-www-form-urlencoded");
@@ -430,7 +429,7 @@ void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe if (!isChatRoom(hContact))
arContacts.insert((HANDLE)hContact);
- for (auto it = jnUsers.begin(); it != jnUsers.end(); ++it){
+ for (auto it = jnUsers.begin(); it != jnUsers.end(); ++it) {
hContact = SetContactInfo((*it));
if (hContact)
arContacts.remove((HANDLE)hContact);
|