diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2014-08-12 18:28:50 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2014-08-12 18:28:50 +0000 |
commit | 4330c62d2fa5b2752036b43018044c7c01b10695 (patch) | |
tree | 41001600877a55ad94ab03f9ccbbe3fab56585ad /protocols | |
parent | c1fdf24779e15d5a1063340b35a4f7b2e3bf9d6a (diff) |
Tox: contact name, status, status message saving
git-svn-id: http://svn.miranda-ng.org/main/trunk@10167 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Tox/src/tox_contacts.cpp | 27 | ||||
-rw-r--r-- | protocols/Tox/src/tox_events.cpp | 40 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.cpp | 7 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.h | 11 | ||||
-rw-r--r-- | protocols/Tox/src/tox_utils.cpp | 21 |
5 files changed, 92 insertions, 14 deletions
diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp index 7249bc47ab..788105b0d4 100644 --- a/protocols/Tox/src/tox_contacts.cpp +++ b/protocols/Tox/src/tox_contacts.cpp @@ -1,8 +1,25 @@ #include "common.h"
+void CToxProto::SetContactStatus(MCONTACT hContact, WORD status)
+{
+ WORD oldStatus = getWord(hContact, "Status", ID_STATUS_OFFLINE);
+ if (oldStatus != status)
+ {
+ setWord(hContact, "Status", status);
+ }
+}
+
+void CToxProto::SetAllContactsStatus(WORD status)
+{
+ for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
+ {
+ setWord(hContact, "Status", status);
+ }
+}
+
bool CToxProto::IsProtoContact(MCONTACT hContact)
{
- return ::lstrcmpiA(::GetContactProto(hContact), m_szModuleName) == 0;
+ return lstrcmpiA(GetContactProto(hContact), m_szModuleName) == 0;
}
MCONTACT CToxProto::FindContact(const char *clientId)
@@ -23,7 +40,7 @@ MCONTACT CToxProto::FindContact(const char *clientId) return hContact;
}
-MCONTACT CToxProto::AddContact(const char *clientId, const char *nick, bool isHidden)
+MCONTACT CToxProto::AddContact(const char *clientId, bool isHidden)
{
MCONTACT hContact = FindContact(clientId);
if (!hContact)
@@ -39,7 +56,6 @@ MCONTACT CToxProto::AddContact(const char *clientId, const char *nick, bool isHi }*/
setString(hContact, TOX_SETTING_ID, clientId);
- setString(hContact, "Nick", nick);
}
return hContact;
@@ -59,10 +75,7 @@ void CToxProto::LoadContactList() tox_get_client_id(tox, friends[i], &clientId[0]);
std::string toxId = DataToHexString(clientId);
- tox_get_name(tox, friends[i], &username[0]);
- std::string nick(username.begin(), username.end());
-
- MCONTACT hContact = AddContact(toxId.c_str(), nick.c_str());
+ MCONTACT hContact = AddContact(toxId.c_str());
}
}
}
diff --git a/protocols/Tox/src/tox_events.cpp b/protocols/Tox/src/tox_events.cpp index 28f2983a4d..c34e8078fb 100644 --- a/protocols/Tox/src/tox_events.cpp +++ b/protocols/Tox/src/tox_events.cpp @@ -64,16 +64,50 @@ void CToxProto::OnFriendMessage(Tox *tox, const int friendnumber, const uint8_t }
}
-void CToxProto::OnFriendNameChange(Tox *tox, const int friendId, const uint8_t *name, const uint16_t nameSize, void *arg)
+void CToxProto::OnFriendNameChange(Tox *tox, const int friendnumber, const uint8_t *name, const uint16_t nameSize, void *arg)
{
+ CToxProto *proto = (CToxProto*)arg;
+
+ std::vector<uint8_t> 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)
+ {
+ proto->setString(hContact, "Nick", (char*)name);
+ }
}
-void CToxProto::OnStatusMessageChanged(Tox *tox, const int friendId, const uint8_t* message, const uint16_t messageSize, void *arg)
+void CToxProto::OnStatusMessageChanged(Tox *tox, const int friendnumber, const uint8_t* message, const uint16_t messageSize, void *arg)
{
+ CToxProto *proto = (CToxProto*)arg;
+
+ std::vector<uint8_t> 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)
+ {
+ db_set_s(hContact, "CList", "StatusMsg", (char*)message);
+ }
}
-void CToxProto::OnUserStatusChanged(Tox *tox, int32_t friendnumber, uint8_t TOX_USERSTATUS, void *userdata)
+void CToxProto::OnUserStatusChanged(Tox *tox, int32_t friendnumber, uint8_t usertatus, void *arg)
{
+ CToxProto *proto = (CToxProto*)arg;
+
+ std::vector<uint8_t> 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)
+ {
+ int status = proto->ToxToMirandaStatus((TOX_USERSTATUS)usertatus);
+ proto->SetContactStatus(hContact, status);
+ }
}
void CToxProto::OnConnectionStatusChanged(Tox *tox, const int friendId, const uint8_t status, void *arg)
diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp index 676039ce76..ee4c60b917 100644 --- a/protocols/Tox/src/tox_proto.cpp +++ b/protocols/Tox/src/tox_proto.cpp @@ -22,6 +22,8 @@ CToxProto::CToxProto(const char* protoName, const TCHAR* userName) : CreateProtoService(PS_CREATEACCMGRUI, &CToxProto::OnAccountManagerInit);
+ SetAllContactsStatus(ID_STATUS_OFFLINE);
+
hMessageProcess = 1;
}
@@ -143,6 +145,11 @@ int __cdecl CToxProto::SetStatus(int iNewStatus) ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
+ if (!Miranda_Terminated())
+ {
+ SetAllContactsStatus(ID_STATUS_OFFLINE);
+ }
+
return 0;
}
else
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index f443528421..53c1c3bf7d 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -99,17 +99,19 @@ private: static void OnFriendRequest(Tox *tox, const uint8_t *userId, const uint8_t *message, const uint16_t messageSize, void *arg);
static void OnFriendMessage(Tox *tox, const int friendnumber, const uint8_t *message, const uint16_t messageSize, void *arg);
- static void OnFriendNameChange(Tox *tox, const int friendId, const uint8_t *name, const uint16_t nameSize, void *arg);
- static void OnStatusMessageChanged(Tox *tox, const int friendId, const uint8_t* message, const uint16_t messageSize, void *arg);
- static void OnUserStatusChanged(Tox *tox, int32_t friendnumber, uint8_t TOX_USERSTATUS, void *userdata);
+ static void OnFriendNameChange(Tox *tox, const int friendnumber, const uint8_t *name, const uint16_t nameSize, void *arg);
+ static void OnStatusMessageChanged(Tox *tox, const int friendnumber, const uint8_t* message, const uint16_t messageSize, void *arg);
+ static void OnUserStatusChanged(Tox *tox, int32_t friendnumber, uint8_t usertatus, void *arg);
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
+ void SetContactStatus(MCONTACT hContact, WORD status);
+ void SetAllContactsStatus(WORD status);
bool IsProtoContact(MCONTACT hContact);
MCONTACT FindContact(const char *clientId);
- MCONTACT AddContact(const char *clientId, const char *nick, bool isHidden = false);
+ MCONTACT AddContact(const char *clientId, bool isHidden = false);
void LoadContactList();
@@ -121,6 +123,7 @@ private: // utils
TOX_USERSTATUS MirandaToToxStatus(int status);
+ int ToxToMirandaStatus(TOX_USERSTATUS userstatus);
HANDLE AddDbEvent(MCONTACT hContact, WORD type, DWORD timestamp, DWORD flags, DWORD cbBlob, PBYTE pBlob);
diff --git a/protocols/Tox/src/tox_utils.cpp b/protocols/Tox/src/tox_utils.cpp index bd26d9136b..4876b7e9fd 100644 --- a/protocols/Tox/src/tox_utils.cpp +++ b/protocols/Tox/src/tox_utils.cpp @@ -21,6 +21,27 @@ TOX_USERSTATUS CToxProto::MirandaToToxStatus(int status) return userstatus;
}
+int CToxProto::ToxToMirandaStatus(TOX_USERSTATUS userstatus)
+{
+ int status;
+ switch (userstatus)
+ {
+ case TOX_USERSTATUS_NONE:
+ status = ID_STATUS_ONLINE;
+ break;
+ case TOX_USERSTATUS_AWAY:
+ status = ID_STATUS_AWAY;
+ break;
+ case TOX_USERSTATUS_BUSY:
+ status = ID_STATUS_OCCUPIED;
+ break;
+ default:
+ status = ID_STATUS_OFFLINE;
+ break;
+ }
+ return status;
+}
+
HANDLE CToxProto::AddDbEvent(MCONTACT hContact, WORD type, DWORD timestamp, DWORD flags, DWORD cbBlob, PBYTE pBlob)
{
DBEVENTINFO dbei = { sizeof(dbei) };
|