summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/SkypeWeb/src/main.cpp2
-rw-r--r--protocols/SkypeWeb/src/skype_db.cpp47
-rw-r--r--protocols/SkypeWeb/src/skype_events.cpp56
-rw-r--r--protocols/SkypeWeb/src/skype_history_sync.cpp20
-rw-r--r--protocols/SkypeWeb/src/skype_messages.cpp20
-rw-r--r--protocols/SkypeWeb/src/skype_proto.h12
-rw-r--r--protocols/SkypeWeb/src/stdafx.h3
7 files changed, 99 insertions, 61 deletions
diff --git a/protocols/SkypeWeb/src/main.cpp b/protocols/SkypeWeb/src/main.cpp
index c944b64fb5..2dcb3b0046 100644
--- a/protocols/SkypeWeb/src/main.cpp
+++ b/protocols/SkypeWeb/src/main.cpp
@@ -70,7 +70,7 @@ extern "C" int __declspec(dllexport) Load(void)
CSkypeProto::InitMenus();
CSkypeProto::InitLanguages();
CreateServiceFunction(MODULE"/GetEventIcon", &CSkypeProto::EventGetIcon);
- CreateServiceFunction(MODULE"/GetCallText", &CSkypeProto::GetCallEventText);
+ CreateServiceFunction(MODULE"/GetEventText", &CSkypeProto::GetEventText);
HookEvent(ME_SYSTEM_MODULESLOADED, &CSkypeProto::OnModulesLoaded);
return 0;
diff --git a/protocols/SkypeWeb/src/skype_db.cpp b/protocols/SkypeWeb/src/skype_db.cpp
index 394f0f552e..b987cb9343 100644
--- a/protocols/SkypeWeb/src/skype_db.cpp
+++ b/protocols/SkypeWeb/src/skype_db.cpp
@@ -38,9 +38,6 @@ 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 && dbei.eventType != SKYPE_DB_EVENT_TYPE_CALL_INFO && dbei.eventType != SKYPE_DB_EVENT_TYPE_FILETRANSFER_INFO && dbei.eventType != SKYPE_DB_EVENT_TYPE_URIOBJ)
- continue;
-
size_t cbLen = mir_strlen((char*)dbei.pBlob);
if (memcmp(&dbei.pBlob[cbLen + 1], messageId, messageIdLength) == 0)
return hDbEvent;
@@ -66,6 +63,50 @@ MEVENT CSkypeProto::AddDbEvent(WORD type, MCONTACT hContact, DWORD timestamp, DW
return AddEventToDb(hContact, type, timestamp, flags, (DWORD)cbBlob, pBlob);
}
+MEVENT CSkypeProto::AppendDBEvent(MCONTACT hContact, MEVENT hEvent, const char *szContent, const char *szUid, time_t edit_time)
+{
+ DBEVENTINFO dbei = { sizeof(dbei) };
+ dbei.cbBlob = db_event_getBlobSize(hEvent);
+ dbei.pBlob = mir_ptr<BYTE>((PBYTE)mir_alloc(dbei.cbBlob));
+ db_event_get(hEvent, &dbei);
+
+ JSONNode jMsg = JSONNode::parse((char*)dbei.pBlob);
+ if (jMsg)
+ {
+ if (jMsg["edits"])
+ {
+ JSONNode jEdit;
+ jEdit.push_back(JSONNode("time", (long)edit_time));
+ jEdit.push_back(JSONNode("text", szContent));
+
+ jMsg["edits"].push_back(jEdit);
+ }
+ }
+ else
+ {
+ jMsg = JSONNode();
+ JSONNode jOriginalMsg;
+ JSONNode jEdits(JSON_ARRAY);
+ JSONNode jEdit;
+
+ jOriginalMsg.set_name("original_message");
+ jOriginalMsg.push_back(JSONNode("time", (long)dbei.timestamp));
+ jOriginalMsg.push_back(JSONNode("text", (char*)dbei.pBlob));
+ jMsg.push_back(jOriginalMsg);
+
+ jEdit.push_back(JSONNode("time", (long)edit_time));
+ jEdit.push_back(JSONNode("text", szContent));
+
+ jEdits.push_back(jEdit);
+ jEdits.set_name("edits");
+ jMsg.push_back(jEdits);
+
+
+ }
+ int r = db_event_delete(hContact, hEvent);
+ return AddDbEvent(SKYPE_DB_EVENT_TYPE_EDITED_MESSAGE, hContact, dbei.timestamp, DBEF_UTF, jMsg.write().c_str(), szUid);
+}
+
MEVENT CSkypeProto::AddEventToDb(MCONTACT hContact, WORD type, DWORD timestamp, DWORD flags, DWORD cbBlob, PBYTE pBlob)
{
DBEVENTINFO dbei = { sizeof(dbei) };
diff --git a/protocols/SkypeWeb/src/skype_events.cpp b/protocols/SkypeWeb/src/skype_events.cpp
index 2e401ac4a7..9071025d50 100644
--- a/protocols/SkypeWeb/src/skype_events.cpp
+++ b/protocols/SkypeWeb/src/skype_events.cpp
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
-INT_PTR CSkypeProto::GetCallEventText(WPARAM, LPARAM lParam)
+INT_PTR CSkypeProto::GetEventText(WPARAM, LPARAM lParam)
{
DBEVENTGETTEXT *pEvent = (DBEVENTGETTEXT *)lParam;
@@ -27,6 +27,40 @@ INT_PTR CSkypeProto::GetCallEventText(WPARAM, LPARAM lParam)
switch (pEvent->dbei->eventType)
{
+ case SKYPE_DB_EVENT_TYPE_EDITED_MESSAGE:
+ {
+ CMStringA text;
+ JSONNode jMsg = JSONNode::parse((char*)pEvent->dbei->pBlob);
+ if (jMsg)
+ {
+ text.AppendFormat(Translate("Original message:\n\t%s\n"), jMsg["original_message"]["text"].as_string());
+ JSONNode &jEdits = jMsg["edits"];
+ for (auto it = jEdits.begin(); it != jEdits.end(); ++it)
+ {
+ const JSONNode &jEdit = *it;
+
+ time_t time = jEdit["time"].as_int();
+ tm* _tm = localtime(&time);
+ char szTime[MAX_PATH];
+ strftime(szTime, 0, "%X %x", _tm);
+
+ text.AppendFormat(Translate("Edited at %s:\n\t%s\n"), szTime, jEdit["text"].as_string());
+ }
+
+ }
+ else
+ {
+#ifdef _DEBUG
+ text = (char*)pEvent->dbei->pBlob;
+#else
+ text = Translate("Invalid data!");
+#endif
+ }
+
+ pszText = mir_utf8decodeA(text);
+ break;
+ }
+
case SKYPE_DB_EVENT_TYPE_CALL_INFO:
{
CMStringA text;
@@ -52,7 +86,7 @@ INT_PTR CSkypeProto::GetCallEventText(WPARAM, LPARAM lParam)
}
xmlDestroyNode(xml);
}
- pszText = mir_strdup(text.GetBuffer());
+ pszText = mir_strdup(text);
break;
}
case SKYPE_DB_EVENT_TYPE_FILETRANSFER_INFO:
@@ -80,7 +114,7 @@ INT_PTR CSkypeProto::GetCallEventText(WPARAM, LPARAM lParam)
}
xmlDestroyNode(xml);
}
- pszText = mir_strdup(text.GetBuffer());
+ pszText = mir_strdup(text);
break;
}
case SKYPE_DB_EVENT_TYPE_URIOBJ:
@@ -92,7 +126,7 @@ INT_PTR CSkypeProto::GetCallEventText(WPARAM, LPARAM lParam)
text.Append(_T2A(xmlGetText(xml)));
xmlDestroyNode(xml);
}
- pszText = mir_strdup(text.GetBuffer());
+ pszText = mir_strdup(text);
break;
}
@@ -153,23 +187,27 @@ void CSkypeProto::InitDBEvents()
DBEVENTTYPEDESCR dbEventType = { sizeof(dbEventType) };
dbEventType.module = m_szModuleName;
dbEventType.flags = DETF_HISTORY | DETF_MSGWINDOW;
- dbEventType.iconService = MODULE"/GetEventIcon";
- dbEventType.textService = MODULE"/GetCallText";
+ dbEventType.iconService = MODULE "/GetEventIcon";
+ dbEventType.textService = MODULE "/GetEventText";
+
+ dbEventType.eventType = SKYPE_DB_EVENT_TYPE_EDITED_MESSAGE;
+ dbEventType.descr = Translate("Edited message");
+ CallService(MS_DB_EVENT_REGISTERTYPE, 0, (LPARAM)&dbEventType);
dbEventType.eventType = SKYPE_DB_EVENT_TYPE_ACTION;
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.");
+ dbEventType.descr = Translate("Call information");
CallService(MS_DB_EVENT_REGISTERTYPE, 0, (LPARAM)&dbEventType);
dbEventType.eventType = SKYPE_DB_EVENT_TYPE_FILETRANSFER_INFO;
- dbEventType.descr = Translate("File transfer information.");
+ dbEventType.descr = Translate("File transfer information");
CallService(MS_DB_EVENT_REGISTERTYPE, 0, (LPARAM)&dbEventType);
dbEventType.eventType = SKYPE_DB_EVENT_TYPE_URIOBJ;
- dbEventType.descr = Translate("Uri object.");
+ dbEventType.descr = Translate("URI object");
CallService(MS_DB_EVENT_REGISTERTYPE, 0, (LPARAM)&dbEventType);
dbEventType.eventType = SKYPE_DB_EVENT_TYPE_INCOMING_CALL;
diff --git a/protocols/SkypeWeb/src/skype_history_sync.cpp b/protocols/SkypeWeb/src/skype_history_sync.cpp
index 91f1041276..4d70e23d99 100644
--- a/protocols/SkypeWeb/src/skype_history_sync.cpp
+++ b/protocols/SkypeWeb/src/skype_history_sync.cpp
@@ -77,25 +77,7 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response)
if (isEdited && dbevent != NULL)
{
- DBEVENTINFO dbei = { sizeof(dbei) };
-
- dbei.cbBlob = db_event_getBlobSize(dbevent);
- mir_ptr<BYTE> blob((PBYTE)mir_alloc(dbei.cbBlob));
- dbei.pBlob = blob;
-
- db_event_get(dbevent, &dbei);
- time_t dbEventTimestamp = dbei.timestamp;
-
- char *dbMsgText = NEWSTR_ALLOCA((char *)dbei.pBlob);
-
- TCHAR time[64];
- _locale_t locale = _create_locale(LC_ALL, "");
- _tcsftime_l(time, sizeof(time), L"%X %x", localtime(&timestamp), locale);
- _free_locale(locale);
-
- CMStringA msg(FORMAT, "%s\n%s %s:\n%s", mir_utf8decodeA(dbMsgText), Translate("Edited at"), T2Utf(time), mir_utf8decodeA(message));
- db_event_delete(hContact, dbevent);
- AddDbEvent(EVENTTYPE_MESSAGE, hContact, dbEventTimestamp, flags, mir_utf8encode(&msg.GetBuffer()[emoteOffset]), clientMsgId.c_str());
+ AppendDBEvent(hContact, dbevent, message, clientMsgId.c_str(), timestamp);
}
else AddDbEvent(EVENTTYPE_MESSAGE, hContact, timestamp, flags, &message[emoteOffset], clientMsgId.c_str());
}
diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp
index ebc31f2ab0..8c8cbb25aa 100644
--- a/protocols/SkypeWeb/src/skype_messages.cpp
+++ b/protocols/SkypeWeb/src/skype_messages.cpp
@@ -180,25 +180,7 @@ void CSkypeProto::OnPrivateMessageEvent(const JSONNode &node)
MEVENT dbevent = GetMessageFromDb(hContact, skypeEditedId.c_str());
if (isEdited && dbevent != NULL)
{
- DBEVENTINFO dbei = { sizeof(dbei) };
- CMStringA msg;
- dbei.cbBlob = db_event_getBlobSize(dbevent);
- dbei.pBlob = mir_ptr<BYTE>((PBYTE)mir_alloc(dbei.cbBlob));
-
- db_event_get(dbevent, &dbei);
-
- time_t dbEventTimestamp = dbei.timestamp;
-
- char *dbMsgText = NEWSTR_ALLOCA((char *)dbei.pBlob);
-
- TCHAR time[64];
- _locale_t locale = _create_locale(LC_ALL, "");
- _tcsftime_l(time, sizeof(time), L"%X %x", localtime(&timestamp), locale);
- _free_locale(locale);
-
- msg.AppendFormat("%s\n%s %s:\n%s", mir_utf8decodeA(dbMsgText), Translate("Edited at"), T2Utf(time), mir_utf8decodeA(message));
- db_event_delete(hContact, dbevent);
- AddDbEvent(EVENTTYPE_MESSAGE, hContact, dbEventTimestamp, DBEF_UTF, ptrA(mir_utf8encode(msg.GetBuffer())), skypeEditedId.c_str());
+ AppendDBEvent(hContact, dbevent, message, skypeEditedId.c_str(), timestamp);
}
else OnReceiveMessage(clientMsgId.c_str(), conversationLink.c_str(), timestamp, message, emoteOffset);
}
diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h
index b8b85fb62e..d88b54c102 100644
--- a/protocols/SkypeWeb/src/skype_proto.h
+++ b/protocols/SkypeWeb/src/skype_proto.h
@@ -23,8 +23,7 @@ typedef void(CSkypeProto::*SkypeResponseWithArgCallback)(const NETLIBHTTPREQUEST
struct TRInfo
{
- std::string
- socketIo,
+ std::string socketIo,
connId,
st,
se,
@@ -56,18 +55,12 @@ public:
virtual int __cdecl Authorize(MEVENT hDbEvent);
virtual int __cdecl AuthDeny(MEVENT hDbEvent, const TCHAR* szReason);
virtual int __cdecl AuthRecv(MCONTACT hContact, PROTORECVEVENT*);
-
virtual DWORD_PTR __cdecl GetCaps(int type, MCONTACT hContact = NULL);
virtual int __cdecl GetInfo(MCONTACT hContact, int infoType);
-
virtual HANDLE __cdecl SearchBasic(const TCHAR* id);
-
virtual int __cdecl SendMsg(MCONTACT hContact, int flags, const char* msg);
-
virtual int __cdecl SetStatus(int iNewStatus);
-
virtual int __cdecl UserIsTyping(MCONTACT hContact, int type);
-
virtual int __cdecl OnEvent(PROTOEVENTTYPE iEventType, WPARAM wParam, LPARAM lParam);
// accounts
@@ -100,7 +93,7 @@ public:
static int CompareAccounts(const CSkypeProto *p1, const CSkypeProto *p2);
void ProcessTimer();
static INT_PTR EventGetIcon(WPARAM wParam, LPARAM lParam);
- static INT_PTR GetCallEventText(WPARAM, LPARAM lParam);
+ static INT_PTR GetEventText(WPARAM, LPARAM lParam);
static mir_cs accountsLock;
private:
@@ -241,6 +234,7 @@ private:
MEVENT GetMessageFromDb(MCONTACT hContact, const char *messageId, LONGLONG timestamp = 0);
MEVENT AddDbEvent(WORD type, MCONTACT hContact, DWORD timestamp, DWORD flags, const char *content, const char *uid);
+ MEVENT AppendDBEvent(MCONTACT hContact, MEVENT hEvent, const char *szContent, const char *szUid, time_t edit_time);
int OnReceiveMessage(const char *messageId, const char *url, time_t timestamp, char *content, int emoteOffset = 0, bool isRead = false);
int OnSendMessage(MCONTACT hContact, int flags, const char *message);
diff --git a/protocols/SkypeWeb/src/stdafx.h b/protocols/SkypeWeb/src/stdafx.h
index 195aa83deb..c6762544bd 100644
--- a/protocols/SkypeWeb/src/stdafx.h
+++ b/protocols/SkypeWeb/src/stdafx.h
@@ -102,7 +102,8 @@ enum SKYPE_DB_EVENT_TYPE
SKYPE_DB_EVENT_TYPE_INCOMING_CALL,
SKYPE_DB_EVENT_TYPE_CALL_INFO,
SKYPE_DB_EVENT_TYPE_FILETRANSFER_INFO,
- SKYPE_DB_EVENT_TYPE_URIOBJ
+ SKYPE_DB_EVENT_TYPE_URIOBJ,
+ SKYPE_DB_EVENT_TYPE_EDITED_MESSAGE
};
#define SKYPE_SETTINGS_ID "Skypename"