summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorSergey Bolhovskoy <elzorfox@ya.ru>2014-10-16 09:15:31 +0000
committerSergey Bolhovskoy <elzorfox@ya.ru>2014-10-16 09:15:31 +0000
commit1f53603a20c3cccc23f001f5e9fcabee97afd100 (patch)
tree6b94e2d5e3498149057d124f41f5f25ffe57bb84 /protocols
parentf71c05fadaa38b0719f75d8ba5fc26ea230b478e (diff)
VKontakte:
add destroy options for offline chats more processing for kick and invite git-svn-id: http://svn.miranda-ng.org/main/trunk@10795 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/VKontakte/src/misc.cpp19
-rw-r--r--protocols/VKontakte/src/vk_chats.cpp48
-rw-r--r--protocols/VKontakte/src/vk_proto.cpp10
-rw-r--r--protocols/VKontakte/src/vk_proto.h4
-rw-r--r--protocols/VKontakte/src/vk_thread.cpp14
5 files changed, 88 insertions, 7 deletions
diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp
index 8c15e75c20..9e69a3a29d 100644
--- a/protocols/VKontakte/src/misc.cpp
+++ b/protocols/VKontakte/src/misc.cpp
@@ -57,6 +57,23 @@ MCONTACT CVkProto::FindUser(LONG dwUserid, bool bCreate)
return hNewContact;
}
+MCONTACT CVkProto::FindChat(LONG dwUserid)
+{
+ if (!dwUserid)
+ return NULL;
+
+ for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ LONG dbUserid = getDword(hContact, "vk_chat_id", -1);
+ if (dbUserid == -1)
+ continue;
+
+ if (dbUserid == dwUserid)
+ return hContact;
+ }
+
+ return NULL;
+}
+
bool CVkProto::CheckMid(int guid)
{
for (int i=m_sendIds.getCount()-1; i >= 0; i--)
@@ -555,7 +572,7 @@ char* CVkProto::GetStickerId (const char* Msg, int &stickerid)
iRes = sscanf(Msg, "[sticker:%d]", &stickerid);
if (iRes == 1){
mir_snprintf(HeadMsg, 32, "[sticker:%d]", stickerid);
- int retLen = strlen(HeadMsg);
+ size_t retLen = strlen(HeadMsg);
if (retLen<strlen(Msg))
retMsg = mir_strdup(&Msg[retLen]);
return retMsg;
diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp
index 2854fcbf1b..4698ae05dc 100644
--- a/protocols/VKontakte/src/vk_chats.cpp
+++ b/protocols/VKontakte/src/vk_chats.cpp
@@ -32,6 +32,11 @@ CVkChatInfo* CVkProto::AppendChat(int id, JSONNODE *pDlg)
if (id == 0)
return NULL;
+ MCONTACT chatContact = FindChat(id);
+ if (chatContact)
+ if (getBool(chatContact, "kicked", false))
+ return NULL;
+
CVkChatInfo *c = m_chats.find((CVkChatInfo*)&id);
if (c != NULL)
return c;
@@ -71,8 +76,10 @@ CVkChatInfo* CVkProto::AppendChat(int id, JSONNODE *pDlg)
}
setDword(gci.hContact, "vk_chat_id", id);
+ db_unset(gci.hContact, m_szModuleName, "off");
if (json_as_int(json_get(pDlg, "left")) == 1){
+ setByte(gci.hContact, "off", 1);
m_chats.remove(c);
return NULL;
}
@@ -136,7 +143,8 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
gce.ptszText = tszTitle;
CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce);
}
- if (json_as_int(json_get(info, "left")) == 1){
+ if ((json_as_int(json_get(info, "left")) == 1) || (json_as_int(json_get(info, "kicked")) == 1)){
+ setByte(cc->m_hContact, "kicked", true);
LeaveChat(cc->m_chatid);
return;
}
@@ -480,6 +488,9 @@ INT_PTR __cdecl CVkProto::OnJoinChat(WPARAM hContact, LPARAM)
{
debugLogA("CVkProto::OnJoinChat");
+ if (getBool(hContact, "kicked", false))
+ return 1;
+
int chat_id = getDword(hContact, "vk_chat_id", -1);
if (chat_id == -1)
@@ -491,7 +502,7 @@ INT_PTR __cdecl CVkProto::OnJoinChat(WPARAM hContact, LPARAM)
<< VER_API;
pReq->AddHeader("Content-Type", "application/x-www-form-urlencoded");
Push(pReq);
-
+ db_unset(hContact, "off", false);
return 0;
}
@@ -528,6 +539,8 @@ void CVkProto::LeaveChat(int chat_id, bool close_window, bool delete_chat)
CallServiceSync(MS_GC_EVENT, close_window? SESSION_TERMINATE:SESSION_OFFLINE, (LPARAM)&gce);
if (delete_chat)
CallService(MS_DB_CONTACT_DELETE, (WPARAM)cc->m_hContact, 0);
+ else
+ setByte(cc->m_hContact, "off", true);
m_chats.remove(cc);
}
@@ -536,6 +549,10 @@ void CVkProto::KickFromChat(int chat_id, int user_id, JSONNODE* pMsg)
debugLogA("CVkProto::KickFromChat (%d)", user_id);
if (user_id == m_myUserId)
return;
+
+ CVkChatInfo *cc = (CVkChatInfo*)m_chats.find((CVkChatInfo*)&chat_id);
+ if (cc == NULL)
+ return;
MCONTACT hContact = FindUser(user_id, false);
CMString msg = json_as_string(json_get(pMsg, "body"));
@@ -550,6 +567,7 @@ void CVkProto::KickFromChat(int chat_id, int user_id, JSONNODE* pMsg)
AppendChatMessage(chat_id, pMsg, false);
MsgPopup(hContact, msg, TranslateT("Chat"));
+ setByte(cc->m_hContact, "kicked", 1);
LeaveChat(chat_id);
}
@@ -564,6 +582,32 @@ void CVkProto::OnChatLeave(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
}
+INT_PTR __cdecl CVkProto::SvcDestroyKickChat(WPARAM hContact, LPARAM)
+{
+ debugLogA("CVkProto::SvcDestroyKickChat");
+
+ if (!getBool(hContact, "off", false))
+ return 1;
+
+ int chat_id = getDword(hContact, "vk_chat_id", -1);
+ if (chat_id == -1)
+ return 1;
+
+ CMStringA code;
+ code.Format("var Hist = API.messages.getHistory({\"chat_id\":%d, \"count\":200});"
+ "var countMsg = Hist.count;var itemsMsg = Hist.items@.id; "
+ "while (countMsg > 0) { API.messages.delete({\"message_ids\":itemsMsg});"
+ "Hist=API.messages.getHistory({\"chat_id\":%d, \"count\":200});"
+ "countMsg = Hist.count;itemsMsg = Hist.items@.id;}; return 1;", chat_id, chat_id);
+ Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.json", true, &CVkProto::OnReceiveSmth)
+ << CHAR_PARAM("code", code)
+ << VER_API);
+
+ CallService(MS_DB_CONTACT_DELETE, (WPARAM)hContact, 0);
+
+ return 0;
+}
+
void CVkProto::OnChatDestroy(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
debugLogA("CVkProto::OnChatDestroy %d", reply->resultCode);
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp
index d8ad1d70d8..cabf6d9c84 100644
--- a/protocols/VKontakte/src/vk_proto.cpp
+++ b/protocols/VKontakte/src/vk_proto.cpp
@@ -131,6 +131,7 @@ void CVkProto::InitMenus()
CreateProtoService(PS_DELETEFRIEND, &CVkProto::SvcDeleteFriend);
CreateProtoService(PS_BANUSER, &CVkProto::SvcBanUser);
CreateProtoService(PS_REPORTABUSE, &CVkProto::SvcReportAbuse);
+ CreateProtoService(PS_DESTROYKICKCHAT, &CVkProto::SvcDestroyKickChat);
CLISTMENUITEM mi = { sizeof(mi) };
char szService[100];
@@ -195,6 +196,13 @@ void CVkProto::InitMenus()
mi.ptszName = LPGENT("Report abuse");
mi.pszService = szService;
g_hContactMenuItems[CMI_REPORTABUSE] = Menu_AddContactMenuItem(&mi);
+
+ mir_snprintf(szService, sizeof(szService), "%s%s", m_szModuleName, PS_DESTROYKICKCHAT);
+ mi.position = -200001000 + CMI_DESTROYKICKCHAT;
+ mi.icolibItem = Skin_GetIconByHandle(GetIconHandle(IDI_FRIENDDEL));
+ mi.ptszName = LPGENT("Destroy room");
+ mi.pszService = szService;
+ g_hContactMenuItems[CMI_DESTROYKICKCHAT] = Menu_AddContactMenuItem(&mi);
}
int CVkProto::OnPreBuildContactMenu(WPARAM hContact, LPARAM)
@@ -207,7 +215,7 @@ int CVkProto::OnPreBuildContactMenu(WPARAM hContact, LPARAM)
Menu_ShowItem(g_hContactMenuItems[CMI_DELETEFRIEND], bisFriend);
Menu_ShowItem(g_hContactMenuItems[CMI_BANUSER], !isChatRoom(hContact));
Menu_ShowItem(g_hContactMenuItems[CMI_REPORTABUSE], !isChatRoom(hContact));
-
+ Menu_ShowItem(g_hContactMenuItems[CMI_DESTROYKICKCHAT], isChatRoom(hContact)&&getBool(hContact, "off", false));
return 0;
}
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h
index 85208c1f14..181ca23fb0 100644
--- a/protocols/VKontakte/src/vk_proto.h
+++ b/protocols/VKontakte/src/vk_proto.h
@@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define PS_DELETEFRIEND "/DeleteFriend"
#define PS_BANUSER "/BanUser"
#define PS_REPORTABUSE "/ReportAbuse"
+#define PS_DESTROYKICKCHAT "/DestroyKickChat"
#define MAXHISTORYMIDSPERONE 200
#define MAX_RETRIES 10
@@ -237,6 +238,7 @@ struct CVkProto : public PROTO<CVkProto>
INT_PTR __cdecl SvcBanUser(WPARAM hContact, LPARAM);
INT_PTR __cdecl SvcReportAbuse(WPARAM hContact, LPARAM);
INT_PTR __cdecl SvcGetAllServerHistory(WPARAM hContact, LPARAM);
+ INT_PTR __cdecl SvcDestroyKickChat(WPARAM hContact, LPARAM);
void InitMenus();
void UnInitMenus();
int __cdecl OnPreBuildContactMenu(WPARAM hContact, LPARAM);
@@ -343,6 +345,7 @@ private:
CMI_DELETEFRIEND,
CMI_BANUSER,
CMI_REPORTABUSE,
+ CMI_DESTROYKICKCHAT,
CMI_COUNT
};
enum ProtoMenuIndexes {
@@ -392,6 +395,7 @@ private:
void ReloadAvatarInfo(MCONTACT hContact);
MCONTACT FindUser(LONG userid, bool bCreate = false);
+ MCONTACT FindChat(LONG dwUserid);
void SetAllContactStatuses(int status);
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp
index 4089e27ed0..fe75ca477c 100644
--- a/protocols/VKontakte/src/vk_thread.cpp
+++ b/protocols/VKontakte/src/vk_thread.cpp
@@ -574,10 +574,18 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
if (chat_id != 0) {
CMString action_chat = json_as_string(json_get(pMsg, "action"));
- CMString action_mid = json_as_string(json_get(pMsg, "action_mid"));
- if ((action_chat == "chat_kick_user") && (_ttoi(action_mid.GetBuffer()) == m_myUserId))
+ int action_mid = _ttoi(json_as_string(json_get(pMsg, "action_mid")));
+ if ((action_chat == "chat_kick_user") && (action_mid == m_myUserId))
KickFromChat(chat_id, uid, pMsg);
- else
+ else if ((action_chat == "chat_invite_user") && (action_mid == m_myUserId)){
+ MCONTACT chatContact = FindChat(chat_id);
+ if (chatContact){
+ db_unset(chatContact, m_szModuleName, "kicked");
+ db_unset(chatContact, m_szModuleName, "off");
+ }
+ AppendChatMessage(chat_id, pMsg, false);
+ }
+ else
AppendChatMessage(chat_id, pMsg, false);
continue;
}