From 59328dff21b246ffee24cfd45dfe36b65c76e916 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Sat, 11 May 2013 14:49:09 +0000 Subject: - fix own nick in chat log - add thread sync on contact searching in db git-svn-id: http://svn.miranda-ng.org/main/trunk@4632 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Skype/src/skype_chat.cpp | 19 ++++++++++++++----- protocols/Skype/src/skype_contacts.cpp | 23 +++++++++++++++-------- protocols/Skype/src/skype_events.cpp | 7 +++---- protocols/Skype/src/skype_own_info.cpp | 5 +++++ protocols/Skype/src/skype_proto.cpp | 4 ++-- protocols/Skype/src/skype_proto.h | 2 +- 6 files changed, 40 insertions(+), 20 deletions(-) (limited to 'protocols/Skype') diff --git a/protocols/Skype/src/skype_chat.cpp b/protocols/Skype/src/skype_chat.cpp index c17ac72106..d5f0c9d787 100644 --- a/protocols/Skype/src/skype_chat.cpp +++ b/protocols/Skype/src/skype_chat.cpp @@ -192,17 +192,23 @@ bool CSkypeProto::IsChatRoom(HANDLE hContact) HANDLE CSkypeProto::GetChatRoomByCid(const wchar_t *cid) { - for (HANDLE hContact = ::db_find_first(this->m_szModuleName); hContact; hContact = ::db_find_next(hContact, this->m_szModuleName)) + HANDLE hContact = NULL; + + ::EnterCriticalSection(&this->contact_search_lock); + + for (hContact = ::db_find_first(this->m_szModuleName); hContact; hContact = ::db_find_next(hContact, this->m_szModuleName)) { if (this->IsChatRoom(hContact)) { mir_ptr chatID(::db_get_wsa(hContact, this->m_szModuleName, "ChatRoomID")); if (::lstrcmp(cid, chatID) == 0) - return hContact; + break; } } - return 0; + ::LeaveCriticalSection(&this->contact_search_lock); + + return hContact; } HANDLE CSkypeProto::AddChatRoom(CConversation::Ref conversation) @@ -449,9 +455,12 @@ void CSkypeProto::LeaveChat(const wchar_t *cid) void CSkypeProto::RaiseChatEvent(const wchar_t *cid, const wchar_t *sid, int evt, DWORD flags, DWORD itemData, const wchar_t *status, const wchar_t *message) { HANDLE hContact = this->GetContactBySid(sid); - mir_ptr nick( hContact ? + mir_ptr nick(::db_get_wsa(hContact, this->m_szModuleName, "Nick")); + if (!nick) + nick = ::mir_wstrdup(sid); + /*mir_ptr nick( hContact ? ::mir_a2u((char *)::CallService(MS_CLIST_GETCONTACTDISPLAYNAME, WPARAM(hContact), 0)) : - ::mir_wstrdup(sid)); + ::mir_wstrdup(sid));*/ GCDEST gcd = { this->m_szModuleName, { NULL }, evt }; gcd.ptszID = ::mir_wstrdup(cid); diff --git a/protocols/Skype/src/skype_contacts.cpp b/protocols/Skype/src/skype_contacts.cpp index bf2582b71a..e5f15afd93 100644 --- a/protocols/Skype/src/skype_contacts.cpp +++ b/protocols/Skype/src/skype_contacts.cpp @@ -159,17 +159,23 @@ bool CSkypeProto::IsProtoContact(HANDLE hContact) HANDLE CSkypeProto::GetContactBySid(const wchar_t *sid) { - for (HANDLE hContact = ::db_find_first(this->m_szModuleName); hContact; hContact = ::db_find_next(hContact, this->m_szModuleName)) + HANDLE hContact = NULL; + + ::EnterCriticalSection(&this->contact_search_lock); + + for (hContact = ::db_find_first(this->m_szModuleName); hContact; hContact = ::db_find_next(hContact, this->m_szModuleName)) { if ( !this->IsChatRoom(hContact)) { mir_ptr contactSid( ::db_get_wsa(hContact, this->m_szModuleName, SKYPE_SETTINGS_LOGIN)); if (::lstrcmpi(contactSid, sid) == 0) - return hContact; + break; } } - return 0; + ::LeaveCriticalSection(&this->contact_search_lock); + + return hContact; } HANDLE CSkypeProto::GetContactFromAuthEvent(HANDLE hEvent) @@ -207,7 +213,8 @@ HANDLE CSkypeProto::AddContact(CContact::Ref contact) mir_ptr nick(::mir_utf8decodeW(contact->GetNick())); - switch(availability) { + switch(availability) + { case CContact::SKYPEOUT: ::db_set_b(hContact, this->m_szModuleName, "IsSkypeOut", 1); break; @@ -243,8 +250,6 @@ HANDLE CSkypeProto::AddContact(CContact::Ref contact) void __cdecl CSkypeProto::LoadContactList(void* data) { - ::EnterCriticalSection(&this->cl_loading); - this->Log(L"Updating contacts list"); bool isFirstLoad = data != NULL; @@ -282,8 +287,6 @@ void __cdecl CSkypeProto::LoadContactList(void* data) this->UpdateProfile(contact.fetch(), hContact); } } - - ::LeaveCriticalSection(&this->cl_loading); } void __cdecl CSkypeProto::LoadChatList(void*) @@ -341,11 +344,15 @@ bool CSkypeProto::IsContactOnline(HANDLE hContact) void CSkypeProto::SetAllContactStatus(int status) { + ::EnterCriticalSection(&this->contact_search_lock); + for (HANDLE hContact = ::db_find_first(this->m_szModuleName); hContact; hContact = ::db_find_next(hContact, this->m_szModuleName)) { if (::db_get_b(hContact, this->m_szModuleName, "IsSkypeOut", 0) == 0) ::db_set_w(hContact, this->m_szModuleName, SKYPE_SETTINGS_STATUS, status); } + + ::LeaveCriticalSection(&this->contact_search_lock); } void CSkypeProto::OnSearchCompleted(HANDLE hSearch) diff --git a/protocols/Skype/src/skype_events.cpp b/protocols/Skype/src/skype_events.cpp index a89729a46f..63f5bebb84 100644 --- a/protocols/Skype/src/skype_events.cpp +++ b/protocols/Skype/src/skype_events.cpp @@ -244,9 +244,8 @@ void CSkypeProto::OnChatMessageSent(CConversation::Ref &conversation, CMessage:: conversation->GetPropIdentity(data); mir_ptr cid( ::mir_utf8decodeW(data)); - mir_ptr nick( ::db_get_wsa(NULL, this->m_szModuleName, "Nick")); - if (::wcsicmp(nick, L"") == 0) - nick = ::db_get_wsa(NULL, this->m_szModuleName, SKYPE_SETTINGS_LOGIN); + message->GetPropAuthor(data); + mir_ptr sid( ::mir_utf8decodeW(data)); CMessage::TYPE messageType; message->GetPropType(messageType); @@ -254,7 +253,7 @@ void CSkypeProto::OnChatMessageSent(CConversation::Ref &conversation, CMessage:: //this->SendChatMessage(cid, nick, mir_ptr(::mir_utf8decodeW(text))); this->RaiseChatEvent( cid, - nick, + sid, messageType == CMessage::POSTED_TEXT ? /*GC_EVENT_MESSAGE */ 0x0040 : /*GC_EVENT_ACTION */ 0x0200, /*GCEF_ADDTOLOG*/ 0x0001, 0, diff --git a/protocols/Skype/src/skype_own_info.cpp b/protocols/Skype/src/skype_own_info.cpp index cc5fb4c123..5fed41ddad 100644 --- a/protocols/Skype/src/skype_own_info.cpp +++ b/protocols/Skype/src/skype_own_info.cpp @@ -8,6 +8,11 @@ void __cdecl CSkypeProto::LoadOwnInfo(void *) SEString data; this->account->GetPropFullname(data); + if (data.length() == 0) + { + this->account->GetPropSkypename(data); + } + nick = ::mir_utf8decodeW(data); ::db_set_ws(NULL, this->m_szModuleName, "Nick", nick); } diff --git a/protocols/Skype/src/skype_proto.cpp b/protocols/Skype/src/skype_proto.cpp index f0f074d596..db33037edc 100644 --- a/protocols/Skype/src/skype_proto.cpp +++ b/protocols/Skype/src/skype_proto.cpp @@ -6,7 +6,7 @@ CSkypeProto::CSkypeProto(const char* protoName, const TCHAR* userName) this->rememberPassword = false; - ::InitializeCriticalSection(&this->cl_loading); + ::InitializeCriticalSection(&this->contact_search_lock); this->SetAllContactStatus(ID_STATUS_OFFLINE); @@ -28,7 +28,7 @@ CSkypeProto::CSkypeProto(const char* protoName, const TCHAR* userName) CSkypeProto::~CSkypeProto() { - ::DeleteCriticalSection(&this->cl_loading); + ::DeleteCriticalSection(&this->contact_search_lock); ::mir_free(this->login); if (this->password) diff --git a/protocols/Skype/src/skype_proto.h b/protocols/Skype/src/skype_proto.h index 2268ecb4a8..88903af885 100644 --- a/protocols/Skype/src/skype_proto.h +++ b/protocols/Skype/src/skype_proto.h @@ -187,7 +187,7 @@ protected: CContactGroup::Ref commonList; CContactGroup::Ref authWaitList; - CRITICAL_SECTION cl_loading; + CRITICAL_SECTION contact_search_lock; static std::map languages; -- cgit v1.2.3