summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_messages.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2014-09-09 19:52:07 +0000
committerAlexander Lantsev <aunsane@gmail.com>2014-09-09 19:52:07 +0000
commit56c1f62b71e28b12e83e4ee7999461f73a3367fb (patch)
tree4a8f66d01a94d3bed7bcd614d5bcaaa1250221ae /protocols/Tox/src/tox_messages.cpp
parent4becc46d15baf8393a347c1d3897af5d8d55dea6 (diff)
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
Diffstat (limited to 'protocols/Tox/src/tox_messages.cpp')
-rw-r--r--protocols/Tox/src/tox_messages.cpp66
1 files changed, 61 insertions, 5 deletions
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<uint8_t> 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)
@@ -80,4 +103,37 @@ int CToxProto::OnPreCreateMessage(WPARAM wParam, LPARAM lParam)
}
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<uint8_t> 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