From 9f53b4ab59d8183b9064ac65ab46a87932b5cf34 Mon Sep 17 00:00:00 2001
From: Alexander Lantsev <aunsane@gmail.com>
Date: Fri, 7 Jun 2013 09:24:01 +0000
Subject: Skype: - fixed encoding in name of received files - some chat
 improvements

git-svn-id: http://svn.miranda-ng.org/main/trunk@4890 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
---
 protocols/Skype/src/skype_chat.cpp  | 109 ++++++++++++++++++++++++------------
 protocols/Skype/src/skype_chat.h    |   6 +-
 protocols/Skype/src/skype_proto.cpp |   2 +-
 protocols/Skype/src/skype_proto.h   |   2 -
 4 files changed, 78 insertions(+), 41 deletions(-)

(limited to 'protocols')

diff --git a/protocols/Skype/src/skype_chat.cpp b/protocols/Skype/src/skype_chat.cpp
index 6a032ab25c..370bb3b982 100644
--- a/protocols/Skype/src/skype_chat.cpp
+++ b/protocols/Skype/src/skype_chat.cpp
@@ -139,11 +139,13 @@ void ChatRoom::Start(const ParticipantRefs &participants, bool showWindow)
 
 	for (uint i = 0; i < participants.size(); i++)
 	{
-		participants[i]->GetPropIdentity(data);
+		auto participant = participants[i];
+
+		participant->GetPropIdentity(data);
 		ptrW sid = ::mir_utf8decodeW(data);
 
 		ChatMember *member = new ChatMember(sid);
-		member->rank = participants[i]->GetUintProp(Participant::P_RANK);
+		member->rank = participant->GetUintProp(Participant::P_RANK);
 				
 		Contact::Ref contact;
 		this->ppro->GetContact(data, contact);
@@ -158,6 +160,8 @@ void ChatRoom::Start(const ParticipantRefs &participants, bool showWindow)
 		else
 			member->nick = ::mir_wstrdup(sid);
 
+		member->participant = participant;
+		member->participant.fetch();
 		this->AddMember(member);
 	}
 }
@@ -371,46 +375,73 @@ void ChatRoom::OnEvent(const ConversationRef &conversation, const MessageRef &me
 				uint timestamp;
 				message->GetPropTimestamp(timestamp);
 
-				message->GetPropIdentities(data);
-				char *identities = ::mir_strdup(data);
-				if (identities)
-				{
-					char *identity = ::strtok(identities, " ");
-					if (identity != NULL)
-					{
-						do
-						{
-							Contact::Ref contact;
-							this->ppro->GetContact(identity, contact);
-
-							contact->GetIdentity(data);
-							ptrW sid = ::mir_utf8decodeW(data);
+				ParticipantRefs participants;
+				conversation->GetParticipants(participants);
 
-							ChatMember *member = new ChatMember(sid);
-							//todo: fix rank
-							
-							member->rank = 
-								messageType == Message::ADDED_APPLICANTS ? 
-								Participant::APPLICANT : 
-								Participant::SPEAKER;
-								//conversation->GetUintProp(Conversation::P_OPT_ENTRY_LEVEL_RANK);
-								//participants[i]->GetUintProp(Participant::P_RANK);
+				for (size_t i = 0; i < participants.size(); i++)
+				{					
+					participants[i]->GetPropIdentity(data);
+					ptrW sid(::mir_utf8decodeW(data));
+					if (this->FindChatMember(sid) == NULL)
+					{
+						ChatMember *member = new ChatMember(sid);
+						member->rank = participants[i]->GetUintProp(Participant::P_RANK);
 
-							Contact::AVAILABILITY status;
-							contact->GetPropAvailability(status);
-							member->status = CSkypeProto::SkypeToMirandaStatus(status);
+						Contact::Ref contact;
+						this->ppro->GetContact(data, contact);
 
-							contact->GetPropFullname(data);
-							member->nick = ::mir_utf8decodeW(data);
+						Contact::AVAILABILITY status;
+						contact->GetPropAvailability(status);
+						member->status = CSkypeProto::SkypeToMirandaStatus(status);
 
-							this->AddMember(member, timestamp);
+						contact->GetPropFullname(data);
+						member->nick = ::mir_utf8decodeW(data);
 
-							identity = ::strtok(NULL, " ");
-						}
-						while (identity != NULL);
+						this->AddMember(member);
 					}
-					::mir_free(identities);
 				}
+
+				// do not remove
+				//message->GetPropIdentities(data);
+				//char *identities = ::mir_strdup(data);
+				//if (identities)
+				//{
+				//	char *identity = ::strtok(identities, " ");
+				//	if (identity != NULL)
+				//	{
+				//		do
+				//		{
+				//			Contact::Ref contact;
+				//			this->ppro->GetContact(identity, contact);
+
+				//			contact->GetIdentity(data);
+				//			ptrW sid = ::mir_utf8decodeW(data);
+
+				//			ChatMember *member = new ChatMember(sid);
+				//			//todo: fix rank
+				//			
+				//			member->rank = 
+				//				messageType == Message::ADDED_APPLICANTS ? 
+				//				Participant::APPLICANT : 
+				//				Participant::SPEAKER;
+				//				//conversation->GetUintProp(Conversation::P_OPT_ENTRY_LEVEL_RANK);
+				//				//participants[i]->GetUintProp(Participant::P_RANK);
+
+				//			Contact::AVAILABILITY status;
+				//			contact->GetPropAvailability(status);
+				//			member->status = CSkypeProto::SkypeToMirandaStatus(status);
+
+				//			contact->GetPropFullname(data);
+				//			member->nick = ::mir_utf8decodeW(data);
+
+				//			this->AddMember(member, timestamp);
+
+				//			identity = ::strtok(NULL, " ");
+				//		}
+				//		while (identity != NULL);
+				//	}
+				//	::mir_free(identities);
+				//}
 			}
 		}
 		break;
@@ -825,6 +856,7 @@ INT_PTR __cdecl CSkypeProto::OnJoinChat(WPARAM wParam, LPARAM)
 		ptrW name = ::mir_utf8decodeW(data);
 
 		ChatRoom *room = new ChatRoom(cid, name, this);
+		room->conversation = conversation;
 
 		Participant::Refs participants;
 		conversation->GetParticipants(participants, Conversation::ALL);
@@ -1072,6 +1104,8 @@ void __cdecl CSkypeProto::LoadChatList(void*)
 				ptrW name = ::mir_utf8decodeW(data);
 
 				ChatRoom *room = new ChatRoom(cid, name, this);
+				room->conversation = conversation;
+				//room->conversation.fetch();
 				this->AddChatRoom(conversation);
 
 				Participant::Refs participants;
@@ -1115,13 +1149,14 @@ void CSkypeProto::OnChatEvent(const ConversationRef &conversation, const Message
 		ptrW name = ::mir_utf8decodeW(data);
 
 		ChatRoom *room = new ChatRoom(cid, name, this);
+		room->conversation = conversation;
+		//room->conversation.fetch();
 		this->AddChatRoom(conversation);
 
 		Participant::Refs participants;
 		conversation->GetParticipants(participants, Conversation::ALL);
 				
 		room->Start(participants, true);
-		conversation.fetch();
 	}
 }
 
