summaryrefslogtreecommitdiff
path: root/protocols/SkypeWeb
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-04-09 20:04:12 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-04-09 20:04:12 +0000
commit84261a1bda35dcdd1a4e56c3a573a169092f7363 (patch)
tree24031582c3cc692e87b2c33edc58862dc0be55e1 /protocols/SkypeWeb
parent5504428ab29cacbdc8bb7ca704e6108638bf4ecf (diff)
SkypeWeb: attempt to speed up contact lookup
git-svn-id: http://svn.miranda-ng.org/main/trunk@12717 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/SkypeWeb')
-rw-r--r--protocols/SkypeWeb/res/resource.rc2
-rw-r--r--protocols/SkypeWeb/src/resource.h3
-rw-r--r--protocols/SkypeWeb/src/skype_contacts.cpp25
-rw-r--r--protocols/SkypeWeb/src/skype_messages.cpp14
-rw-r--r--protocols/SkypeWeb/src/skype_options.cpp7
-rw-r--r--protocols/SkypeWeb/src/skype_proto.cpp8
-rw-r--r--protocols/SkypeWeb/src/skype_proto.h4
7 files changed, 41 insertions, 22 deletions
diff --git a/protocols/SkypeWeb/res/resource.rc b/protocols/SkypeWeb/res/resource.rc
index c9601ddf60..29e2448f21 100644
--- a/protocols/SkypeWeb/res/resource.rc
+++ b/protocols/SkypeWeb/res/resource.rc
@@ -114,7 +114,7 @@ BEGIN
LTEXT "Default group:",IDC_STATIC,12,51,69,12
EDITTEXT IDC_GROUP,81,49,217,12,ES_AUTOHSCROLL
GROUPBOX "Others",IDC_STATIC,5,79,298,71
- CONTROL "Automatic messages synchronization",IDC_CHECK2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,94,160,10
+ CONTROL "Automatic messages synchronization",IDC_AUTOSYNC,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,94,160,10
END
IDD_PASSWORD_EDITOR DIALOGEX 0, 0, 209, 75
diff --git a/protocols/SkypeWeb/src/resource.h b/protocols/SkypeWeb/src/resource.h
index f61d19353c..d86676ff3c 100644
--- a/protocols/SkypeWeb/src/resource.h
+++ b/protocols/SkypeWeb/src/resource.h
@@ -1,6 +1,6 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
-// Used by D:\Others\SVN\MirandaNG\trunk\protocols\SkypeWeb\res\resource.rc
+// Used by e:\Projects\C++\MirandaNG\protocols\SkypeWeb\res\resource.rc
//
#define IDI_SKYPE 100
#define IDC_SKYPENAME 101
@@ -12,6 +12,7 @@
#define IDC_SAVEPERMANENTLY 108
#define IDC_RADIO1 1027
#define IDC_CHECK2 1028
+#define IDC_AUTOSYNC 1028
// Next default values for new objects
//
diff --git a/protocols/SkypeWeb/src/skype_contacts.cpp b/protocols/SkypeWeb/src/skype_contacts.cpp
index c33e1c5dca..4e34d1b2e0 100644
--- a/protocols/SkypeWeb/src/skype_contacts.cpp
+++ b/protocols/SkypeWeb/src/skype_contacts.cpp
@@ -43,24 +43,31 @@ MCONTACT CSkypeProto::GetContactFromAuthEvent(MEVENT hEvent)
MCONTACT CSkypeProto::GetContact(const char *skypename)
{
- MCONTACT hContact = NULL;
- for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
+ std::map<std::string, MCONTACT>::iterator it = contactMap.find(skypename);
+ if (it != contactMap.end())
+ return it->second;
+
+ for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
{
- ptrA cSkypename(getStringA(hContact, SKYPE_SETTINGS_ID));
- if (mir_strcmpi(skypename, cSkypename) == 0)
- break;
+ std::string cSkypename = ptrA(getStringA(hContact, SKYPE_SETTINGS_ID));
+ if (!contactMap.count(cSkypename))
+ contactMap[cSkypename] = hContact;
+ if (mir_strcmpi(skypename, cSkypename.c_str()) == 0)
+ return hContact;
}
- return hContact;
+ return NULL;
}
MCONTACT CSkypeProto::AddContact(const char *skypename, bool isTemporary)
{
MCONTACT hContact = GetContact(skypename);
- if (!hContact)
+ if (hContact == NULL)
{
hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
CallService(MS_PROTO_ADDTOCONTACT, hContact, (LPARAM)m_szModuleName);
+ contactMap[skypename] = hContact;
+
setString(hContact, SKYPE_SETTINGS_ID, skypename);
DBVARIANT dbv;
@@ -247,5 +254,9 @@ INT_PTR CSkypeProto::OnGrantAuth(WPARAM hContact, LPARAM)
int CSkypeProto::OnContactDeleted(MCONTACT hContact, LPARAM)
{
+ /*ptrA skypename(getStringA(hContact, SKYPE_SETTINGS_ID));
+ std::map<std::string, MCONTACT>::iterator it = contactMap.find((char*)skypename);
+ if (it != contactMap.end())
+ contactMap.erase(it);*/
return 0;
} \ No newline at end of file
diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp
index eaffc50640..ae4d1ea513 100644
--- a/protocols/SkypeWeb/src/skype_messages.cpp
+++ b/protocols/SkypeWeb/src/skype_messages.cpp
@@ -1,6 +1,6 @@
#include "common.h"
-MEVENT CSkypeProto::GetMessageFromDB(MCONTACT hContact, const char *messageId, LONGLONG timestamp)
+MEVENT CSkypeProto::GetMessageFromDb(MCONTACT hContact, const char *messageId, LONGLONG timestamp)
{
mir_cslock lock(messageSyncLock);
@@ -32,7 +32,7 @@ MEVENT CSkypeProto::GetMessageFromDB(MCONTACT hContact, const char *messageId, L
MEVENT CSkypeProto::AddMessageToDb(MCONTACT hContact, DWORD timestamp, DWORD flags, const char *messageId, char *content, int emoteOffset)
{
- if (MEVENT hDbEvent = GetMessageFromDB(hContact, messageId, timestamp))
+ if (MEVENT hDbEvent = GetMessageFromDb(hContact, messageId, timestamp))
return hDbEvent;
size_t messageLength = mir_strlen(&content[emoteOffset]) + 1;
size_t messageIdLength = mir_strlen(messageId);
@@ -240,17 +240,17 @@ void CSkypeProto::OnSyncHistory(const NETLIBHTTPREQUEST *response)
if (lastMessage == NULL)
continue;
- ptrA clientMsgId(mir_t2a(ptrT(json_as_string(json_get(lastMessage, "clientmessageid")))));
- ptrA conversationLink(mir_t2a(ptrT(json_as_string(json_get(lastMessage, "conversationLink")))));
- LONGLONG composeTime(IsoToUnixTime(ptrT(json_as_string(json_get(lastMessage, "conversationLink")))));
+ char *clientMsgId = _T2A(json_as_string(json_get(lastMessage, "clientmessageid")));
+ char *conversationLink = _T2A(json_as_string(json_get(lastMessage, "conversationLink")));
+ time_t composeTime(IsoToUnixTime(ptrT(json_as_string(json_get(lastMessage, "conversationLink")))));
ptrA skypename(ContactUrlToName(conversationLink));
- if (skypename == NULL)
+ if (skypename == NULL)
return;
MCONTACT hContact = GetContact(skypename);
if (hContact == NULL && !IsMe(skypename))
hContact = AddContact(skypename, true);
- if (GetMessageFromDB(hContact, clientMsgId, composeTime) == NULL)
+ if (GetMessageFromDb(hContact, clientMsgId, composeTime) == NULL)
PushRequest(new GetHistoryRequest(ptrA(getStringA("registrationToken")), skypename, ptrA(getStringA("Server"))), &CSkypeProto::OnGetServerHistory);
}
} \ No newline at end of file
diff --git a/protocols/SkypeWeb/src/skype_options.cpp b/protocols/SkypeWeb/src/skype_options.cpp
index b45e9ca2d9..0d8d24861d 100644
--- a/protocols/SkypeWeb/src/skype_options.cpp
+++ b/protocols/SkypeWeb/src/skype_options.cpp
@@ -5,11 +5,10 @@ CSkypeOptionsMain::CSkypeOptionsMain(CSkypeProto *proto, int idDialog, HWND hwnd
m_skypename(this, IDC_SKYPENAME),
m_password(this, IDC_PASSWORD),
m_group(this, IDC_GROUP),
- m_autosync(this, IDC_CHECK2)
+ m_autosync(this, IDC_AUTOSYNC)
{
- //CreateLink(m_skypename, SKYPE_SETTINGS_ID, _T(""));
- //CreateLink(m_password, "Password", _T(""));
CreateLink(m_group, SKYPE_SETTINGS_GROUP, _T("Skype"));
+ CreateLink(m_autosync, "AutoSync", DBVT_BYTE, 1);
}
void CSkypeOptionsMain::OnInitDialog()
@@ -18,7 +17,6 @@ void CSkypeOptionsMain::OnInitDialog()
m_skypename.SetTextA(ptrA(m_proto->getStringA(SKYPE_SETTINGS_ID)));
m_password.SetTextA(ptrA(m_proto->getStringA("Password")));
- m_autosync.SetState(m_proto->getByte("AutoSync", 1));
SendMessage(m_skypename.GetHwnd(), EM_LIMITTEXT, 32, 0);
SendMessage(m_password.GetHwnd(), EM_LIMITTEXT, 20, 0);
@@ -30,7 +28,6 @@ void CSkypeOptionsMain::OnApply()
{
m_proto->setString(SKYPE_SETTINGS_ID, m_skypename.GetTextA());
m_proto->setString("Password", m_password.GetTextA());
- m_proto->setByte("AutoSync", m_autosync.GetState());
TCHAR *group = m_group.GetText();
if (mir_tstrlen(group) > 0 && !Clist_GroupExists(group))
Clist_CreateGroup(0, group);
diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp
index 4e3111ab2c..0056b2e330 100644
--- a/protocols/SkypeWeb/src/skype_proto.cpp
+++ b/protocols/SkypeWeb/src/skype_proto.cpp
@@ -35,6 +35,14 @@ PROTO<CSkypeProto>(protoName, userName), password(NULL)
dbEventType.eventType = SKYPE_DB_EVENT_TYPE_ACTION;
dbEventType.descr = Translate("Action");
CallService(MS_DB_EVENT_REGISTERTYPE, 0, (LPARAM)&dbEventType);
+
+ // make contact map
+ for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
+ {
+ std::string cSkypename = ptrA(getStringA(hContact, SKYPE_SETTINGS_ID));
+ if (!contactMap.count(cSkypename))
+ contactMap[cSkypename] = hContact;
+ }
}
CSkypeProto::~CSkypeProto()
diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h
index 78ee87e342..0d6203655c 100644
--- a/protocols/SkypeWeb/src/skype_proto.h
+++ b/protocols/SkypeWeb/src/skype_proto.h
@@ -164,6 +164,8 @@ private:
void LoadProfile(const NETLIBHTTPREQUEST *response);
// contacts
+ std::map<std::string, MCONTACT> contactMap;
+
WORD GetContactStatus(MCONTACT hContact);
void SetContactStatus(MCONTACT hContact, WORD status);
void SetAllContactsStatus(WORD status);
@@ -193,7 +195,7 @@ private:
// messages
mir_cs messageSyncLock;
- MEVENT GetMessageFromDB(MCONTACT hContact, const char *messageId, LONGLONG timestamp = 0);
+ MEVENT GetMessageFromDb(MCONTACT hContact, const char *messageId, LONGLONG timestamp = 0);
MEVENT AddMessageToDb(MCONTACT hContact, DWORD timestamp, DWORD flags, const char *messageId, char *content, int emoteOffset = 0);
int OnReceiveMessage(const char *messageId, const char *url, time_t timestamp, char *content, int emoteOffset = 0, bool isRead = false);