From d1b31445c6f4a53627a025b43afb24603bc12dc2 Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Wed, 6 May 2015 13:22:54 +0000 Subject: SkypeWeb: Rework writing calls info to db. Sync fix. git-svn-id: http://svn.miranda-ng.org/main/trunk@13460 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/SkypeWeb/src/skype_events.cpp | 4 ++++ protocols/SkypeWeb/src/skype_history_sync.cpp | 20 ++++++++++---------- protocols/SkypeWeb/src/skype_messages.cpp | 25 ++++++++++++++++++++----- protocols/SkypeWeb/src/skype_proto.h | 1 + protocols/SkypeWeb/src/skype_trouter.cpp | 14 +++++++------- protocols/SkypeWeb/src/stdafx.h | 10 +++++++--- 6 files changed, 49 insertions(+), 25 deletions(-) diff --git a/protocols/SkypeWeb/src/skype_events.cpp b/protocols/SkypeWeb/src/skype_events.cpp index b9e92515f0..645ee38753 100644 --- a/protocols/SkypeWeb/src/skype_events.cpp +++ b/protocols/SkypeWeb/src/skype_events.cpp @@ -76,6 +76,10 @@ void CSkypeProto::InitDBEvents() dbEventType.descr = Translate("Action"); CallService(MS_DB_EVENT_REGISTERTYPE, 0, (LPARAM)&dbEventType); + dbEventType.eventType = SKYPE_DB_EVENT_TYPE_CALL_INFO; + dbEventType.descr = Translate("Call information."); + CallService(MS_DB_EVENT_REGISTERTYPE, 0, (LPARAM)&dbEventType); + dbEventType.eventType = SKYPE_DB_EVENT_TYPE_INCOMING_CALL; dbEventType.descr = Translate("Incoming call"); dbEventType.textService = MODULE"/GetCallText"; diff --git a/protocols/SkypeWeb/src/skype_history_sync.cpp b/protocols/SkypeWeb/src/skype_history_sync.cpp index 98afb8bb90..0e394049b3 100644 --- a/protocols/SkypeWeb/src/skype_history_sync.cpp +++ b/protocols/SkypeWeb/src/skype_history_sync.cpp @@ -39,11 +39,6 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response) if (totalCount >= 99 || json_size(conversations) >= 99) PushRequest(new GetHistoryOnUrlRequest(syncState, RegToken), &CSkypeProto::OnGetServerHistory); - int flags = DBEF_UTF; - - if (!markAllAsUnread) - flags |= DBEF_READ; - for (int i = json_size(conversations); i >= 0; i--) { JSONNODE *message = json_at(conversations, i); @@ -62,15 +57,20 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response) bool isEdited = (json_get(message, "skypeeditedid") != NULL); MCONTACT hContact = FindContact(ptrA(ContactUrlToName(conversationLink))); + + int flags = DBEF_UTF; + + if (!markAllAsUnread) + flags |= DBEF_READ; + + if (IsMe(skypename)) + flags |= DBEF_SENT; + if (conversationLink != NULL && strstr(conversationLink, "/8:")) { if (!mir_strcmpi(messageType, "Text") || !mir_strcmpi(messageType, "RichText")) { - bool isMe = IsMe(skypename); - if (isMe) - flags |= DBEF_SENT; - ptrA message(RemoveHtml(content)); MEVENT dbevent = GetMessageFromDb(hContact, skypeEditedId); @@ -147,7 +147,7 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response) csec.AppendFormat(sec < 10 ? "0%d" : "%d", sec); text.AppendFormat("%s\n%s: %s:%s:%s", Translate("Call ended"), Translate("Duration"), chours, cmins, csec); } - AddMessageToDb(hContact, timestamp, flags, clientMsgId, text.GetBuffer()); + AddCallInfoToDb(hContact, timestamp, flags, clientMsgId, text.GetBuffer()); } else if (!mir_strcmpi(messageType, "RichText/Files")) { diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp index 8191308b85..76bce319aa 100644 --- a/protocols/SkypeWeb/src/skype_messages.cpp +++ b/protocols/SkypeWeb/src/skype_messages.cpp @@ -38,7 +38,7 @@ MEVENT CSkypeProto::GetMessageFromDb(MCONTACT hContact, const char *messageId, L dbei.pBlob = blob; db_event_get(hDbEvent, &dbei); - if (dbei.eventType != EVENTTYPE_MESSAGE && dbei.eventType != SKYPE_DB_EVENT_TYPE_ACTION) + if (dbei.eventType != EVENTTYPE_MESSAGE && dbei.eventType != SKYPE_DB_EVENT_TYPE_ACTION && dbei.eventType != SKYPE_DB_EVENT_TYPE_CALL_INFO) continue; size_t cbLen = strlen((char*)dbei.pBlob); @@ -66,6 +66,20 @@ MEVENT CSkypeProto::AddMessageToDb(MCONTACT hContact, DWORD timestamp, DWORD fla return AddEventToDb(hContact, emoteOffset == 0 ? EVENTTYPE_MESSAGE : SKYPE_DB_EVENT_TYPE_ACTION, timestamp, flags, (DWORD)cbBlob, pBlob); } +MEVENT CSkypeProto::AddCallInfoToDb(MCONTACT hContact, DWORD timestamp, DWORD flags, const char *messageId, char *content) +{ + if (MEVENT hDbEvent = GetMessageFromDb(hContact, messageId, timestamp)) + return hDbEvent; + size_t messageLength = mir_strlen(content) + 1; + size_t messageIdLength = mir_strlen(messageId); + size_t cbBlob = messageLength + messageIdLength; + PBYTE pBlob = (PBYTE)mir_alloc(cbBlob); + memcpy(pBlob, content, messageLength); + memcpy(pBlob + messageLength, messageId, messageIdLength); + + return AddEventToDb(hContact,SKYPE_DB_EVENT_TYPE_CALL_INFO, timestamp, flags, (DWORD)cbBlob, pBlob); +} + MEVENT CSkypeProto::AddCallToDb(MCONTACT hContact, DWORD timestamp, DWORD flags, const char *callId, const char *gp) { size_t callIdLength = mir_strlen(callId); @@ -321,10 +335,11 @@ void CSkypeProto::OnPrivateMessageEvent(JSONNODE *node) csec.AppendFormat(sec < 10 ? "0%d" : "%d", sec); text.AppendFormat("%s\n%s: %s:%s:%s", Translate("Call ended"), Translate("Duration"), chours, cmins, csec); } - if (IsMe(from)) - AddMessageToDb(hContact, timestamp, DBEF_UTF | DBEF_SENT, clientMsgId, text.GetBuffer()); - else - OnReceiveMessage(clientMsgId, conversationLink, timestamp, text.GetBuffer()); + + int flags = DBEF_UTF; + if (IsMe(from)) flags |= DBEF_SENT; + + AddCallInfoToDb(hContact, timestamp, flags, clientMsgId, text.GetBuffer()); } else if (!mir_strcmpi(messageType, "RichText/Files")) { diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index 9847fdcc5a..0d1f403912 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -226,6 +226,7 @@ private: 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); MEVENT AddCallToDb(MCONTACT hContact, DWORD timestamp, DWORD flags, const char *callId, const char *gp); + MEVENT AddCallInfoToDb(MCONTACT hContact, DWORD timestamp, DWORD flags, const char *messageId, char *content); int OnReceiveMessage(const char *messageId, const char *url, time_t timestamp, char *content, int emoteOffset = 0, bool isRead = false); int SaveMessageToDb(MCONTACT hContact, PROTORECVEVENT *pre); diff --git a/protocols/SkypeWeb/src/skype_trouter.cpp b/protocols/SkypeWeb/src/skype_trouter.cpp index adb9ec3df1..21a250a193 100644 --- a/protocols/SkypeWeb/src/skype_trouter.cpp +++ b/protocols/SkypeWeb/src/skype_trouter.cpp @@ -20,14 +20,14 @@ void CSkypeProto::OnCreateTrouter(const NETLIBHTTPREQUEST *response) { if (response == NULL || response->pData == NULL) { - ShowNotification(_A2T(m_szModuleName), _T("Failed establish a TRouter connection.")); + ShowNotification(_A2T(m_szModuleName), TranslateT("Failed establish a TRouter connection.")); return; } JSONROOT root(response->pData); if (root == NULL) { - ShowNotification(_A2T(m_szModuleName), _T("Failed establish a TRouter connection.")); + ShowNotification(_A2T(m_szModuleName), TranslateT("Failed establish a TRouter connection.")); return; } @@ -39,7 +39,7 @@ void CSkypeProto::OnCreateTrouter(const NETLIBHTTPREQUEST *response) if (ccid == NULL || connId == NULL || instance == NULL || socketio == NULL || url == NULL) { - ShowNotification(_A2T(m_szModuleName), _T("Failed establish a TRouter connection.")); + ShowNotification(_A2T(m_szModuleName), TranslateT("Failed establish a TRouter connection.")); return; } @@ -56,7 +56,7 @@ void CSkypeProto::OnTrouterPoliciesCreated(const NETLIBHTTPREQUEST *response) { if (response == NULL || response->pData == NULL) { - ShowNotification(_A2T(m_szModuleName), _T("Failed establish a TRouter connection.")); + ShowNotification(_A2T(m_szModuleName), TranslateT("Failed establish a TRouter connection.")); return; } @@ -64,7 +64,7 @@ void CSkypeProto::OnTrouterPoliciesCreated(const NETLIBHTTPREQUEST *response) if (root == NULL) { - ShowNotification(_A2T(m_szModuleName), _T("Failed establish a TRouter connection.")); + ShowNotification(_A2T(m_szModuleName), TranslateT("Failed establish a TRouter connection.")); return; } @@ -74,7 +74,7 @@ void CSkypeProto::OnTrouterPoliciesCreated(const NETLIBHTTPREQUEST *response) if (st == NULL || se == NULL || sig == NULL) { - ShowNotification(_A2T(m_szModuleName), _T("Failed establish a TRouter connection.")); + ShowNotification(_A2T(m_szModuleName), TranslateT("Failed establish a TRouter connection.")); return; } @@ -98,7 +98,7 @@ void CSkypeProto::OnGetTrouter(const NETLIBHTTPREQUEST *response, void *p) { if (response == NULL || response->pData == NULL) { - ShowNotification(_A2T(m_szModuleName), _T("Failed establish a TRouter connection.")); + ShowNotification(_A2T(m_szModuleName), TranslateT("Failed establish a TRouter connection.")); return; } bool isHealth = (bool)p; diff --git a/protocols/SkypeWeb/src/stdafx.h b/protocols/SkypeWeb/src/stdafx.h index 8a88f3e054..b627274e40 100644 --- a/protocols/SkypeWeb/src/stdafx.h +++ b/protocols/SkypeWeb/src/stdafx.h @@ -99,13 +99,17 @@ enum SKYPE_LOGIN_ERROR LOGIN_ERROR_UNKNOWN = 1001 }; +enum SKYPE_DB_EVENT_TYPE +{ + SKYPE_DB_EVENT_TYPE_ACTION = 10001, + SKYPE_DB_EVENT_TYPE_INCOMING_CALL, + SKYPE_DB_EVENT_TYPE_CALL_INFO +}; + #define SKYPE_SETTINGS_ID "Skypename" #define SKYPE_SETTINGS_PASSWORD "Password" #define SKYPE_SETTINGS_GROUP "DefaultGroup" #define POLLING_ERRORS_LIMIT 3 -#define SKYPE_DB_EVENT_TYPE_ACTION 10001 -#define SKYPE_DB_EVENT_TYPE_INCOMING_CALL 10002 - #endif //_COMMON_H_ \ No newline at end of file -- cgit v1.2.3