From 56c1f62b71e28b12e83e4ee7999461f73a3367fb Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Tue, 9 Sep 2014 19:52:07 +0000 Subject: Tox: id saves in db as blob at now git-svn-id: http://svn.miranda-ng.org/main/trunk@10412 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_messages.cpp | 66 +++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 5 deletions(-) (limited to 'protocols/Tox/src/tox_messages.cpp') diff --git a/protocols/Tox/src/tox_messages.cpp b/protocols/Tox/src/tox_messages.cpp index 0c57fbf68d..ee19016c2d 100644 --- a/protocols/Tox/src/tox_messages.cpp +++ b/protocols/Tox/src/tox_messages.cpp @@ -33,15 +33,38 @@ void CToxProto::OnFriendAction(Tox *tox, const int number, const uint8_t *action } } -void CToxProto::OnTypingChanged(Tox *tox, const int number, uint8_t isTyping, void *arg) +int __cdecl CToxProto::SendMsg(MCONTACT hContact, int flags, const char* msg) { - CToxProto *proto = (CToxProto*)arg; + DBVARIANT dbv; + std::vector id(TOX_CLIENT_ID_SIZE); + if (!db_get(hContact, m_szModuleName, TOX_SETTINGS_ID, &dbv)) + { + memcpy(&id[0], dbv.pbVal, TOX_CLIENT_ID_SIZE); + db_free(&dbv); + } - MCONTACT hContact = proto->FindContact(number); - if (hContact) + uint32_t number = tox_get_friend_number(tox, id.data()); + if (number == TOX_ERROR) { - CallService(MS_PROTO_CONTACTISTYPING, hContact, (LPARAM)isTyping); + debugLogA("CToxProto::SendMsg: failed to get friend number"); + return 0; } + + int result = 0; + if (strncmp(msg, "/me ", 4) != 0) + { + result = tox_send_message(tox, number, (uint8_t*)msg, (uint16_t)strlen(msg)); + } + else + { + result = tox_send_action(tox, number, (uint8_t*)&msg[4], (uint16_t)strlen(msg) - 4); + } + if (result == 0) + { + debugLogA("CToxProto::SendMsg: could not to send message"); + } + + return result; } void CToxProto::OnReadReceipt(Tox *tox, int32_t number, uint32_t receipt, void *arg) @@ -79,5 +102,38 @@ int CToxProto::OnPreCreateMessage(WPARAM wParam, LPARAM lParam) evt->dbei->eventType = TOX_DB_EVENT_TYPE_ACTION; } + return 1; +} + +void CToxProto::OnTypingChanged(Tox *tox, const int number, uint8_t isTyping, void *arg) +{ + CToxProto *proto = (CToxProto*)arg; + + MCONTACT hContact = proto->FindContact(number); + if (hContact) + { + CallService(MS_PROTO_CONTACTISTYPING, hContact, (LPARAM)isTyping); + } +} + +int __cdecl CToxProto::UserIsTyping(MCONTACT hContact, int type) +{ + if (hContact && IsOnline()) + { + DBVARIANT dbv; + std::vector id(TOX_CLIENT_ID_SIZE); + if (!db_get(hContact, m_szModuleName, TOX_SETTINGS_ID, &dbv)) + { + memcpy(&id[0], dbv.pbVal, TOX_CLIENT_ID_SIZE); + db_free(&dbv); + } + uint32_t number = tox_get_friend_number(tox, id.data()); + if (number >= 0) + { + tox_set_user_is_typing(tox, number, type); + return 0; + } + } + return 1; } \ No newline at end of file -- cgit v1.2.3