From 3acc3adbcba5afbb0527a4385e6b2f0c63e960da Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Mon, 1 Jul 2013 19:00:11 +0000 Subject: Skype: - removed ignore command - block command behavior like in official client now - added blocked list in account options - added history sync Note: this commit may contain non-working code git-svn-id: http://svn.miranda-ng.org/main/trunk@5203 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Skype/src/resource.h | 15 +- protocols/Skype/src/skype.h | 2 +- protocols/Skype/src/skype_blocked.cpp | 363 +++++++++++++++++++++++++++++++++ protocols/Skype/src/skype_dialogs.cpp | 10 +- protocols/Skype/src/skype_events.cpp | 12 +- protocols/Skype/src/skype_icons.cpp | 1 - protocols/Skype/src/skype_menus.cpp | 99 ++++++--- protocols/Skype/src/skype_messages.cpp | 127 ++++++++++++ protocols/Skype/src/skype_proto.h | 28 ++- 9 files changed, 613 insertions(+), 44 deletions(-) create mode 100644 protocols/Skype/src/skype_blocked.cpp (limited to 'protocols/Skype/src') diff --git a/protocols/Skype/src/resource.h b/protocols/Skype/src/resource.h index da62894a98..73ade12bde 100644 --- a/protocols/Skype/src/resource.h +++ b/protocols/Skype/src/resource.h @@ -1,6 +1,6 @@ //{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. -// Used by D:\Projects\CPlusPlus\MirandaNG\protocols\Skype\res\Resource.rc +// Used by E:\Projects\C++\MirandaNG\protocols\Skype\res\Resource.rc // #define IDD_ACCMGR 9 #define IDD_OPT_MAIN 10 @@ -21,7 +21,6 @@ #define IDD_CHATROOM_CREATE 111 #define IDD_CHATROOM_CONFIG 112 #define IDI_DELETE 112 -#define IDI_IGNORE 114 #define IDI_BLOCK 115 #define IDI_CONFERENCE 116 #define IDI_CONTACT 117 @@ -77,6 +76,7 @@ #define IDC_ROLES 1047 #define IDC_CHAT_ROLES 1047 #define IDC_CHAT_GUIDLINE3 1047 +#define IDC_CONTACTS 1047 #define IDC_CHAT_JOINING2 1048 #define IDC_CHAT_SECURED 1048 #define IDC_CHAT_GUIDLINE4 1048 @@ -90,10 +90,19 @@ #define IDC_CHECK1 1052 #define IDC_COMBO2 1053 #define IDC_CHECK2 1054 +#define IDC_BLOCK 1054 +#define ID_CANCEL 1055 +#define IDC_REPORT_ABUSE 1057 +#define IDC_REMOVE_FROM_CL 1058 +#define IDC_MESSAGE 1060 #define IDC_HEADERBAR 1320 #define IDD_BOOKMARKS 3001 #define IDD_IGNORE_LIST 3001 +#define IDD_BLOCK 3001 #define IDC_BM_LIST 3002 +#define IDC_BC_LIST 3002 +#define IDC_LIST 3002 +#define IDD_OPT_BLOCKED 3002 // Next default values for new objects // @@ -101,7 +110,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 118 #define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1054 +#define _APS_NEXT_CONTROL_VALUE 1061 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/protocols/Skype/src/skype.h b/protocols/Skype/src/skype.h index 696551b041..84aec32161 100644 --- a/protocols/Skype/src/skype.h +++ b/protocols/Skype/src/skype.h @@ -72,8 +72,8 @@ enum CMI_AUTH_REQUEST, CMI_AUTH_GRANT, CMI_AUTH_REVOKE, - CMI_IGNORE, CMI_BLOCK, + CMI_HISTORY, CMI_MAX // this item shall be the last one }; diff --git a/protocols/Skype/src/skype_blocked.cpp b/protocols/Skype/src/skype_blocked.cpp new file mode 100644 index 0000000000..13f32441c9 --- /dev/null +++ b/protocols/Skype/src/skype_blocked.cpp @@ -0,0 +1,363 @@ +#include "skype.h" +#include "skype_chat.h" + +int CSkypeProto::BlockCommand(WPARAM wParam, LPARAM lParam) +{ + HANDLE hContact = (HANDLE)wParam; + if (hContact) + { + SEString sid(_T2A(::db_get_wsa(hContact, this->m_szModuleName, SKYPE_SETTINGS_SID))); + + ContactRef contact; + if ( !this->GetContact(sid, contact) || !contact) + return 0; + + bool isBlocked = false; + if (contact->IsMemberOfHardwiredGroup(ContactGroup::CONTACTS_BLOCKED_BY_ME, isBlocked) && !isBlocked) + { + BlockParam param(hContact, this); + if (::DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_BLOCK), NULL, CSkypeProto::SkypeBlockProc, (LPARAM)¶m) == IDOK) + { + if ( !contact->SetBlocked(true, param.abuse)) + return 0; + + if (param.remove) + { + contact->SetBuddyStatus(false); + this->contactList.remove_val(contact); + ::CallService(MS_DB_CONTACT_DELETE, wParam, 0); + } + else if (::db_get_b(hContact, this->m_szModuleName, "IsSkypeOut", 0) > 0) + ::db_set_w(hContact, this->m_szModuleName, "Status", ID_STATUS_OFFLINE); + } + } + else + { + if (contact->SetBlocked(false)) + if (::db_get_b(hContact, this->m_szModuleName, "IsSkypeOut", 0) > 0) + ::db_set_w(hContact, this->m_szModuleName, "Status", ID_STATUS_ONTHEPHONE); + } + } + + return 0; +} + +INT_PTR CSkypeProto::OpenBlockedListCommand(WPARAM, LPARAM) +{ + OPENOPTIONSDIALOG ood; + ood.cbSize = sizeof(ood); + ood.pszGroup = "Network"; + ood.pszPage = _T2A(this->m_tszUserName); + ood.pszTab = "Bloked contacts"; + return ::Options_Open(&ood); +} + +INT_PTR CALLBACK CSkypeProto::SkypeBlockProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + BlockParam *param = (BlockParam *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + + switch (msg) + { + case WM_INITDIALOG: + if (lParam) + { + param = (BlockParam *)lParam; + ::SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); + ::TranslateDialogDefault(hwndDlg); + + ::SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)::Skin_GetIcon("Skype_block", ICON_BIG)); + ::SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)::Skin_GetIcon("Skype_block")); + + wchar_t text[1024]; + ::mir_sntprintf( + text, + SIZEOF(text), + L"Are you sure you want to block %s (%s)?\nThey won't be able to contact you\nand won't appear in your Contact List.", + ptrW(::db_get_wsa(param->hContact, param->ppro->m_szModuleName, "Nick")), + ptrW(::db_get_wsa(param->hContact, param->ppro->m_szModuleName, SKYPE_SETTINGS_SID))); + ::SetDlgItemText(hwndDlg, IDC_MESSAGE, text), + + ::Utils_RestoreWindowPosition(hwndDlg, 0, MODULE, "BlockWindow"); + } + break; + + case WM_COMMAND: + if (HIWORD( wParam ) == BN_CLICKED) + { + switch(LOWORD(wParam)) + { + case IDOK: + param->remove = ::IsDlgButtonChecked(hwndDlg, IDC_REMOVE_FROM_CL) > 0; + param->abuse = ::IsDlgButtonChecked(hwndDlg, IDC_REPORT_ABUSE) > 0; + + ::Utils_SaveWindowPosition(hwndDlg, NULL, MODULE, "BlockWindow"); + ::Skin_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0)); + ::Skin_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, 0)); + ::EndDialog(hwndDlg, IDOK); + break; + + case IDCANCEL: + ::Utils_SaveWindowPosition(hwndDlg, NULL, MODULE, "BlockWindow"); + ::Skin_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0)); + ::Skin_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, 0)); + ::EndDialog(hwndDlg, IDCANCEL); + break; + } + } + break; + } + return FALSE; +} + +static WNDPROC oldWndProc = NULL; + +static LRESULT CALLBACK SkypeBlockedOptionsSubProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + if (msg == WM_LBUTTONDOWN) + { + LVHITTESTINFO hi; + hi.pt.x = LOWORD(lParam); hi.pt.y = HIWORD(lParam); + ListView_SubItemHitTest(hwnd, &hi); + if (hi.iSubItem == 1) + { + LVITEM lvi = {0}; + lvi.mask = LVIF_IMAGE | LVIF_PARAM; + lvi.stateMask = -1; + lvi.iItem = hi.iItem; + if (ListView_GetItem(hwnd, &lvi)) + { + CContact *contact = (CContact *)lvi.lParam; + + if (contact->SetBlocked(false)) + { + SEString data; + contact->GetIdentity(data); + + ListView_DeleteItem(hwnd, lvi.iItem); + + ::SendMessage( + ::GetDlgItem(GetParent(hwnd), IDC_CONTACTS), + CB_ADDSTRING, + 0, + (LPARAM)ptrW(::Utf8DecodeW(data))); + } + } + } + } + + return ::CallWindowProc(oldWndProc, hwnd, msg, wParam, lParam); +} + +int ImageList_AddIconFromIconLib(HIMAGELIST hIml, const char *name) +{ + HICON icon = ::Skin_GetIconByHandle(::Skin_GetIconHandle(name)); + int res = ImageList_AddIcon(hIml, icon); + ::Skin_ReleaseIcon(icon); + return res; +} + +INT_PTR CALLBACK CSkypeProto::SkypeBlockedOptionsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + CSkypeProto *ppro = (CSkypeProto *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + + switch (msg) + { + case WM_INITDIALOG: + if (lParam) + { + ppro = (CSkypeProto *)lParam; + ::SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); + + ::TranslateDialogDefault(hwndDlg); + + HWND hwndList = ::GetDlgItem(hwndDlg, IDC_LIST); + { // IDC_BM_LIST setup + oldWndProc = (WNDPROC)::SetWindowLongPtr(hwndList, GWLP_WNDPROC, (LONG_PTR)SkypeBlockedOptionsSubProc); + + HIMAGELIST hIml = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 4, 0); + ImageList_AddIconFromIconLib(hIml, "Skype_contact"); + ImageList_AddIconFromIconLib(hIml, "Skype_delete"); + ListView_SetImageList(hwndList, hIml, LVSIL_SMALL); + /// + LVCOLUMN lvc = {0}; + lvc.mask = LVCF_WIDTH | LVCF_TEXT; + //lvc.fmt = LVCFMT_JUSTIFYMASK; + lvc.pszText = TranslateT("Name"); + lvc.cx = 220; // width of column in pixels + ListView_InsertColumn(hwndList, 0, &lvc); + //lvc.fmt = LVCFMT_RIGHT; + lvc.pszText = L""; + lvc.cx = 32 - GetSystemMetrics(SM_CXVSCROLL); // width of column in pixels + ListView_InsertColumn(hwndList, 1, &lvc); + /// + ::SendMessage(hwndList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_SUBITEMIMAGES | LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP); + + if ( !ppro->IsOnline()) + { + ::EnableWindow(hwndList, FALSE); + ::EnableWindow(::GetDlgItem(hwndDlg, IDC_CONTACTS), FALSE); + } + } + + if (ppro->IsOnline()) + { + SEString data; + ContactGroupRef blockedList; + ppro->GetHardwiredContactGroup(ContactGroup::CONTACTS_BLOCKED_BY_ME, blockedList); + + CContact::Refs contacts; + blockedList->GetContacts(contacts); + for (size_t i = 0; i < contacts.size(); i++) + { + auto contact = contacts[i]; + + LVITEM lvi = {0}; + lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM; + lvi.iItem = (int)i; + lvi.iImage = 0; + lvi.lParam = (LPARAM)contact.fetch(); + lvi.pszText = ptrW(::mir_utf8decodeW(contact->GetSid())); + int iRow = ListView_InsertItem(hwndList, &lvi); + + if (iRow != -1) + { + lvi.iItem = iRow; + lvi.mask = LVIF_IMAGE; + lvi.iSubItem = 1; + lvi.iImage = 1; + ListView_SetItem(hwndList, &lvi); + } + } + /// + int nItem = 0; + HANDLE hContact = NULL; + + ::EnterCriticalSection(&ppro->contact_search_lock); + + for (hContact = ::db_find_first(ppro->m_szModuleName); hContact && !ppro->IsChatRoom(hContact); hContact = ::db_find_next(hContact, ppro->m_szModuleName)) + { + ptrW sid(::db_get_wsa(hContact, ppro->m_szModuleName, SKYPE_SETTINGS_SID)); + + ContactRef contact; + ppro->GetContact((char *)_T2A(sid), contact); + if ( !contacts.contains(contact)) + { + nItem = ::SendMessage( + ::GetDlgItem(hwndDlg, IDC_CONTACTS), + CB_ADDSTRING, + 0, + (LPARAM)sid); + + ::SendMessage( + ::GetDlgItem(hwndDlg, IDC_CONTACTS), + CB_SETITEMDATA, + nItem, + (LPARAM)hContact); + } + } + + ::LeaveCriticalSection(&ppro->contact_search_lock); + } + + } + break; + + case WM_COMMAND: + { + switch(LOWORD(wParam)) + { + case IDC_CONTACTS: + ::EnableWindow(::GetDlgItem(hwndDlg, IDC_BLOCK), TRUE); + break; + + case IDC_BLOCK: + { + int i = ::SendMessage(::GetDlgItem(hwndDlg, IDC_CONTACTS), CB_GETCURSEL, 0, 0); + + HANDLE hContact = (HANDLE)::SendMessage(GetDlgItem(hwndDlg, IDC_CONTACTS), CB_GETITEMDATA, i, 0); + if ( !hContact) + break; + + ptrW sid(::db_get_wsa(hContact, ppro->m_szModuleName, SKYPE_SETTINGS_SID)); + + SEString data; + ContactRef contact; + if (!ppro->GetContact((char *)_T2A(sid), contact) || !contact) + break; + + BlockParam param(hContact, ppro); + if (::DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_BLOCK), NULL, CSkypeProto::SkypeBlockProc, (LPARAM)¶m) != IDOK) + break; + + contact->SetBlocked(true, param.abuse); + + if (param.remove) + { + contact->SetBuddyStatus(false); + ppro->contactList.remove_val(contact); + ::CallService(MS_DB_CONTACT_DELETE, wParam, 0); + } + + if (contact->SetBlocked(true)) + { + LVITEM lvi = {0}; + lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM; + lvi.iItem = (int)i; + lvi.iImage = 0; + lvi.lParam = (LPARAM)contact.fetch(); + lvi.pszText = sid; + int iRow = ListView_InsertItem(::GetDlgItem(hwndDlg, IDC_LIST), &lvi); + + if (iRow != -1) + { + lvi.iItem = iRow; + lvi.mask = LVIF_IMAGE; + lvi.iSubItem = 1; + lvi.iImage = 1; + ListView_SetItem(::GetDlgItem(hwndDlg, IDC_LIST), &lvi); + } + ::SendMessage(::GetDlgItem(hwndDlg, IDC_CONTACTS), CB_DELETESTRING, i, 0); + } + } + break; + } + } + break; + + case WM_NOTIFY: + if (reinterpret_cast(lParam)->code == PSN_APPLY && !ppro->IsOnline()) + { + return TRUE; + } + break; + + switch(LOWORD(wParam)) + { + case IDC_BM_LIST: + if (((LPNMHDR)lParam)->code == NM_DBLCLK) + { + HWND hwndList = ::GetDlgItem(hwndDlg, IDC_BM_LIST); + int iItem = ListView_GetNextItem(hwndList, -1, LVNI_ALL | LVNI_SELECTED); + if (iItem < 0) break; + LVITEM lvi = {0}; + lvi.mask = LVIF_PARAM | LVIF_GROUPID; + lvi.stateMask = -1; + lvi.iItem = iItem; + if (ListView_GetItem(hwndList, &lvi)) + { + SEString data; + if (lvi.iGroupId == 1) + { + CContact *contact = (CContact *)lvi.lParam; + + contact->GetIdentity(data); + ptrW sid(::mir_utf8decodeW(data)); + ::CallService(MS_MSG_SENDMESSAGE, (WPARAM)ppro->GetContactBySid(sid), 0); + } + } + } + } + break; + } + return FALSE; +} \ No newline at end of file diff --git a/protocols/Skype/src/skype_dialogs.cpp b/protocols/Skype/src/skype_dialogs.cpp index d088754d0f..427c924c7f 100644 --- a/protocols/Skype/src/skype_dialogs.cpp +++ b/protocols/Skype/src/skype_dialogs.cpp @@ -13,11 +13,11 @@ INT_PTR CALLBACK CSkypeProto::SkypeMainOptionsProc(HWND hwnd, UINT message, WPAR proto = (CSkypeProto *)lParam; ::SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam); { - mir_ptr sid( ::db_get_wsa(NULL, proto->m_szModuleName, SKYPE_SETTINGS_SID)); + ptrW sid( ::db_get_wsa(NULL, proto->m_szModuleName, SKYPE_SETTINGS_SID)); SetDlgItemText(hwnd, IDC_SL, sid); } { - mir_ptr pwd( ::db_get_sa(NULL, proto->m_szModuleName, SKYPE_SETTINGS_PASSWORD)); + ptrA pwd( ::db_get_sa(NULL, proto->m_szModuleName, SKYPE_SETTINGS_PASSWORD)); if (pwd) ::CallService(MS_DB_CRYPT_DECODESTRING, ::strlen(pwd), pwd); @@ -48,7 +48,7 @@ INT_PTR CALLBACK CSkypeProto::SkypeMainOptionsProc(HWND hwnd, UINT message, WPAR SendDlgItemMessage(hwnd, IDC_GROUP, EM_LIMITTEXT, SKYPE_GROUP_NAME_LIMIT, 0); - mir_ptr defgroup( db_get_wsa(NULL, proto->m_szModuleName, SKYPE_SETTINGS_DEF_GROUP)); + ptrW defgroup( db_get_wsa(NULL, proto->m_szModuleName, SKYPE_SETTINGS_DEF_GROUP)); SetDlgItemText(hwnd, IDC_GROUP, defgroup); } return TRUE; @@ -378,7 +378,7 @@ INT_PTR CALLBACK CSkypeProto::SkypeDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam if (!szProto) break; - ::SetDlgItemText(hwndDlg, IDC_SID, mir_ptr(::db_get_wsa(hContact, ppro->m_szModuleName, SKYPE_SETTINGS_SID))); + ::SetDlgItemText(hwndDlg, IDC_SID, ptrW(::db_get_wsa(hContact, ppro->m_szModuleName, SKYPE_SETTINGS_SID))); DBVARIANT dbv; if ( !::db_get_ts(hContact, ppro->m_szModuleName, "XStatusMsg", &dbv)) { @@ -724,7 +724,7 @@ INT_PTR CALLBACK CSkypeProto::HomeSkypeDlgProc(HWND hwndDlg, UINT msg, WPARAM wP else ::SetDlgItemText(hwndDlg, IDC_STATE, _T("")); - mir_ptr countr(::db_get_wsa(NULL, ppro->m_szModuleName, "Country")); + ptrW countr(::db_get_wsa(NULL, ppro->m_szModuleName, "Country")); for (int i = 0; i < g_cbCountries; i++) { if (g_countries[i].id != 0xFFFF && g_countries[i].id != 0) diff --git a/protocols/Skype/src/skype_events.cpp b/protocols/Skype/src/skype_events.cpp index 542ec235a0..0e2b8db926 100644 --- a/protocols/Skype/src/skype_events.cpp +++ b/protocols/Skype/src/skype_events.cpp @@ -102,15 +102,19 @@ int __cdecl CSkypeProto::OnOptionsInit(WPARAM wParam, LPARAM lParam) OPTIONSDIALOGPAGE odp = {0}; odp.cbSize = sizeof(odp); odp.hInstance = g_hInstance; - odp.ptszTitle = m_tszUserName; + odp.ptszTitle = this->m_tszUserName; odp.dwInitParam = LPARAM(this); odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR | ODPF_DONTTRANSLATE; - - odp.position = 271828; odp.ptszGroup = LPGENT("Network"); + odp.ptszTab = LPGENT("Account"); odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_MAIN); - odp.pfnDlgProc = SkypeMainOptionsProc; + odp.pfnDlgProc = CSkypeProto::SkypeMainOptionsProc; + ::Options_AddPage(wParam, &odp); + + odp.ptszTab = LPGENT("Bloked contacts"); + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_BLOCKED); + odp.pfnDlgProc = CSkypeProto::SkypeBlockedOptionsProc; ::Options_AddPage(wParam, &odp); return 0; diff --git a/protocols/Skype/src/skype_icons.cpp b/protocols/Skype/src/skype_icons.cpp index a04e6acbc0..5822cf2b37 100644 --- a/protocols/Skype/src/skype_icons.cpp +++ b/protocols/Skype/src/skype_icons.cpp @@ -10,7 +10,6 @@ _tag_iconList CSkypeProto::IconList[] = { LPGENT("Send contact"), "sendContacts", IDI_SEND_CONTACTS }, { LPGENT("Contact"), "contact", IDI_CONTACT }, { LPGENT("Delete"), "delete", IDI_DELETE }, - { LPGENT("Ignore"), "ignore", IDI_IGNORE }, { LPGENT("Block"), "block", IDI_BLOCK }, }; diff --git a/protocols/Skype/src/skype_menus.cpp b/protocols/Skype/src/skype_menus.cpp index 20b60f1546..f98ad39630 100644 --- a/protocols/Skype/src/skype_menus.cpp +++ b/protocols/Skype/src/skype_menus.cpp @@ -26,21 +26,32 @@ int CSkypeProto::OnPrebuildContactMenu(WPARAM wParam, LPARAM) bool authNeed = ::db_get_b(hContact, this->m_szModuleName, "Auth", 0) > 0; bool grantNeed = ::db_get_b(hContact, this->m_szModuleName, "Grant", 0) > 0; - bool ignored = ::db_get_b(hContact, this->m_szModuleName, "Ignore", 0) > 0; - + ::Menu_ShowItem(CSkypeProto::contactMenuItems[CMI_AUTH_REQUEST], ctrlPressed || authNeed); ::Menu_ShowItem(CSkypeProto::contactMenuItems[CMI_AUTH_GRANT], ctrlPressed || grantNeed); ::Menu_ShowItem(CSkypeProto::contactMenuItems[CMI_AUTH_REVOKE], ctrlPressed || (!grantNeed && !authNeed)); - ::Menu_ShowItem(CSkypeProto::contactMenuItems[CMI_BLOCK], ctrlPressed); - - CLISTMENUITEM clmi = { sizeof(clmi) }; - clmi.cbSize = sizeof(CLISTMENUITEM); - clmi.flags = CMIM_FLAGS; - //::CallService(MS_IGNORE_ISIGNORED, wParam, IGNOREEVENT_ALL); - if (::db_get_b(hContact, this->m_szModuleName, "Ignore", 0) == 1) - //clmi.flags |= CMIF_CHECKED; - clmi.icolibItem = CSkypeProto::GetSkinIconHandle("contact"); - ::CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)CSkypeProto::contactMenuItems[CMI_IGNORE], (LPARAM)&clmi); + ::Menu_ShowItem(CSkypeProto::contactMenuItems[CMI_HISTORY], TRUE); + + { + SEString sid(_T2A(::db_get_wsa(hContact, this->m_szModuleName, SKYPE_SETTINGS_SID))); + + ContactRef contact; + this->GetContact(sid, contact); + + bool isBlocked = false; + contact->IsMemberOfHardwiredGroup(ContactGroup::CONTACTS_BLOCKED_BY_ME, isBlocked); + + CLISTMENUITEM clmi = { sizeof(clmi) }; + clmi.cbSize = sizeof(CLISTMENUITEM); + clmi.flags = CMIM_FLAGS; + if (isBlocked) + { + clmi.flags |= CMIM_NAME | CMIM_ICON | CMIF_TCHAR; + clmi.icolibItem = CSkypeProto::GetSkinIconHandle("contact"); + clmi.ptszName = LPGENT("Unblock this person..."); + } + ::CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)CSkypeProto::contactMenuItems[CMI_BLOCK], (LPARAM)&clmi); + } } return 0; @@ -138,22 +149,58 @@ void CSkypeProto::InitMenus() CSkypeProto::contactMenuItems[CMI_AUTH_REVOKE] = ::Menu_AddContactMenuItem(&mi); ::CreateServiceFunction(mi.pszService, GlobalService<&CSkypeProto::RevokeAuth>); - // "Ignore" - mi.pszService = MODULE"/Ignore"; - mi.ptszName = LPGENT("Ignore"); - mi.position = -200001000 + CMI_IGNORE; - mi.icolibItem = CSkypeProto::GetSkinIconHandle("ignore"); - CSkypeProto::contactMenuItems[CMI_IGNORE] = ::Menu_AddContactMenuItem(&mi); - ::CreateServiceFunction(mi.pszService, GlobalService<&CSkypeProto::IgnoreCommand>); - // "Block" mi.pszService = MODULE"/Block"; - mi.ptszName = LPGENT("Block"); - //mi.flags |= CMIF_HIDDEN; + mi.ptszName = LPGENT("Block this person..."); mi.position = -200001000 + CMI_BLOCK; mi.icolibItem = CSkypeProto::GetSkinIconHandle("block"); CSkypeProto::contactMenuItems[CMI_BLOCK] = ::Menu_AddContactMenuItem(&mi); ::CreateServiceFunction(mi.pszService, GlobalService<&CSkypeProto::BlockCommand>); + + mi.pszService = MODULE"/SyncHistory"; + mi.ptszName = LPGENT("View old messages..."); + mi.flags = CMIF_TCHAR | CMIF_ROOTPOPUP; + mi.position = -200001000 + CMI_HISTORY; + mi.icolibItem = ::LoadSkinnedIconHandle(SKINICON_OTHER_HISTORY); + CSkypeProto::contactMenuItems[CMI_HISTORY] = ::Menu_AddContactMenuItem(&mi); + + mi.flags &= ~CMIF_ROOTPOPUP; + + mi.pszService = MODULE"/SyncHistoryDay"; + mi.ptszName = LPGENT("...by last day"); + mi.flags |= CMIF_CHILDPOPUP; + mi.position = -200001000 + CMI_HISTORY + 1; + mi.hParentMenu = CSkypeProto::contactMenuItems[CMI_HISTORY]; + //mi.icolibItem = CSkypeProto::GetSkinIconHandle("block"); + /*CSkypeProto::contactMenuItems[CMI_HISTORY] = */::Menu_AddContactMenuItem(&mi); + //::CreateServiceFunction(mi.pszService, GlobalService<&CSkypeProto::BlockCommand>); + + mi.pszService = MODULE"/SyncHistoryWeek"; + mi.ptszName = LPGENT("...by last week"); + mi.flags |= CMIF_CHILDPOPUP; + mi.position = -200001000 + CMI_HISTORY + 2; + mi.hParentMenu = CSkypeProto::contactMenuItems[CMI_HISTORY]; + //mi.icolibItem = CSkypeProto::GetSkinIconHandle("block"); + /*CSkypeProto::contactMenuItems[CMI_HISTORY] = */::Menu_AddContactMenuItem(&mi); + ::CreateServiceFunction(mi.pszService, GlobalService<&CSkypeProto::SyncLastWeekHistoryCommand>); + + mi.pszService = MODULE"/SyncHistoryMonth"; + mi.ptszName = LPGENT("...by last month"); + mi.flags |= CMIF_CHILDPOPUP; + mi.position = -200001000 + CMI_HISTORY + 3; + mi.hParentMenu = CSkypeProto::contactMenuItems[CMI_HISTORY]; + //mi.icolibItem = CSkypeProto::GetSkinIconHandle("block"); + /*CSkypeProto::contactMenuItems[CMI_HISTORY] = */::Menu_AddContactMenuItem(&mi); + //::CreateServiceFunction(mi.pszService, GlobalService<&CSkypeProto::BlockCommand>); + + mi.pszService = MODULE"/SyncHistory3Month"; + mi.ptszName = LPGENT("...by last 3 month"); + mi.flags |= CMIF_CHILDPOPUP; + mi.position = -200001000 + CMI_HISTORY + 4; + mi.hParentMenu = CSkypeProto::contactMenuItems[CMI_HISTORY]; + //mi.icolibItem = CSkypeProto::GetSkinIconHandle("block"); + /*CSkypeProto::contactMenuItems[CMI_HISTORY] = */::Menu_AddContactMenuItem(&mi); + ::CreateServiceFunction(mi.pszService, GlobalService<&CSkypeProto::SyncLast3MonthHistoryCommand>); } void CSkypeProto::UninitMenus() @@ -198,10 +245,10 @@ void CSkypeProto::OnInitStatusMenu() ::Menu_AddProtoMenuItem(&mi); // Invite Command - ::strcpy(tDest, "/IgnoreList"); - this->CreateServiceObj(tDest, &CSkypeProto::OpenIgnoreListCommand); - mi.ptszName = LPGENT("Ignore list"); + ::strcpy(tDest, "/BlockedeList"); + this->CreateServiceObj(tDest, &CSkypeProto::OpenBlockedListCommand); + mi.ptszName = LPGENT("Blocked contacts"); mi.position = 200000 + SMI_IGNORE_LIST; - mi.icolibItem = CSkypeProto::GetSkinIconHandle("ignore"); + mi.icolibItem = CSkypeProto::GetSkinIconHandle("block"); ::Menu_AddProtoMenuItem(&mi); } \ No newline at end of file diff --git a/protocols/Skype/src/skype_messages.cpp b/protocols/Skype/src/skype_messages.cpp index 2c398de2b0..16570e8081 100644 --- a/protocols/Skype/src/skype_messages.cpp +++ b/protocols/Skype/src/skype_messages.cpp @@ -207,4 +207,131 @@ void CSkypeProto::OnMessageEvent(const ConversationRef &conversation, const Mess } break; } +} + +void CSkypeProto::SyncMessageHystory(const ConversationRef &conversation, const time_t timestamp) +{ + if (conversation) + { + conversation->SetConsumedHorizon(timestamp); + MessageRefs oldMessages, newMessages; + conversation->GetLastMessages(oldMessages, newMessages, timestamp); + for (size_t i = 0; i < oldMessages.size(); i++) + this->OnMessageEvent(conversation, oldMessages[i]); + for (size_t i = 0; i < newMessages.size(); i++) + this->OnMessageEvent(conversation, newMessages[i]); + conversation->SetConsumedHorizon(time(NULL)); + } +} + +int CSkypeProto::SyncLastDayHistoryCommand(WPARAM wParam, LPARAM lParam) +{ + HANDLE hContact = (HANDLE)wParam; + if (hContact) + { + ptrW sid = ::db_get_wsa(hContact, this->m_szModuleName, SKYPE_SETTINGS_SID); + + ConversationRef conversation; + if ( !this->IsChatRoom(hContact)) + { + SEStringList target; + target.append((char *)ptrA(::mir_utf8encodeW(sid))); + this->GetConversationByParticipants(target, conversation); + } + else + this->GetConversationByIdentity((char *)ptrA(::mir_utf8encodeW(sid)), conversation); + + if (conversation) + { + time_t timestamp = time(NULL); + timestamp -= 60*60*24; + + this->SyncMessageHystory(conversation, timestamp); + } + } + return 0; +} + +int CSkypeProto::SyncLastWeekHistoryCommand(WPARAM wParam, LPARAM lParam) +{ + HANDLE hContact = (HANDLE)wParam; + if (hContact) + { + ptrW sid = ::db_get_wsa(hContact, this->m_szModuleName, SKYPE_SETTINGS_SID); + + ConversationRef conversation; + if ( !this->IsChatRoom(hContact)) + { + SEStringList target; + target.append((char *)ptrA(::mir_utf8encodeW(sid))); + this->GetConversationByParticipants(target, conversation); + } + else + this->GetConversationByIdentity((char *)ptrA(::mir_utf8encodeW(sid)), conversation); + + if (conversation) + { + time_t timestamp = time(NULL); + timestamp -= 60*60*24*7; + + this->SyncMessageHystory(conversation, timestamp); + } + } + return 0; +} + +int CSkypeProto::SyncLastMonthHistoryCommand(WPARAM wParam, LPARAM lParam) +{ + HANDLE hContact = (HANDLE)wParam; + if (hContact) + { + ptrW sid = ::db_get_wsa(hContact, this->m_szModuleName, SKYPE_SETTINGS_SID); + + ConversationRef conversation; + if ( !this->IsChatRoom(hContact)) + { + SEStringList target; + target.append((char *)ptrA(::mir_utf8encodeW(sid))); + this->GetConversationByParticipants(target, conversation); + } + else + this->GetConversationByIdentity((char *)ptrA(::mir_utf8encodeW(sid)), conversation); + + if (conversation) + { + time_t timestamp = time(NULL); + timestamp -= 60*60*24*30; + + this->SyncMessageHystory(conversation, timestamp); + } + } + return 0; +} + +int CSkypeProto::SyncLast3MonthHistoryCommand(WPARAM wParam, LPARAM lParam) +{ + HANDLE hContact = (HANDLE)wParam; + if (hContact) + { + ptrW sid = ::db_get_wsa(hContact, this->m_szModuleName, SKYPE_SETTINGS_SID); + + ConversationRef conversation; + if ( !this->IsChatRoom(hContact)) + { + SEStringList target; + target.append((char *)ptrA(::mir_utf8encodeW(sid))); + this->GetConversationByParticipants(target, conversation); + } + else + this->GetConversationByIdentity((char *)ptrA(::mir_utf8encodeW(sid)), conversation); + + if (conversation) + { + time_t timestamp = time(NULL); + timestamp -= 60*60*24*90; + + this->SyncMessageHystory(conversation, timestamp); + } + } + return 0; } \ No newline at end of file diff --git a/protocols/Skype/src/skype_proto.h b/protocols/Skype/src/skype_proto.h index fe310eb913..6fc0d128e7 100644 --- a/protocols/Skype/src/skype_proto.h +++ b/protocols/Skype/src/skype_proto.h @@ -19,6 +19,19 @@ struct ReadMessageParam CMessage::TYPE msgType; }; +struct BlockParam +{ + HANDLE hContact; + CSkypeProto *ppro; + bool remove; + bool abuse; + + BlockParam(HANDLE hContact, CSkypeProto *ppro) : ppro(ppro) + { + this->hContact = hContact; + } +}; + struct ChatRoomParam { wchar_t *id; @@ -282,6 +295,13 @@ protected: void OnMessageSent(const ConversationRef &conversation, const MessageRef &message); void OnMessageReceived(const ConversationRef &conversation, const MessageRef &message); + void SyncMessageHystory(const ConversationRef &conversation, const time_t timestamp); + + int __cdecl SyncLastDayHistoryCommand(WPARAM wParam, LPARAM lParam); + int __cdecl SyncLastWeekHistoryCommand(WPARAM wParam, LPARAM lParam); + int __cdecl SyncLastMonthHistoryCommand(WPARAM wParam, LPARAM lParam); + int __cdecl SyncLast3MonthHistoryCommand(WPARAM wParam, LPARAM lParam); + // contacts void OnContactsEvent(const ConversationRef &conversation, const MessageRef &message); void OnContactsSent(const ConversationRef &conversation, const MessageRef &message); @@ -456,12 +476,12 @@ protected: static int PrebuildContactMenu(WPARAM wParam, LPARAM lParam); int OnPrebuildContactMenu(WPARAM wParam, LPARAM); - // ignore list - int __cdecl IgnoreCommand(WPARAM, LPARAM); + // blocked list int __cdecl BlockCommand(WPARAM, LPARAM); - INT_PTR __cdecl OpenIgnoreListCommand(WPARAM, LPARAM); + INT_PTR __cdecl OpenBlockedListCommand(WPARAM, LPARAM); - static INT_PTR CALLBACK IgnoreListWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); + static INT_PTR CALLBACK SkypeBlockProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); + static INT_PTR CALLBACK SkypeBlockedOptionsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); // database bool IsMessageInDB(HANDLE hContact, DWORD timestamp, SEBinary &guid, int flag = 0); -- cgit v1.2.3