@@ -1142,6 +1177,8 @@ void CSkypeProto::OnConversationListChange(
 		ptrW name = ::mir_utf8decodeW(data);
 
 		ChatRoom *room = new ChatRoom(cid, name, this);
+		room->conversation = conversation;
+		//room->conversation.fetch();
 		this->AddChatRoom(conversation);
 
 		Participant::Refs participants;
diff --git a/protocols/Skype/src/skype_chat.h b/protocols/Skype/src/skype_chat.h
index 134823e343..75fec78dcd 100644
--- a/protocols/Skype/src/skype_chat.h
+++ b/protocols/Skype/src/skype_chat.h
@@ -11,6 +11,8 @@ public:
 	int rank;
 	WORD status;
 
+	CParticipant::Ref participant;
+
 	ChatMember()
 	{
 		this->sid = NULL;
@@ -58,8 +60,6 @@ public:
 
 class ChatRoom
 {
-	friend class ChatList;
-
 private:
 	wchar_t *cid;
 	wchar_t *name;
@@ -83,6 +83,8 @@ private:
 	void AddMember(ChatMember *member, DWORD timestamp, int flag);
 
 public:
+	CConversation::Ref conversation;
+
 	ChatRoom(const wchar_t *cid, const wchar_t *name, CSkypeProto *ppro);
 	~ChatRoom();	
 
diff --git a/protocols/Skype/src/skype_proto.cpp b/protocols/Skype/src/skype_proto.cpp
index fad767da3e..a717c8948e 100644
--- a/protocols/Skype/src/skype_proto.cpp
+++ b/protocols/Skype/src/skype_proto.cpp
@@ -163,7 +163,7 @@ HANDLE __cdecl CSkypeProto::FileAllow( HANDLE hContact, HANDLE hTransfer, const
 		transfers[i]->GetPropFilename(data);
 		ptrW name(::mir_utf8decodeW(data));
 		::mir_sntprintf(fullPath, MAX_PATH, L"%s%s", szPath, name);
-		if (!transfers[i]->Accept(::mir_u2a(fullPath), success) || !success)
+		if (!transfers[i]->Accept((char *)ptrA(::mir_utf8encodeW(fullPath)), success) || !success)
 		{
 			return 0;
 		}
diff --git a/protocols/Skype/src/skype_proto.h b/protocols/Skype/src/skype_proto.h
index 487cd925dd..9ddf7238fe 100644
--- a/protocols/Skype/src/skype_proto.h
+++ b/protocols/Skype/src/skype_proto.h
@@ -84,12 +84,10 @@ struct PasswordChangeBoxParam
 
 class ChatMember;
 class ChatRoom;
-class ChatList;
 
 struct CSkypeProto : public PROTO_INTERFACE, private Skype
 {
 	friend class ChatRoom;
-	friend class ChatList;
 
 public:
 	// PROTO_INTERFACE
-- 
cgit v1.2.3