diff options
author | George Hazan <george.hazan@gmail.com> | 2014-01-11 20:14:55 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-01-11 20:14:55 +0000 |
commit | e5a8933a9842f02a322ecb59d720030e4e81593d (patch) | |
tree | a11239111aa37da4b46b40862ee269cce28a886e | |
parent | adbbb8b03e941e2c0b099b9e6a90f2b178dd1afa (diff) |
VK: chat creation works
git-svn-id: http://svn.miranda-ng.org/main/trunk@7600 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/VKontakte/res/resource.rc | 22 | ||||
-rw-r--r-- | protocols/VKontakte/src/resource.h | 8 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_chats.cpp | 128 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.cpp | 21 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.h | 6 |
5 files changed, 180 insertions, 5 deletions
diff --git a/protocols/VKontakte/res/resource.rc b/protocols/VKontakte/res/resource.rc index 92b9b0ee02..2c7897eb4d 100644 --- a/protocols/VKontakte/res/resource.rc +++ b/protocols/VKontakte/res/resource.rc @@ -80,6 +80,20 @@ BEGIN COMBOBOX IDC_CONTACT,7,26,177,99,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP
END
+IDD_GC_CREATE DIALOGEX 0, 0, 215, 229
+STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+CAPTION "Create group chat"
+FONT 8, "MS Shell Dlg", 0, 0, 0x1
+BEGIN
+ CONTROL "",IDC_CLIST,"CListControl",WS_TABSTOP | 0x1,4,17,206,116,WS_EX_CLIENTEDGE
+ LTEXT "Mark users you want to invite to a new chat",IDC_STATIC,4,7,206,8
+ LTEXT "New chat's title:",IDC_STATIC,9,142,198,8
+ EDITTEXT IDC_TITLE,4,153,206,52,ES_MULTILINE | ES_AUTOHSCROLL
+ DEFPUSHBUTTON "OK",IDOK,107,211,50,14
+ PUSHBUTTON "Cancel",IDCANCEL,160,211,50,14
+END
+
+
/////////////////////////////////////////////////////////////////////////////
//
// Icon
@@ -118,6 +132,14 @@ BEGIN TOPMARGIN, 7
BOTTOMMARGIN, 58
END
+
+ IDD_GC_CREATE, DIALOG
+ BEGIN
+ LEFTMARGIN, 4
+ RIGHTMARGIN, 210
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 225
+ END
END
#endif // APSTUDIO_INVOKED
diff --git a/protocols/VKontakte/src/resource.h b/protocols/VKontakte/src/resource.h index b6843eb8bb..6b3d64d274 100644 --- a/protocols/VKontakte/src/resource.h +++ b/protocols/VKontakte/src/resource.h @@ -6,6 +6,7 @@ #define IDD_CAPTCHAFORM 102
#define IDD_OPT_MAIN 103
#define IDD_INVITE 104
+#define IDD_GC_CREATE 105
#define IDI_KEYS 203
#define IDC_LOGIN 1001
#define IDC_PASSWORD 1002
@@ -19,16 +20,19 @@ #define IDC_SUBMIT 1010
#define IDC_DELIVERY 1011
#define IDC_GROUPNAME 1012
+#define IDC_CLIST 1013
#define IDC_CONTACT 1015
+#define IDC_BUTTON1 1018
+#define IDC_BUTTON2 1019
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
-#define _APS_NEXT_RESOURCE_VALUE 105
+#define _APS_NEXT_RESOURCE_VALUE 108
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1016
+#define _APS_NEXT_CONTROL_VALUE 1020
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp index c9aef8a24e..29b3a8a5e4 100644 --- a/protocols/VKontakte/src/vk_chats.cpp +++ b/protocols/VKontakte/src/vk_chats.cpp @@ -488,6 +488,11 @@ void CVkProto::NickMenuHook(CVkChatInfo *cc, GCHOOK *gch) _itoa(cc->m_chatid, szChatId, 10);
switch (gch->dwData) {
+ case IDM_INFO:
+ if (HANDLE hContact = FindUser(cu->m_uid))
+ CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)hContact, 0);
+ break;
+
case IDM_KICK:
HttpParam params[] = {
{ "chat_id", szChatId },
@@ -535,3 +540,126 @@ int CVkProto::OnGcMenuHook(WPARAM, LPARAM lParam) }
return 0;
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static void FilterContacts(HWND hwndDlg, CVkProto *ppro)
+{
+ HWND hwndClist = GetDlgItem(hwndDlg, IDC_CLIST);
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ char *proto = GetContactProto(hContact);
+ if (lstrcmpA(proto, ppro->m_szModuleName) || ppro->isChatRoom(hContact))
+ if (HANDLE hItem = (HANDLE)SendMessage(hwndClist, CLM_FINDCONTACT, (WPARAM)hContact, 0))
+ SendMessage(hwndClist, CLM_DELETEITEM, (WPARAM)hItem, 0);
+ }
+}
+
+static void ResetOptions(HWND hwndDlg)
+{
+ HWND hwndClist = GetDlgItem(hwndDlg, IDC_CLIST);
+ SendMessage(hwndClist, CLM_SETBKBITMAP, 0, 0);
+ SendMessage(hwndClist, CLM_SETBKCOLOR, GetSysColor(COLOR_WINDOW), 0);
+ SendMessage(hwndClist, CLM_SETGREYOUTFLAGS, 0, 0);
+ SendMessage(hwndClist, CLM_SETLEFTMARGIN, 4, 0);
+ SendMessage(hwndClist, CLM_SETINDENT, 10, 0);
+ SendMessage(hwndClist, CLM_SETHIDEEMPTYGROUPS, 1, 0);
+ SendMessage(hwndClist, CLM_GETHIDEOFFLINEROOT, 1, 0);
+ for (int i = 0; i <= FONTID_MAX; i++)
+ SendMessage(hwndClist, CLM_SETTEXTCOLOR, i, GetSysColor(COLOR_WINDOWTEXT));
+}
+
+static INT_PTR CALLBACK GcCreateDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ CVkProto *ppro = (CVkProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+ NMCLISTCONTROL* nmc;
+
+ switch (msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hwndDlg);
+
+ ppro = (CVkProto*)lParam;
+ SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
+ {
+ HWND hwndClist = GetDlgItem(hwndDlg, IDC_CLIST);
+ SetWindowLongPtr(hwndClist, GWL_STYLE,
+ GetWindowLongPtr(hwndClist, GWL_STYLE) | CLS_CHECKBOXES | CLS_HIDEEMPTYGROUPS | CLS_USEGROUPS | CLS_GREYALTERNATE | CLS_GROUPCHECKBOXES);
+ SendMessage(hwndClist, CLM_SETEXSTYLE, CLS_EX_DISABLEDRAGDROP | CLS_EX_TRACKSELECT, 0);
+
+ ResetOptions(hwndDlg);
+ }
+ return TRUE;
+
+ case WM_NOTIFY:
+ nmc = (NMCLISTCONTROL*)lParam;
+ if (nmc->hdr.idFrom == IDC_CLIST && nmc->hdr.code == CLN_LISTREBUILT)
+ FilterContacts(hwndDlg, ppro);
+ break;
+
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDCANCEL:
+ EndDialog(hwndDlg, 0);
+ return TRUE;
+
+ case IDOK:
+ HWND hwndClist = GetDlgItem(hwndDlg, IDC_CLIST);
+ CMStringA uids;
+ for (HANDLE hContact = db_find_first(ppro->m_szModuleName); hContact; hContact = db_find_next(hContact, ppro->m_szModuleName)) {
+ if (ppro->isChatRoom(hContact))
+ continue;
+
+ if (int hItem = SendMessage(hwndClist, CLM_FINDCONTACT, (WPARAM)hContact, 0)) {
+ if (SendMessage(hwndClist, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) {
+ int uid = ppro->getDword(hContact, "ID", 0);
+ if (uid != NULL) {
+ if (!uids.IsEmpty())
+ uids.AppendChar(',');
+ uids.AppendFormat("%d", uid);
+ }
+ }
+ }
+ }
+
+ TCHAR tszTitle[1024];
+ GetDlgItemText(hwndDlg, IDC_TITLE, tszTitle, SIZEOF(tszTitle));
+ ppro->CreateNewChat(uids, tszTitle);
+ EndDialog(hwndDlg, 0);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+INT_PTR CVkProto::SvcCreateChat(WPARAM, LPARAM)
+{
+ DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_GC_CREATE), NULL, GcCreateDlgProc, (LPARAM)this);
+ return 0;
+}
+
+void CVkProto::CreateNewChat(LPCSTR uids, LPCTSTR ptszTitle)
+{
+ ptrA szTitle(mir_utf8encodeT(ptszTitle));
+
+ HttpParam params[] = {
+ { "title", szTitle },
+ { "uids", uids },
+ { "access_token", m_szAccessToken }
+ };
+ PushAsyncHttpRequest(REQUEST_GET, "/method/messages.createChat.json", true, &CVkProto::OnCreateNewChat, SIZEOF(params), params);
+}
+
+void CVkProto::OnCreateNewChat(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
+{
+ debugLogA("CVkProto::OnCreateNewChat %d", reply->resultCode);
+ if (reply->resultCode != 200)
+ return;
+
+ JSONROOT pRoot;
+ JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
+ if (pResponse == NULL)
+ return;
+
+ int chat_id = json_as_int(pResponse);
+ if (chat_id != NULL)
+ AppendChat(chat_id, NULL);
+}
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index 9a0c122eaf..aad19ae036 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -31,10 +31,8 @@ CVkProto::CVkProto(const char *szModuleName, const TCHAR *ptszUserName) : CreateProtoService(PS_CREATEACCMGRUI, &CVkProto::SvcCreateAccMgrUI);
CreateProtoService(PS_GETAVATARINFOT, &CVkProto::SvcGetAvatarInfo);
- CreateProtoService(PS_GETAVATARCAPS, &CVkProto::SvcGetAvatarCaps);
+ CreateProtoService(PS_GETAVATARCAPS, &CVkProto::SvcGetAvatarCaps);
- HookProtoEvent(ME_GC_EVENT, &CVkProto::OnChatEvent);
- HookProtoEvent(ME_GC_BUILDMENU, &CVkProto::OnGcMenuHook);
HookProtoEvent(ME_OPT_INITIALISE, &CVkProto::OnOptionsInit);
TCHAR descr[512];
@@ -56,6 +54,7 @@ CVkProto::CVkProto(const char *szModuleName, const TCHAR *ptszUserName) : m_bServerDelivery = getBool("ServerDelivery", true);
+ // Chats
GCREGISTER gcr = { sizeof(gcr) };
gcr.ptszDispName = m_tszUserName;
gcr.pszModule = m_szModuleName;
@@ -63,6 +62,11 @@ CVkProto::CVkProto(const char *szModuleName, const TCHAR *ptszUserName) : gcr.pColors = sttColors;
CallServiceSync(MS_GC_REGISTER, NULL, (LPARAM)&gcr);
+ CreateProtoService(PS_CREATECHAT, &CVkProto::SvcCreateChat);
+
+ HookProtoEvent(ME_GC_EVENT, &CVkProto::OnChatEvent);
+ HookProtoEvent(ME_GC_BUILDMENU, &CVkProto::OnGcMenuHook);
+
// Set all contacts offline -- in case we crashed
SetAllContactStatuses(ID_STATUS_OFFLINE);
}
@@ -75,6 +79,17 @@ CVkProto::~CVkProto() int CVkProto::OnModulesLoaded(WPARAM wParam, LPARAM lParam)
{
+ char szService[100];
+ mir_snprintf(szService, sizeof(szService), "%s%s", m_szModuleName, PS_CREATECHAT);
+
+ CLISTMENUITEM mi = { sizeof(mi) };
+ mi.flags = CMIF_CHILDPOPUP;
+ mi.hParentMenu = MO_GetProtoRootMenu(m_szModuleName);
+ mi.pszService = szService;
+ mi.position = 10009;
+ mi.icolibItem = LoadSkinnedIconHandle(SKINICON_CHAT_JOIN);
+ mi.pszName = LPGEN("Create new chat");
+ Menu_AddProtoMenuItem(&mi);
return 0;
}
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index f75489f42a..34f036393a 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -15,6 +15,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#define PS_CREATECHAT "/CreateNewChat"
+
struct CVkProto;
typedef void (CVkProto::*VK_REQUEST_HANDLER)(NETLIBHTTPREQUEST*, struct AsyncHttpRequest*);
@@ -163,6 +165,9 @@ struct CVkProto : public PROTO<CVkProto> void SetServerStatus(int);
+ void CreateNewChat(LPCSTR uids, LPCTSTR ptrszTitle);
+ void OnCreateNewChat(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
+
__forceinline bool IsOnline() const { return m_bOnline; }
__forceinline LPCTSTR getGroup() const { return m_defaultGroup; }
@@ -250,6 +255,7 @@ private: void NickMenuHook(CVkChatInfo*, GCHOOK*);
LPTSTR ChangeChatTopic(CVkChatInfo*);
CVkChatInfo* GetChatById(LPCTSTR ptszId);
+ INT_PTR __cdecl SvcCreateChat(WPARAM, LPARAM);
CMString GetAttachmentDescr(JSONNODE*);
};
|