diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-08-12 18:56:09 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-08-12 18:56:09 +0000 |
commit | e530b1be3a65296d2324b2299897367ee14d4a3d (patch) | |
tree | 12a5f019b133bebf61a26f76b4841075f6162ebd /protocols | |
parent | 9c4e02916ad863a7fdd95d2668f29714997d61c5 (diff) |
Tox: contact status message support
git-svn-id: http://svn.miranda-ng.org/main/trunk@14926 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Tox/src/api_friends.cpp | 135 | ||||
-rw-r--r-- | protocols/Tox/src/api_main.cpp | 138 | ||||
-rw-r--r-- | protocols/Tox/src/tox_contacts.cpp | 2 | ||||
-rw-r--r-- | protocols/Tox/src/tox_messages.cpp | 32 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.cpp | 11 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.h | 2 |
6 files changed, 184 insertions, 136 deletions
diff --git a/protocols/Tox/src/api_friends.cpp b/protocols/Tox/src/api_friends.cpp new file mode 100644 index 0000000000..9856007bc8 --- /dev/null +++ b/protocols/Tox/src/api_friends.cpp @@ -0,0 +1,135 @@ +#include "stdafx.h"
+
+/* FRIEND FUNCTIONS */
+
+uint32_t tox_friend_add(Tox *tox, const uint8_t *address, const uint8_t *message, size_t length, TOX_ERR_FRIEND_ADD *error)
+{
+ return CreateFunction<uint32_t(*)(Tox*, const uint8_t*, const uint8_t*, size_t, TOX_ERR_FRIEND_ADD*)>(__FUNCTION__)(tox, address, message, length, error);
+}
+
+uint32_t tox_friend_add_norequest(Tox *tox, const uint8_t *public_key, TOX_ERR_FRIEND_ADD *error)
+{
+ return CreateFunction<uint32_t(*)(Tox*, const uint8_t*, TOX_ERR_FRIEND_ADD*)>(__FUNCTION__)(tox, public_key, error);
+}
+
+bool tox_friend_delete(Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_DELETE *error)
+{
+ return CreateFunction<bool(*)(Tox*, uint32_t, TOX_ERR_FRIEND_DELETE*)>(__FUNCTION__)(tox, friend_number, error);
+}
+
+uint32_t tox_friend_by_public_key(const Tox *tox, const uint8_t *public_key, TOX_ERR_FRIEND_BY_PUBLIC_KEY *error)
+{
+ return CreateFunction<uint32_t(*)(const Tox*, const uint8_t*, TOX_ERR_FRIEND_BY_PUBLIC_KEY*)>(__FUNCTION__)(tox, public_key, error);
+}
+
+int tox_friend_exists(const Tox *tox, int32_t friendnumber)
+{
+ return CreateFunction<int(*)(const Tox*, int32_t)>(__FUNCTION__)(tox, friendnumber);
+}
+
+size_t tox_self_get_friend_list_size(const Tox *tox)
+{
+ return CreateFunction<size_t(*)(const Tox*)>(__FUNCTION__)(tox);
+}
+
+void tox_self_get_friend_list(const Tox *tox, uint32_t *list)
+{
+ CreateFunction<void(*)(const Tox*, uint32_t*)>(__FUNCTION__)(tox, list);
+}
+
+bool tox_friend_get_public_key(const Tox *tox, uint32_t friend_number, uint8_t *public_key, TOX_ERR_FRIEND_GET_PUBLIC_KEY *error)
+{
+ return CreateFunction<bool(*)(const Tox*, int32_t, uint8_t*, TOX_ERR_FRIEND_GET_PUBLIC_KEY*)>(__FUNCTION__)(tox, friend_number, public_key, error);
+}
+
+uint64_t tox_friend_get_last_online(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_GET_LAST_ONLINE *error)
+{
+ return CreateFunction<uint64_t(*)(const Tox*, uint32_t, TOX_ERR_FRIEND_GET_LAST_ONLINE*)>(__FUNCTION__)(tox, friend_number, error);
+}
+
+size_t tox_friend_get_name_size(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error)
+{
+ return CreateFunction<size_t(*)(const Tox*, uint32_t, TOX_ERR_FRIEND_QUERY*)>(__FUNCTION__)(tox, friend_number, error);
+}
+
+bool tox_friend_get_name(const Tox *tox, uint32_t friend_number, uint8_t *name, TOX_ERR_FRIEND_QUERY *error)
+{
+ return CreateFunction<bool(*)(const Tox*, uint32_t, uint8_t*, TOX_ERR_FRIEND_QUERY*)>(__FUNCTION__)(tox, friend_number, name, error);
+}
+
+void tox_callback_friend_name(Tox *tox, tox_friend_name_cb *function, void *user_data)
+{
+ CreateFunction<void(*)(Tox*tox, tox_friend_name_cb, void*)>(__FUNCTION__)(tox, function, user_data);
+}
+
+size_t tox_friend_get_status_message_size(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error)
+{
+ return CreateFunction<size_t(*)(const Tox*, uint32_t, TOX_ERR_FRIEND_QUERY*)>(__FUNCTION__)(tox, friend_number, error);
+}
+
+bool tox_friend_get_status_message(const Tox *tox, uint32_t friend_number, uint8_t *status_message, TOX_ERR_FRIEND_QUERY *error)
+{
+ return CreateFunction<bool(*)(const Tox*, uint32_t, uint8_t*, TOX_ERR_FRIEND_QUERY*)>(__FUNCTION__)(tox, friend_number, status_message, error);
+}
+
+void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb *function, void *user_data)
+{
+ CreateFunction<void(*)(Tox*, tox_friend_status_message_cb, void*)>(__FUNCTION__)(tox, function, user_data);
+}
+
+TOX_USER_STATUS tox_friend_get_status(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error)
+{
+ return CreateFunction<TOX_USER_STATUS(*)(const Tox*, uint32_t, TOX_ERR_FRIEND_QUERY*)>(__FUNCTION__)(tox, friend_number, error);
+}
+
+void tox_callback_friend_status(Tox *tox, tox_friend_status_cb *function, void *user_data)
+{
+ CreateFunction<void(*)(Tox*, tox_friend_status_cb, void*)>(__FUNCTION__)(tox, function, user_data);
+}
+
+TOX_CONNECTION tox_friend_get_connection_status(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error)
+{
+ return CreateFunction<TOX_CONNECTION(*)(const Tox*, uint32_t, TOX_ERR_FRIEND_QUERY*)>(__FUNCTION__)(tox, friend_number, error);
+}
+
+void tox_callback_friend_connection_status(Tox *tox, tox_friend_connection_status_cb *function, void *user_data)
+{
+ CreateFunction<void(*)(Tox*, tox_friend_connection_status_cb, void*)>(__FUNCTION__)(tox, function, user_data);
+}
+
+bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error)
+{
+ return CreateFunction<bool(*)(const Tox*, uint32_t, TOX_ERR_FRIEND_QUERY*)>(__FUNCTION__)(tox, friend_number, error);
+}
+
+void tox_callback_friend_typing(Tox *tox, tox_friend_typing_cb *function, void *user_data)
+{
+ CreateFunction<void(*)(Tox*, tox_friend_typing_cb, void*)>(__FUNCTION__)(tox, function, user_data);
+}
+
+/* */
+
+bool tox_self_set_typing(Tox *tox, uint32_t friend_number, bool is_typing, TOX_ERR_SET_TYPING *error)
+{
+ return CreateFunction<bool(*)(Tox*, uint32_t, bool, TOX_ERR_SET_TYPING*)>(__FUNCTION__)(tox, friend_number, is_typing, error);
+}
+
+uint32_t tox_friend_send_message(Tox *tox, uint32_t friend_number, TOX_MESSAGE_TYPE type, const uint8_t *message, size_t length, TOX_ERR_FRIEND_SEND_MESSAGE *error)
+{
+ return CreateFunction<uint32_t(*)(Tox*, uint32_t, TOX_MESSAGE_TYPE, const uint8_t*, size_t, TOX_ERR_FRIEND_SEND_MESSAGE*)>(__FUNCTION__)(tox, friend_number, type, message, length, error);
+}
+
+void tox_callback_friend_read_receipt(Tox *tox, tox_friend_read_receipt_cb *function, void *user_data)
+{
+ CreateFunction<void(*)(Tox*, tox_friend_read_receipt_cb, void*)>(__FUNCTION__)(tox, function, user_data);
+}
+
+void tox_callback_friend_request(Tox *tox, tox_friend_request_cb *function, void *user_data)
+{
+ CreateFunction<void(*)(Tox*, tox_friend_request_cb, void*)>(__FUNCTION__)(tox, function, user_data);
+}
+
+void tox_callback_friend_message(Tox *tox, tox_friend_message_cb *function, void *user_data)
+{
+ CreateFunction<void(*)(Tox*, tox_friend_message_cb, void*)>(__FUNCTION__)(tox, function, user_data);
+}
\ No newline at end of file diff --git a/protocols/Tox/src/api_main.cpp b/protocols/Tox/src/api_main.cpp index b9812bfbcd..cc46abcb63 100644 --- a/protocols/Tox/src/api_main.cpp +++ b/protocols/Tox/src/api_main.cpp @@ -28,46 +28,6 @@ void tox_self_get_address(const Tox *tox, uint8_t *address) CreateFunction<void(*)(const Tox*, uint8_t*)>(__FUNCTION__)(tox, address);
}
-uint32_t tox_friend_add(Tox *tox, const uint8_t *address, const uint8_t *message, size_t length, TOX_ERR_FRIEND_ADD *error)
-{
- return CreateFunction<uint32_t(*)(Tox*, const uint8_t*, const uint8_t*, size_t, TOX_ERR_FRIEND_ADD*)>(__FUNCTION__)(tox, address, message, length, error);
-}
-
-uint32_t tox_friend_add_norequest(Tox *tox, const uint8_t *public_key, TOX_ERR_FRIEND_ADD *error)
-{
- return CreateFunction<uint32_t(*)(Tox*, const uint8_t*, TOX_ERR_FRIEND_ADD*)>(__FUNCTION__)(tox, public_key, error);
-}
-
-uint32_t tox_friend_by_public_key(const Tox *tox, const uint8_t *public_key, TOX_ERR_FRIEND_BY_PUBLIC_KEY *error)
-{
- return CreateFunction<uint32_t(*)(const Tox*, const uint8_t*, TOX_ERR_FRIEND_BY_PUBLIC_KEY*)>(__FUNCTION__)(tox, public_key, error);
-}
-
-bool tox_friend_get_public_key(const Tox *tox, uint32_t friend_number, uint8_t *public_key, TOX_ERR_FRIEND_GET_PUBLIC_KEY *error)
-{
- return CreateFunction<bool(*)(const Tox*, int32_t, uint8_t*, TOX_ERR_FRIEND_GET_PUBLIC_KEY*)>(__FUNCTION__)(tox, friend_number, public_key, error);
-}
-
-bool tox_friend_delete(Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_DELETE *error)
-{
- return CreateFunction<bool(*)(Tox*, uint32_t, TOX_ERR_FRIEND_DELETE*)>(__FUNCTION__)(tox, friend_number, error);
-}
-
-int tox_get_friend_connection_status(const Tox *tox, int32_t friendnumber)
-{
- return CreateFunction<int(*)(const Tox*, int32_t)>(__FUNCTION__)(tox, friendnumber);
-}
-
-int tox_friend_exists(const Tox *tox, int32_t friendnumber)
-{
- return CreateFunction<int(*)(const Tox*, int32_t)>(__FUNCTION__)(tox, friendnumber);
-}
-
-uint32_t tox_friend_send_message(Tox *tox, uint32_t friend_number, TOX_MESSAGE_TYPE type, const uint8_t *message, size_t length, TOX_ERR_FRIEND_SEND_MESSAGE *error)
-{
- return CreateFunction<uint32_t(*)(Tox*, uint32_t, TOX_MESSAGE_TYPE, const uint8_t*, size_t, TOX_ERR_FRIEND_SEND_MESSAGE*)>(__FUNCTION__)(tox, friend_number, type, message, length, error);
-}
-
bool tox_self_set_name(Tox *tox, const uint8_t *name, size_t length, TOX_ERR_SET_INFO *error)
{
return CreateFunction<bool(*)(Tox*, const uint8_t*, size_t, TOX_ERR_SET_INFO*)>(__FUNCTION__)(tox, name, length, error);
@@ -78,19 +38,14 @@ void tox_self_get_name(const Tox *tox, uint8_t *name) CreateFunction<void(*)(const Tox*, uint8_t*)>(__FUNCTION__)(tox, name);
}
-bool tox_friend_get_name(const Tox *tox, uint32_t friend_number, uint8_t *name, TOX_ERR_FRIEND_QUERY *error)
-{
- return CreateFunction<bool(*)(const Tox*, uint32_t, uint8_t*, TOX_ERR_FRIEND_QUERY*)>(__FUNCTION__)(tox, friend_number, name, error);
-}
-
-size_t tox_friend_get_name_size(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error)
+int tox_get_self_name_size(const Tox *tox)
{
- return CreateFunction<size_t(*)(const Tox*, uint32_t, TOX_ERR_FRIEND_QUERY*)>(__FUNCTION__)(tox, friend_number, error);
+ return CreateFunction<int(*)(const Tox*)>(__FUNCTION__)(tox);
}
-int tox_get_self_name_size(const Tox *tox)
+size_t tox_self_get_status_message_size(const Tox *tox)
{
- return CreateFunction<int(*)(const Tox*)>(__FUNCTION__)(tox);
+ return CreateFunction<size_t(*)(const Tox*)>(__FUNCTION__)(tox);
}
bool tox_self_set_status_message(Tox *tox, const uint8_t *status, size_t length, TOX_ERR_SET_INFO *error)
@@ -103,106 +58,21 @@ void tox_self_set_status(Tox *tox, TOX_USER_STATUS user_status) CreateFunction<void(*)(Tox*, TOX_USER_STATUS)>(__FUNCTION__)(tox, user_status);
}
-int tox_get_status_message_size(const Tox *tox, int32_t friendnumber)
-{
- return CreateFunction<int(*)(const Tox*, int32_t)>(__FUNCTION__)(tox, friendnumber);
-}
-
void tox_self_get_status_message(const Tox *tox, uint8_t *status)
{
CreateFunction<void(*)(const Tox*, uint8_t*)>(__FUNCTION__)(tox, status);
}
-int tox_get_status_message(const Tox *tox, int32_t friendnumber, uint8_t *buf, uint32_t maxlen)
-{
- return CreateFunction<int(*)(const Tox*, int32_t, uint8_t*, uint32_t)>(__FUNCTION__)(tox, friendnumber, buf, maxlen);
-}
-
int tox_get_self_status_message(const Tox *tox, uint8_t *buf, uint32_t maxlen)
{
return CreateFunction<int(*)(const Tox*, uint8_t*, uint32_t)>(__FUNCTION__)(tox, buf, maxlen);
}
-uint8_t tox_get_user_status(const Tox *tox, int32_t friendnumber)
-{
- return CreateFunction<int(*)(const Tox*, int32_t)>(__FUNCTION__)(tox, friendnumber);
-}
-
uint8_t tox_get_self_user_status(const Tox *tox)
{
return CreateFunction<int(*)(const Tox*)>(__FUNCTION__)(tox);
}
-uint64_t tox_friend_get_last_online(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_GET_LAST_ONLINE *error)
-{
- return CreateFunction<uint64_t(*)(const Tox*, uint32_t, TOX_ERR_FRIEND_GET_LAST_ONLINE*)>(__FUNCTION__)(tox, friend_number, error);
-}
-
-int tox_friend_get_typing(Tox *tox, int32_t friendnumber, uint8_t is_typing)
-{
- return CreateFunction<int(*)(Tox*, int32_t, uint8_t)>(__FUNCTION__)(tox, friendnumber, is_typing);
-}
-
-bool tox_self_set_typing(Tox *tox, uint32_t friend_number, bool is_typing, TOX_ERR_SET_TYPING *error)
-{
- return CreateFunction<bool(*)(Tox*, uint32_t, bool, TOX_ERR_SET_TYPING*)>(__FUNCTION__)(tox, friend_number, is_typing, error);
-}
-
-size_t tox_self_get_friend_list_size(const Tox *tox)
-{
- return CreateFunction<size_t(*)(const Tox*)>(__FUNCTION__)(tox);
-}
-
-uint32_t tox_get_num_online_friends(const Tox *tox)
-{
- return CreateFunction<int(*)(const Tox*)>(__FUNCTION__)(tox);
-}
-
-void tox_self_get_friend_list(const Tox *tox, uint32_t *list)
-{
- CreateFunction<void(*)(const Tox*, uint32_t*)>(__FUNCTION__)(tox, list);
-}
-
-void tox_callback_friend_request(Tox *tox, tox_friend_request_cb *function, void *user_data)
-{
- CreateFunction<void(*)(Tox*, tox_friend_request_cb, void*)>(__FUNCTION__)(tox, function, user_data);
-}
-
-void tox_callback_friend_message(Tox *tox, tox_friend_message_cb *function, void *user_data)
-{
- CreateFunction<void(*)(Tox*, tox_friend_message_cb, void*)>(__FUNCTION__)(tox, function, user_data);
-}
-
-void tox_callback_friend_name(Tox *tox, tox_friend_name_cb *function, void *user_data)
-{
- CreateFunction<void(*)(Tox*tox, tox_friend_name_cb, void*)>(__FUNCTION__)(tox, function, user_data);
-}
-
-void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb *function, void *user_data)
-{
- CreateFunction<void(*)(Tox*, tox_friend_status_message_cb, void*)>(__FUNCTION__)(tox, function, user_data);
-}
-
-void tox_callback_friend_status(Tox *tox, tox_friend_status_cb *function, void *user_data)
-{
- CreateFunction<void(*)(Tox*, tox_friend_status_cb, void*)>(__FUNCTION__)(tox, function, user_data);
-}
-
-void tox_callback_friend_read_receipt(Tox *tox, tox_friend_read_receipt_cb *function, void *user_data)
-{
- CreateFunction<void(*)(Tox*, tox_friend_read_receipt_cb, void*)>(__FUNCTION__)(tox, function, user_data);
-}
-
-void tox_callback_friend_typing(Tox *tox, tox_friend_typing_cb *function, void *user_data)
-{
- CreateFunction<void(*)(Tox*, tox_friend_typing_cb, void*)>(__FUNCTION__)(tox, function, user_data);
-}
-
-void tox_callback_friend_connection_status(Tox *tox, tox_friend_connection_status_cb *function, void *user_data)
-{
- CreateFunction<void(*)(Tox*, tox_friend_connection_status_cb, void*)>(__FUNCTION__)(tox, function, user_data);
-}
-
/* SAVING AND LOADING FUNCTIONS */
size_t tox_get_savedata_size(const Tox *tox)
diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp index 7540961bae..7ce9442134 100644 --- a/protocols/Tox/src/tox_contacts.cpp +++ b/protocols/Tox/src/tox_contacts.cpp @@ -57,7 +57,7 @@ MCONTACT CToxProto::GetContact(const char *pubKey) {
ptrA contactPubKey(getStringA(hContact, TOX_SETTINGS_ID));
// check only public key part of address
- if (strnicmp(pubKey, contactPubKey, TOX_PUBLIC_KEY_SIZE) == 0)
+ if (mir_strncmpi(pubKey, contactPubKey, TOX_PUBLIC_KEY_SIZE) == 0)
break;
}
return hContact;
diff --git a/protocols/Tox/src/tox_messages.cpp b/protocols/Tox/src/tox_messages.cpp index 895e4e9aa1..b52bcbbe8a 100644 --- a/protocols/Tox/src/tox_messages.cpp +++ b/protocols/Tox/src/tox_messages.cpp @@ -111,6 +111,38 @@ int CToxProto::OnPreCreateMessage(WPARAM, LPARAM lParam) return 0;
}
+/* STATUS MESSAGE */
+void CToxProto::GetStatusMessageAsync(void* arg)
+{
+ MCONTACT hContact = (MCONTACT)arg;
+
+ int32_t friendNumber = GetToxFriendNumber(hContact);
+ if (friendNumber == UINT32_MAX)
+ {
+ ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_FAILED, (HANDLE)hContact, 0);
+ return;
+ }
+
+ TOX_ERR_FRIEND_QUERY error;
+ size_t size = tox_friend_get_status_message_size(tox, friendNumber, &error);
+ if (error != TOX_ERR_FRIEND_QUERY::TOX_ERR_FRIEND_QUERY_OK)
+ {
+ debugLogA(__FUNCTION__": failed to get status message for (%d) (%d)", friendNumber, error);
+ ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_FAILED, (HANDLE)hContact, 0);
+ return;
+ }
+
+ ptrA statusMessage((char*)mir_calloc(size + 1));
+ if (!tox_friend_get_status_message(tox, friendNumber, (uint8_t*)(char*)statusMessage, &error))
+ {
+ debugLogA(__FUNCTION__": failed to get status message for (%d) (%d)", friendNumber, error);
+ ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_FAILED, (HANDLE)hContact, 0);
+ return;
+ }
+
+ ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)hContact, ptrT(mir_utf8decodeT(statusMessage)));
+}
+
/* TYPING */
int CToxProto::OnUserIsTyping(MCONTACT hContact, int type)
diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp index aff83a2db3..b31d83f894 100644 --- a/protocols/Tox/src/tox_proto.cpp +++ b/protocols/Tox/src/tox_proto.cpp @@ -210,7 +210,16 @@ int CToxProto::SetStatus(int iNewStatus) return 0;
}
-HANDLE CToxProto::GetAwayMsg(MCONTACT) { return 0; }
+HANDLE CToxProto::GetAwayMsg(MCONTACT hContact)
+{
+ if (IsOnline())
+ {
+ ForkThread(&CToxProto::GetStatusMessageAsync, (void*)hContact);
+ return (HANDLE)hContact;
+ }
+
+ return 0;
+}
int CToxProto::SetAwayMsg(int, const TCHAR *msg)
{
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index b2326dc4d4..28d22f2422 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -215,6 +215,8 @@ private: static void OnFriendMessage(Tox *tox, uint32_t friendNumber, TOX_MESSAGE_TYPE type, const uint8_t *message, size_t length, void *arg);
static void OnReadReceipt(Tox *tox, uint32_t friendNumber, uint32_t messageId, void *arg);
+ void __cdecl GetStatusMessageAsync(void* arg);
+
int OnUserIsTyping(MCONTACT hContact, int type);
static void OnTypingChanged(Tox *tox, uint32_t friendNumber, bool isTyping, void *arg);
|