From c1fdf24779e15d5a1063340b35a4f7b2e3bf9d6a Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Tue, 12 Aug 2014 17:23:41 +0000 Subject: Tox: added message receiving git-svn-id: http://svn.miranda-ng.org/main/trunk@10166 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_events.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'protocols/Tox/src/tox_events.cpp') diff --git a/protocols/Tox/src/tox_events.cpp b/protocols/Tox/src/tox_events.cpp index 45060ab170..28f2983a4d 100644 --- a/protocols/Tox/src/tox_events.cpp +++ b/protocols/Tox/src/tox_events.cpp @@ -44,8 +44,24 @@ void CToxProto::OnFriendRequest(Tox *tox, const uint8_t *userId, const uint8_t * { } -void CToxProto::OnFriendMessage(Tox *tox, const int friendId, const uint8_t *message, const uint16_t messageSize, void *arg) +void CToxProto::OnFriendMessage(Tox *tox, const int friendnumber, const uint8_t *message, const uint16_t messageSize, 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->FindContact(toxId.c_str()); + if (hContact) + { + PROTORECVEVENT recv = { 0 }; + recv.flags = PREF_UTF; + recv.timestamp = time(NULL); + recv.szMessage = mir_strdup((char*)message); + + ProtoChainRecvMsg(hContact, &recv); + } } void CToxProto::OnFriendNameChange(Tox *tox, const int friendId, const uint8_t *name, const uint16_t nameSize, void *arg) @@ -76,7 +92,7 @@ void CToxProto::OnReadReceipt(Tox *tox, int32_t friendnumber, uint32_t receipt, tox_get_client_id(tox, friendnumber, &clientId[0]); std::string toxId = proto->DataToHexString(clientId); - MCONTACT hContact = proto->GetContactByClientId(toxId.c_str()); + MCONTACT hContact = proto->FindContact(toxId.c_str()); proto->ProtoBroadcastAck( hContact, -- cgit v1.2.3