1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
#include "stdafx.h"
void ShowNotification(const wchar_t *caption, const wchar_t *message, int flags, MCONTACT hContact)
{
if (Miranda_IsTerminated())
return;
if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1)) {
POPUPDATAT ppd = { 0 };
ppd.lchContact = hContact;
wcsncpy(ppd.lpwzContactName, caption, MAX_CONTACTNAME);
wcsncpy(ppd.lpwzText, message, MAX_SECONDLINE);
ppd.lchIcon = IcoLib_GetIcon("Slack_main");
if (!PUAddPopupT(&ppd))
return;
}
MessageBox(nullptr, message, caption, MB_OK | flags);
}
void ShowNotification(const wchar_t *message, int flags, MCONTACT hContact)
{
ShowNotification(_A2W(MODULE), message, flags, hContact);
}
MEVENT AddEventToDb(MCONTACT hContact, WORD type, DWORD flags, DWORD cbBlob, PBYTE pBlob)
{
DBEVENTINFO dbei = {};
dbei.szModule = MODULE;
dbei.timestamp = time(nullptr);
dbei.eventType = type;
dbei.cbBlob = cbBlob;
dbei.pBlob = pBlob;
dbei.flags = flags;
return db_event_add(hContact, &dbei);
}
bool CanSendToContact(MCONTACT hContact)
{
if (!hContact)
return false;
const char *proto = GetContactProto(hContact);
if (!proto)
return false;
bool isCtrlPressed = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
if (isCtrlPressed)
return true;
bool canSend = (CallProtoService(proto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IMSEND) != 0;
if (!canSend)
return false;
bool isProtoOnline = Proto_GetStatus(proto) > ID_STATUS_OFFLINE;
if (!isProtoOnline)
return false;
bool isContactOnline = Contact_GetStatus(hContact) > ID_STATUS_OFFLINE;
if (isContactOnline)
return true;
return CallProtoService(proto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_IMSENDOFFLINE;
}
void SendToContact(MCONTACT hContact, const wchar_t *data)
{
const char *szProto = GetContactProto(hContact);
if (db_get_b(hContact, szProto, "ChatRoom", 0) == TRUE) {
ptrW tszChatRoom(db_get_wsa(hContact, szProto, "ChatRoomID"));
Chat_SendUserMessage(szProto, tszChatRoom, data);
return;
}
char *message = mir_utf8encodeW(data);
if (ProtoChainSend(hContact, PSS_MESSAGE, 0, (LPARAM)message) != ACKRESULT_FAILED)
AddEventToDb(hContact, EVENTTYPE_MESSAGE, DBEF_UTF | DBEF_SENT, (DWORD)mir_strlen(message), (PBYTE)message);
}
void PasteToInputArea(MCONTACT hContact, const wchar_t *data)
{
CallService(MS_MSG_SENDMESSAGEW, hContact, (LPARAM)data);
}
void PasteToClipboard(const wchar_t *data)
{
if (OpenClipboard(nullptr)) {
EmptyClipboard();
size_t size = sizeof(wchar_t) * (mir_wstrlen(data) + 1);
HGLOBAL hClipboardData = GlobalAlloc(NULL, size);
if (hClipboardData) {
wchar_t *pchData = (wchar_t*)GlobalLock(hClipboardData);
mir_wstrcpy(pchData, data);
GlobalUnlock(hClipboardData);
SetClipboardData(CF_UNICODETEXT, hClipboardData);
}
CloseClipboard();
}
}
void Report(MCONTACT hContact, const wchar_t *data)
{
if (db_get_b(NULL, MODULE, "UrlAutoSend", 1))
SendToContact(hContact, data);
if (db_get_b(NULL, MODULE, "UrlPasteToMessageInputArea", 0))
PasteToInputArea(hContact, data);
if (db_get_b(NULL, MODULE, "UrlCopyToClipboard", 0))
PasteToClipboard(data);
}
|