summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-11-03 10:43:20 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-11-03 10:43:20 +0300
commita7672154de78b838ab9110d202784897b0abd464 (patch)
treef8a2b3c0099b858cf2cd30bdbb989255226e5c26
parent8576740bf5e710a9ceaf25b7fbe47aa94372c97c (diff)
WhatsApp: support for message titles in the extended messages
-rw-r--r--protocols/WhatsApp/res/whatsapp.rc1
-rw-r--r--protocols/WhatsApp/src/appsync.cpp2
-rw-r--r--protocols/WhatsApp/src/message.cpp2
-rw-r--r--protocols/WhatsApp/src/options.cpp7
-rw-r--r--protocols/WhatsApp/src/proto.cpp1
-rw-r--r--protocols/WhatsApp/src/proto.h2
-rw-r--r--protocols/WhatsApp/src/resource.h1
-rw-r--r--protocols/WhatsApp/src/utils.cpp24
-rw-r--r--protocols/WhatsApp/src/utils.h2
9 files changed, 33 insertions, 9 deletions
diff --git a/protocols/WhatsApp/res/whatsapp.rc b/protocols/WhatsApp/res/whatsapp.rc
index c134163fa5..a3ad787518 100644
--- a/protocols/WhatsApp/res/whatsapp.rc
+++ b/protocols/WhatsApp/res/whatsapp.rc
@@ -62,6 +62,7 @@ BEGIN
EDITTEXT IDC_DEVICE_NAME,87,41,211,12,ES_AUTOHSCROLL
CONTROL "Do not open chat windows on creation",IDC_HIDECHATS,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,64,294,10
+ CONTROL "Use BBCodes",IDC_USEBBCODES,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,78,294,10
END
IDD_GROUPCHAT_INVITE DIALOGEX 0, 0, 215, 170
diff --git a/protocols/WhatsApp/src/appsync.cpp b/protocols/WhatsApp/src/appsync.cpp
index 9289cd57b1..2032a928ec 100644
--- a/protocols/WhatsApp/src/appsync.cpp
+++ b/protocols/WhatsApp/src/appsync.cpp
@@ -274,7 +274,7 @@ void WhatsAppProto::ProcessHistorySync(const Wa__HistorySync *pSync)
continue;
}
- CMStringA szMessageText(getMessageText(pMessage->message->message));
+ CMStringA szMessageText(GetMessageText(pMessage->message->message));
if (!szMessageText.IsEmpty()) {
PROTORECVEVENT pre = {};
pre.timestamp = pMessage->message->messagetimestamp;
diff --git a/protocols/WhatsApp/src/message.cpp b/protocols/WhatsApp/src/message.cpp
index 74bead6695..b653b18688 100644
--- a/protocols/WhatsApp/src/message.cpp
+++ b/protocols/WhatsApp/src/message.cpp
@@ -210,7 +210,7 @@ void WhatsAppProto::ProcessMessage(WAMSG type, const Wa__WebMessageInfo &msg)
// try to extract some text
if (pUser) {
- CMStringA szMessageText(getMessageText(body));
+ CMStringA szMessageText(GetMessageText(body));
if (!szMessageText.IsEmpty()) {
PROTORECVEVENT pre = {};
pre.timestamp = timestamp;
diff --git a/protocols/WhatsApp/src/options.cpp b/protocols/WhatsApp/src/options.cpp
index 0da3576456..0df8e005b1 100644
--- a/protocols/WhatsApp/src/options.cpp
+++ b/protocols/WhatsApp/src/options.cpp
@@ -11,13 +11,14 @@ Copyright © 2019-22 George Hazan
class COptionsDlg : public CProtoDlgBase<WhatsAppProto>
{
- CCtrlCheck chkHideChats;
+ CCtrlCheck chkHideChats, chkBbcodes;
CCtrlEdit edtGroup, edtNick, edtDevName;
ptrW m_wszOldGroup;
public:
COptionsDlg(WhatsAppProto *ppro, int iDlgID, bool bFullDlg) :
CProtoDlgBase<WhatsAppProto>(ppro, iDlgID),
+ chkBbcodes(this, IDC_USEBBCODES),
chkHideChats(this, IDC_HIDECHATS),
edtNick(this, IDC_NICK),
edtGroup(this, IDC_DEFGROUP),
@@ -28,8 +29,10 @@ public:
CreateLink(edtGroup, ppro->m_wszDefaultGroup);
CreateLink(edtDevName, ppro->m_wszDeviceName);
- if (bFullDlg)
+ if (bFullDlg) {
CreateLink(chkHideChats, ppro->m_bHideGroupchats);
+ CreateLink(chkBbcodes, ppro->m_bUseBbcodes);
+ }
}
bool OnInitDialog() override
diff --git a/protocols/WhatsApp/src/proto.cpp b/protocols/WhatsApp/src/proto.cpp
index 8d72d38af0..64bc73a292 100644
--- a/protocols/WhatsApp/src/proto.cpp
+++ b/protocols/WhatsApp/src/proto.cpp
@@ -49,6 +49,7 @@ WhatsAppProto::WhatsAppProto(const char *proto_name, const wchar_t *username) :
m_wszDeviceName(this, "DeviceName", L"Miranda NG"),
m_wszDefaultGroup(this, "DefaultGroup", L"WhatsApp"),
m_bUsePopups(this, "UsePopups", true),
+ m_bUseBbcodes(this, "UseBbcodes", true),
m_bHideGroupchats(this, "HideChats", true)
{
db_set_resident(m_szModuleName, "StatusMsg");
diff --git a/protocols/WhatsApp/src/proto.h b/protocols/WhatsApp/src/proto.h
index 57f980fb7a..8a8e3461a4 100644
--- a/protocols/WhatsApp/src/proto.h
+++ b/protocols/WhatsApp/src/proto.h
@@ -309,6 +309,7 @@ class WhatsAppProto : public PROTO<WhatsAppProto>
int m_iPacketId;
uint16_t m_wMsgPrefix[2];
CMStringA GenerateMessageId();
+ CMStringA GetMessageText(const Wa__Message *pMessage);
void ProcessMessage(WAMSG type, const Wa__WebMessageInfo &msg);
bool CreateMsgParticipant(WANode *pParticipants, const WAJid &jid, const MBinBuffer &orig);
@@ -434,6 +435,7 @@ public:
CMOption<wchar_t*> m_wszDeviceName; // how do you see Miranda in mobile phone
CMOption<wchar_t*> m_wszDefaultGroup; // clist group to store contacts
CMOption<bool> m_bHideGroupchats; // do not open chat windows on creation
+ CMOption<bool> m_bUseBbcodes; // use extended markup for messages
// Processing Threads //////////////////////////////////////////////////////////////////
diff --git a/protocols/WhatsApp/src/resource.h b/protocols/WhatsApp/src/resource.h
index e245d1deec..8464ab3d8a 100644
--- a/protocols/WhatsApp/src/resource.h
+++ b/protocols/WhatsApp/src/resource.h
@@ -14,6 +14,7 @@
#define IDC_NEWJID 1004
#define IDC_NICK 1005
#define IDC_DEVICE_NAME 1006
+#define IDC_USEBBCODES 1007
// Next default values for new objects
//
diff --git a/protocols/WhatsApp/src/utils.cpp b/protocols/WhatsApp/src/utils.cpp
index 5680c7ab1d..880b0e9469 100644
--- a/protocols/WhatsApp/src/utils.cpp
+++ b/protocols/WhatsApp/src/utils.cpp
@@ -96,6 +96,9 @@ void LT_HASH::sub(const void *pData, size_t len)
WAUser* WhatsAppProto::FindUser(const char *szId)
{
+ if (szId == nullptr)
+ return nullptr;
+
mir_cslock lck(m_csUsers);
auto *tmp = (WAUser *)_alloca(sizeof(WAUser));
tmp->szId = (char*)szId;
@@ -413,12 +416,21 @@ CMStringA file2string(const wchar_t *pwszFileName)
return res;
}
-CMStringA getMessageText(const Wa__Message *pMessage)
+CMStringA WhatsAppProto::GetMessageText(const Wa__Message *pMessage)
{
CMStringA szMessageText;
if (pMessage) {
if (auto *pExt = pMessage->extendedtextmessage) {
+ if (pExt->title) {
+ if (m_bUseBbcodes)
+ szMessageText.Append("<b>");
+ szMessageText.Append(pExt->title);
+ if (m_bUseBbcodes)
+ szMessageText.Append("</b>");
+ szMessageText.Append("\n");
+ }
+
if (pExt->contextinfo && pExt->contextinfo->quotedmessage)
szMessageText.AppendFormat("> %s\n\n", pExt->contextinfo->quotedmessage->conversation);
@@ -446,8 +458,14 @@ void proto::CleanBinary(ProtobufCBinaryData &field)
ProtobufCBinaryData proto::SetBinary(const void *pData, size_t len)
{
ProtobufCBinaryData res;
- res.data = (uint8_t*)malloc(res.len = len);
- memcpy(res.data, pData, len);
+ if (pData == nullptr) {
+ res.data = nullptr;
+ res.len = 0;
+ }
+ else {
+ res.data = (uint8_t *)malloc(res.len = len);
+ memcpy(res.data, pData, len);
+ }
return res;
}
diff --git a/protocols/WhatsApp/src/utils.h b/protocols/WhatsApp/src/utils.h
index bda92a061e..af13efd2eb 100644
--- a/protocols/WhatsApp/src/utils.h
+++ b/protocols/WhatsApp/src/utils.h
@@ -208,8 +208,6 @@ MBinBuffer decodeBufStr(const std::string &buf);
void padBuffer16(MBinBuffer &buf);
MBinBuffer unpadBuffer16(const MBinBuffer &buf);
-CMStringA getMessageText(const Wa__Message *pMessage);
-
CMStringA protobuf_c_text_to_string(const ProtobufCMessage *m);
MBinBuffer aesDecrypt(