/* Copyright (c) 2015-24 Miranda NG team (https://miranda-ng.org) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "stdafx.h" struct { int type; char *name; uint32_t flags; } g_SkypeDBTypes[] = { { SKYPE_DB_EVENT_TYPE_INCOMING_CALL, LPGEN("Incoming call"), DETF_NONOTIFY }, { SKYPE_DB_EVENT_TYPE_EDITED_MESSAGE, LPGEN("Edited message"), 0 }, { SKYPE_DB_EVENT_TYPE_ACTION, LPGEN("Action"), 0 }, { SKYPE_DB_EVENT_TYPE_CALL_INFO, LPGEN("Call information"), 0 }, { SKYPE_DB_EVENT_TYPE_FILETRANSFER_INFO, LPGEN("File transfer information"), 0 }, { SKYPE_DB_EVENT_TYPE_URIOBJ, LPGEN("URI object"), 0 }, { SKYPE_DB_EVENT_TYPE_MOJI, LPGEN("Moji"), 0 }, { SKYPE_DB_EVENT_TYPE_FILE, LPGEN("File"), 0 }, { SKYPE_DB_EVENT_TYPE_UNKNOWN, LPGEN("Unknown event"), 0 }, }; MEVENT CSkypeProto::GetMessageFromDb(const char *messageId) { if (messageId == nullptr) return NULL; return db_event_getById(m_szModuleName, messageId); } MEVENT CSkypeProto::AddDbEvent(uint16_t type, MCONTACT hContact, uint32_t timestamp, uint32_t flags, const CMStringW &content, const CMStringA &msgId) { if (MEVENT hDbEvent = GetMessageFromDb(msgId)) return hDbEvent; T2Utf szMsg(content); DBEVENTINFO dbei = {}; dbei.szModule = m_szModuleName; dbei.timestamp = timestamp; dbei.eventType = type; dbei.cbBlob = (uint32_t)mir_strlen(szMsg) + 1; dbei.pBlob = szMsg; dbei.flags = flags; dbei.szId = msgId; return db_event_add(hContact, &dbei); } void CSkypeProto::EditEvent(MEVENT hEvent, const CMStringW &szContent, time_t edit_time) { mir_cslock lck(m_AppendMessageLock); DB::EventInfo dbei(hEvent); if (!dbei) return; JSONNode jMsg = JSONNode::parse((char*)dbei.pBlob); if (jMsg) { JSONNode &jEdits = jMsg["edits"]; if (jEdits) { for (auto &it : jEdits) if (it["time"].as_int() == edit_time) return; JSONNode jEdit; jEdit << INT_PARAM("time", (long)edit_time) << WCHAR_PARAM("text", szContent); jEdits << jEdit; } } else { JSONNode jOriginalMsg; jOriginalMsg.set_name("original_message"); jOriginalMsg << INT_PARAM("time", (long)dbei.timestamp) << CHAR_PARAM("text", (char *)dbei.pBlob); jMsg = JSONNode(); jMsg << jOriginalMsg; JSONNode jEdit; jEdit << INT_PARAM("time", (long)edit_time) << WCHAR_PARAM("text", szContent); JSONNode jEdits(JSON_ARRAY); jEdits.set_name("edits"); jEdits << jEdit; jMsg << jEdits; } std::string newMsg = jMsg.write().c_str(); dbei.cbBlob = int(newMsg.size() + 1); dbei.pBlob = (char *)newMsg.c_str(); db_event_edit(hEvent, &dbei, true); } void CSkypeProto::InitDBEvents() { // custom event DBEVENTTYPEDESCR dbEventType = {}; dbEventType.module = m_szModuleName; dbEventType.flags = DETF_HISTORY | DETF_MSGWINDOW; dbEventType.iconService = MODULE "/GetEventIcon"; dbEventType.textService = MODULE "/GetEventText"; for (auto &cur : g_SkypeDBTypes) { dbEventType.eventType = cur.type; dbEventType.descr = Translate(cur.name); dbEventType.flags |= cur.flags; DbEvent_RegisterType(&dbEventType); dbEventType.flags &= (~cur.flags); } }