diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-09-24 20:03:41 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-09-24 20:03:41 +0000 |
commit | 97cd13fd97f1481fa0c48c2b9601cd2a0a20ea9e (patch) | |
tree | bf9e459cafdfbd30097f585e95e2489f8cccba62 /plugins | |
parent | a0d2cd360477acf24963e479773588b01f3d8a10 (diff) |
MirLua: reworked Send in m_message
git-svn-id: http://svn.miranda-ng.org/main/trunk@15441 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/MirLua/src/m_message.cpp | 47 | ||||
-rw-r--r-- | plugins/MirLua/src/stdafx.h | 2 |
2 files changed, 35 insertions, 14 deletions
diff --git a/plugins/MirLua/src/m_message.cpp b/plugins/MirLua/src/m_message.cpp index e53403d2bc..2968b1aeda 100644 --- a/plugins/MirLua/src/m_message.cpp +++ b/plugins/MirLua/src/m_message.cpp @@ -27,24 +27,43 @@ static int lua_Paste(lua_State *L) static int lua_Send(lua_State *L)
{
MCONTACT hContact = luaL_checkinteger(L, 1);
- ptrT text(mir_utf8decodeT(luaL_checkstring(L, 2)));
+ const char *message = luaL_checkstring(L, 2);
- MessageWindowInputData mwid = { sizeof(MessageWindowInputData) };
- mwid.hContact = hContact;
- mwid.uFlags = MSG_WINDOW_UFLAG_MSG_BOTH;
+ INT_PTR res = 1;
- MessageWindowData mwd = { sizeof(MessageWindowData) };
-
- INT_PTR res = ::CallService(MS_MSG_GETWINDOWDATA, (WPARAM)&mwid, (LPARAM)&mwd);
- lua_pushinteger(L, res);
- if (res)
+ const char *szProto = GetContactProto(hContact);
+ if (db_get_b(hContact, szProto, "ChatRoom", 0) == TRUE)
+ {
+ ptrT tszChatRoom(db_get_tsa(hContact, szProto, "ChatRoomID"));
+ GCDEST gcd = { szProto, tszChatRoom, GC_EVENT_SENDMESSAGE };
+ GCEVENT gce = { sizeof(gce), &gcd };
+ gce.bIsMe = TRUE;
+ gce.dwFlags = GCEF_ADDTOLOG;
+ gce.ptszText = mir_utf8decodeT(message);
+ gce.time = time(NULL);
+
+ res = ::CallServiceSync(MS_GC_EVENT, WINDOW_VISIBLE, (LPARAM)&gce);
+ lua_pushinteger(L, res);
+
+ mir_free((void*)gce.ptszText);
+ }
+ else if ((res = ::CallContactService(hContact, PSS_MESSAGE, 0, (LPARAM)message)) != ACKRESULT_FAILED)
+ {
+ DBEVENTINFO dbei;
+ dbei.cbSize = sizeof(dbei);
+ dbei.szModule = MODULE;
+ dbei.timestamp = time(NULL);
+ dbei.eventType = EVENTTYPE_MESSAGE;
+ dbei.cbBlob = mir_strlen(message);
+ dbei.pBlob = (PBYTE)mir_strdup(message);
+ dbei.flags = DBEF_UTF | DBEF_SENT;
+ ::db_event_add(hContact, &dbei);
+
+ lua_pushinteger(L, res);
return 1;
+ }
- HWND hEdit = GetDlgItem(mwd.hwndWindow, 1002 /*IDC_MESSAGE*/);
- if (!hEdit) hEdit = GetDlgItem(mwd.hwndWindow, 1009 /*IDC_CHATMESSAGE*/);
-
- SendMessage(hEdit, EM_REPLACESEL, TRUE, (LPARAM)text);
- SendMessage(mwd.hwndWindow, WM_COMMAND, IDOK, 0);
+ lua_pushinteger(L, res);
return 1;
}
diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h index ab257b27eb..61f968d6a4 100644 --- a/plugins/MirLua/src/stdafx.h +++ b/plugins/MirLua/src/stdafx.h @@ -4,6 +4,7 @@ #include <windows.h>
#include <commctrl.h>
#include <malloc.h>
+#include <time.h>
#include <newpluginapi.h>
#include <m_core.h>
@@ -19,6 +20,7 @@ #include <m_hotkeys.h>
#include <m_icolib.h>
#include <m_message.h>
+#include <m_chat.h>
#include <m_protocols.h>
#include <m_folders.h>
|