From 41ec75629ab19e84dd25a168797afe5fe8c01594 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Mon, 11 Aug 2014 19:45:13 +0000 Subject: Tox: some of message sending git-svn-id: http://svn.miranda-ng.org/main/trunk@10158 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_account.cpp | 5 +++++ protocols/Tox/src/tox_contacts.cpp | 4 ++-- protocols/Tox/src/tox_events.cpp | 17 +++++++++++++++++ protocols/Tox/src/tox_proto.cpp | 22 ++++++++++++++++++++-- protocols/Tox/src/tox_proto.h | 11 +++++++---- protocols/Tox/src/tox_utils.cpp | 12 ++++++------ 6 files changed, 57 insertions(+), 14 deletions(-) (limited to 'protocols') diff --git a/protocols/Tox/src/tox_account.cpp b/protocols/Tox/src/tox_account.cpp index 59edd4ec52..77a8095dd2 100644 --- a/protocols/Tox/src/tox_account.cpp +++ b/protocols/Tox/src/tox_account.cpp @@ -1,6 +1,11 @@ #include "common.h" #include "tox_bootstrap.h" +bool CToxProto::IsOnline() +{ + return isConnected && m_iStatus > ID_STATUS_OFFLINE; +} + void CToxProto::DoBootstrap() { static int j = 0; diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp index 929ca1fbf3..ddd880b631 100644 --- a/protocols/Tox/src/tox_contacts.cpp +++ b/protocols/Tox/src/tox_contacts.cpp @@ -5,7 +5,7 @@ bool CToxProto::IsProtoContact(MCONTACT hContact) return ::lstrcmpiA(::GetContactProto(hContact), m_szModuleName) == 0; } -MCONTACT CToxProto::GetContactByUserId(const char *clientId) +MCONTACT CToxProto::GetContactByClientId(const char *clientId) { MCONTACT hContact = NULL; @@ -25,7 +25,7 @@ MCONTACT CToxProto::GetContactByUserId(const char *clientId) MCONTACT CToxProto::AddContact(const char *clientId, const char *nick, bool isHidden) { - MCONTACT hContact = GetContactByUserId(clientId); + MCONTACT hContact = GetContactByClientId(clientId); if (!hContact) { hContact = (MCONTACT)::CallService(MS_DB_CONTACT_ADD, 0, 0); diff --git a/protocols/Tox/src/tox_events.cpp b/protocols/Tox/src/tox_events.cpp index d4ab8a8960..45060ab170 100644 --- a/protocols/Tox/src/tox_events.cpp +++ b/protocols/Tox/src/tox_events.cpp @@ -66,4 +66,21 @@ void CToxProto::OnConnectionStatusChanged(Tox *tox, const int friendId, const ui void CToxProto::OnAction(Tox *tox, const int friendId, const uint8_t *message, const uint16_t messageSize, void *arg) { +} + +void CToxProto::OnReadReceipt(Tox *tox, int32_t friendnumber, uint32_t receipt, void *arg) +{ + CToxProto *proto = (CToxProto*)arg; + + std::vector clientId(TOX_CLIENT_ID_SIZE); + tox_get_client_id(tox, friendnumber, &clientId[0]); + std::string toxId = proto->DataToHexString(clientId); + + MCONTACT hContact = proto->GetContactByClientId(toxId.c_str()); + + proto->ProtoBroadcastAck( + hContact, + ACKTYPE_MESSAGE, + ACKRESULT_SUCCESS, + (HANDLE)receipt, 0); } \ No newline at end of file diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp index 9413a56e40..e2734d8aca 100644 --- a/protocols/Tox/src/tox_proto.cpp +++ b/protocols/Tox/src/tox_proto.cpp @@ -17,6 +17,7 @@ CToxProto::CToxProto(const char* protoName, const TCHAR* userName) : tox_callback_name_change(tox, OnFriendNameChange, this); tox_callback_status_message(tox, OnStatusMessageChanged, this); tox_callback_user_status(tox, OnUserStatusChanged, this); + tox_callback_read_receipt(tox, OnReadReceipt, this); tox_callback_connection_status(tox, OnConnectionStatusChanged, this); CreateProtoService(PS_CREATEACCMGRUI, &CToxProto::OnAccountManagerInit); @@ -63,7 +64,7 @@ DWORD_PTR __cdecl CToxProto::GetCaps(int type, MCONTACT hContact) case PFLAGNUM_2: return PF2_ONLINE | PF2_SHORTAWAY | PF2_LIGHTDND; case PFLAGNUM_4: - return PF4_SUPPORTTYPING; + return PF4_IMSENDUTF | PF4_SUPPORTTYPING; case PFLAG_UNIQUEIDTEXT: return (INT_PTR)"Tox ID"; case PFLAG_UNIQUEIDSETTING: @@ -97,7 +98,24 @@ int __cdecl CToxProto::RecvUrl(MCONTACT hContact, PROTORECVEVENT*) { return 0; } int __cdecl CToxProto::SendContacts(MCONTACT hContact, int flags, int nContacts, MCONTACT* hContactsList) { return 0; } HANDLE __cdecl CToxProto::SendFile(MCONTACT hContact, const PROTOCHAR* szDescription, PROTOCHAR** ppszFiles) { return 0; } -int __cdecl CToxProto::SendMsg(MCONTACT hContact, int flags, const char* msg) { return 0; } + +int __cdecl CToxProto::SendMsg(MCONTACT hContact, int flags, const char* msg) +{ + if (!IsOnline()) + { + return 1; + } + + std::string toxId(getStringA(hContact, TOX_SETTING_ID)); + std::vector clientId = HexStringToData(toxId); + + uint32_t number = tox_get_friend_number(tox, clientId.data()); + + int messageId = tox_send_message(tox, number, (uint8_t*)msg, strlen(msg)); + + return messageId; +} + int __cdecl CToxProto::SendUrl(MCONTACT hContact, int flags, const char* url) { return 0; } int __cdecl CToxProto::SetApparentMode(MCONTACT hContact, int mode) { return 0; } diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index 220e07d0c0..81ee596e7f 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -83,9 +83,11 @@ private: static int CompareProtos(const CToxProto *p1, const CToxProto *p2); // account + bool IsOnline(); + void DoBootstrap(); void DoTox(); - + void __cdecl ConnectionThread(void*); void __cdecl PollingThread(void*); @@ -101,10 +103,11 @@ private: static void OnUserStatusChanged(Tox *tox, int32_t friendnumber, uint8_t TOX_USERSTATUS, void *userdata); static void OnConnectionStatusChanged(Tox *tox, const int friendId, const uint8_t status, void *arg); static void OnAction(Tox *tox, const int friendId, const uint8_t *message, const uint16_t messageSize, void *arg); + static void OnReadReceipt(Tox *tox, int32_t friendnumber, uint32_t receipt, void *arg); // contacts bool IsProtoContact(MCONTACT hContact); - MCONTACT GetContactByUserId(const char *clientId); + MCONTACT GetContactByClientId(const char *clientId); MCONTACT AddContact(const char *clientId, const char *nick, bool isHidden = false); void LoadContactList(); @@ -118,8 +121,8 @@ private: // utils TOX_USERSTATUS MirandaToToxStatus(int status); - std::vector HexStringToData(const std::string hex); - std::string DataToHexString(const std::vector); + std::vector HexStringToData(std::string hex); + std::string DataToHexString(std::vector); int LoadToxData(const char *path); int SaveToxData(const char *path); diff --git a/protocols/Tox/src/tox_utils.cpp b/protocols/Tox/src/tox_utils.cpp index 456b1dd75a..b8eed67c68 100644 --- a/protocols/Tox/src/tox_utils.cpp +++ b/protocols/Tox/src/tox_utils.cpp @@ -21,7 +21,7 @@ TOX_USERSTATUS CToxProto::MirandaToToxStatus(int status) return userstatus; } -std::vector HexStringToData(const std::string hex) +std::vector CToxProto::HexStringToData(std::string hex) { std::stringstream ss; std::vector data; @@ -29,16 +29,16 @@ std::vector HexStringToData(const std::string hex) size_t count = hex.length() / 2; for (size_t i = 0; i < count; i++) { - uint8_t temp; - ss << std::hex << hex.substr(i * 2, 2); - ss >> temp; - data.push_back(temp); + unsigned byte; + std::istringstream hex_byte(hex.substr(i * 2, 2)); + hex_byte >> std::hex >> byte; + data.push_back(static_cast(byte)); } return data; } -std::string CToxProto::DataToHexString(const std::vector data) +std::string CToxProto::DataToHexString(std::vector data) { std::stringstream ss; ss << std::hex << std::uppercase; -- cgit v1.2.3