From 2ae148d3b9040ab734642ea0bc798bede8a06dfa Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Sun, 16 Dec 2012 13:16:42 +0000 Subject: - refactored message receiving git-svn-id: http://svn.miranda-ng.org/main/trunk@2751 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Skype/src/skype_proto.cpp | 30 +++++++++++--- protocols/Skype/src/skype_proto.h | 2 +- protocols/Skype/src/skype_subclassing.cpp | 69 ++++++++++++++++++++----------- protocols/Skype/src/skype_subclassing.h | 24 ++++++++++- 4 files changed, 92 insertions(+), 33 deletions(-) (limited to 'protocols') diff --git a/protocols/Skype/src/skype_proto.cpp b/protocols/Skype/src/skype_proto.cpp index 5d2d8b0bba..f325c549a0 100644 --- a/protocols/Skype/src/skype_proto.cpp +++ b/protocols/Skype/src/skype_proto.cpp @@ -345,14 +345,18 @@ int __cdecl CSkypeProto::OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPA void __cdecl CSkypeProto::SignInAsync(void*) { - g_skype->GetConversationList(g_skype->inbox, CConversation::INBOX_CONVERSATIONS); + /*g_skype->GetConversationList(g_skype->inbox, CConversation::INBOX_CONVERSATIONS); fetch(g_skype->inbox); g_skype->SetOnConversationAddedCallback( (CSkype::OnConversationAdded)&CSkypeProto::OnConversationAdded, this); for (uint i = 0 ; i < g_skype->inbox.size(); i++) g_skype->inbox[i]->SetOnMessageReceivedCallback( - (CConversation::OnMessageReceived)&CSkypeProto::OnOnMessageReceived, + (CConversation::OnMessageReceived)&CSkypeProto::OnMessageReceived, + this);*/ + + g_skype->SetOnMessageReceivedCallback( + (CSkype::OnMessageReceived)&CSkypeProto::OnMessageReceived, this); this->SetStatus(this->m_iDesiredStatus); @@ -403,13 +407,27 @@ void CSkypeProto::RequestPassword() LPARAM(this)); } -void CSkypeProto::OnOnMessageReceived(const char *sid, const char *text) +void CSkypeProto::OnMessageReceived(CMessage::Ref message) { - this->RaiseMessageReceivedEvent(time(NULL), sid, sid, text); + SEIntList propIds; + SEIntDict propValues; + propIds.append(CMessage::P_AUTHOR); + propIds.append(CMessage::P_AUTHOR_DISPLAYNAME); + propIds.append(CMessage::P_BODY_XML); + propValues = message->GetProps(propIds); + + uint timestamp; + message->GetPropTimestamp(timestamp); + + this->RaiseMessageReceivedEvent( + (DWORD)timestamp, + (const char*)propValues[0], + (const char*)propValues[1], + (const char*)propValues[2]); } void CSkypeProto::OnConversationAdded(CConversation::Ref conversation) { - conversation->SetOnMessageReceivedCallback( - (CConversation::OnMessageReceived)&CSkypeProto::OnOnMessageReceived, this); + //conversation->SetOnMessageReceivedCallback( + // (CConversation::OnMessageReceived)&CSkypeProto::OnMessageReceived, this); } \ No newline at end of file diff --git a/protocols/Skype/src/skype_proto.h b/protocols/Skype/src/skype_proto.h index edae4c6acc..3e17a5d906 100644 --- a/protocols/Skype/src/skype_proto.h +++ b/protocols/Skype/src/skype_proto.h @@ -170,7 +170,7 @@ protected: static LanguagesListEntry languages[223]; // messages - void OnOnMessageReceived(const char *sid, const char *text); + void OnMessageReceived(CMessage::Ref message); void OnConversationAdded(CConversation::Ref conversation); // contacts diff --git a/protocols/Skype/src/skype_subclassing.cpp b/protocols/Skype/src/skype_subclassing.cpp index e6b6ec6d34..4ae99d087a 100644 --- a/protocols/Skype/src/skype_subclassing.cpp +++ b/protocols/Skype/src/skype_subclassing.cpp @@ -5,7 +5,8 @@ CSkype::CSkype(int num_threads) : Skype(num_threads) { this->proto = NULL; - this->callback == NULL; + this->onMessageReceivedCallback = NULL; + this->onConversationAddedCallback = NULL; } CAccount* CSkype::newAccount(int oid) @@ -28,11 +29,45 @@ CConversation* CSkype::newConversation(int oid) return new CConversation(oid, this); } +CMessage* CSkype::newMessage(int oid) +{ + return new CMessage(oid, this); +} + CContactSearch* CSkype::newContactSearch(int oid) { return new CContactSearch(oid, this); } +void CSkype::OnMessage ( + const MessageRef & message, + const bool & changesInboxTimestamp, + const MessageRef & supersedesHistoryMessage, + const ConversationRef & conversation) +{ + /*uint now; + skype->GetUnixTimestamp(now); + conversation->SetConsumedHorizon(now);*/ + + Message::TYPE messageType; + message->GetPropType(messageType); + + Message::SENDING_STATUS sendingStatus; + message->GetPropSendingStatus(sendingStatus); + + if (messageType == Message::POSTED_TEXT && !sendingStatus) + { + if (this->proto) + (proto->*onMessageReceivedCallback)(message->ref()); + } +} + +void CSkype::SetOnMessageReceivedCallback(OnMessageReceived callback, CSkypeProto* proto) +{ + this->proto = proto; + this->onMessageReceivedCallback = callback; +} + void CSkype::OnConversationListChange( const ConversationRef &conversation, const Conversation::LIST_TYPE &type, @@ -43,14 +78,14 @@ void CSkype::OnConversationListChange( conversation.fetch(); inbox.append(conversation); if (this->proto) - (proto->*callback)(conversation->ref()); + (proto->*onConversationAddedCallback)(conversation->ref()); } } void CSkype::SetOnConversationAddedCallback(OnConversationAdded callback, CSkypeProto* proto) { this->proto = proto; - this->callback = callback; + this->onConversationAddedCallback = callback; } // CAccount @@ -186,30 +221,16 @@ CConversation::CConversation(unsigned int oid, SERootObject* root) : Conversatio void CConversation::OnMessage(const MessageRef & message) { - Message::TYPE messageType; - message->GetPropType(messageType); - - Message::SENDING_STATUS sendingStatus; - message->GetPropSendingStatus(sendingStatus); - - if (messageType == Message::POSTED_TEXT && !sendingStatus) - { - SEIntList propIds; - SEIntDict propValues; - propIds.append(Message::P_AUTHOR); - propIds.append(Message::P_BODY_XML); - propValues = message->GetProps(propIds); - - //if (propValues[0] != myAccountName) - { - if (this->proto) - (proto->*callback)((const char*)propValues[0], (const char*)propValues[1]); - } - } + if (this->proto) + (proto->*callback)(message->ref()); } void CConversation::SetOnMessageReceivedCallback(OnMessageReceived callback, CSkypeProto* proto) { this->proto = proto; this->callback = callback; -} \ No newline at end of file +} + +// CMessage + +CMessage::CMessage(unsigned int oid, SERootObject* root) : Message(oid, root) { } \ No newline at end of file diff --git a/protocols/Skype/src/skype_subclassing.h b/protocols/Skype/src/skype_subclassing.h index 7f7b7dfd32..0840c57dc3 100644 --- a/protocols/Skype/src/skype_subclassing.h +++ b/protocols/Skype/src/skype_subclassing.h @@ -7,10 +7,20 @@ struct CSkypeProto; +class CMessage : public Message +{ +public: + + typedef DRef Ref; + typedef DRefs Refs; + + CMessage(unsigned int oid, SERootObject* root); +}; + class CConversation : public Conversation { public: - typedef void (CSkypeProto::* OnMessageReceived)(const char *sid, const char *text); + typedef void (CSkypeProto::* OnMessageReceived)(CMessage::Ref message); typedef DRef Ref; typedef DRefs Refs; @@ -115,6 +125,7 @@ private: class CSkype : public Skype { public: + typedef void (CSkypeProto::* OnMessageReceived)(CMessage::Ref message); typedef void (CSkypeProto::* OnConversationAdded)(CConversation::Ref conversation); CAccount* newAccount(int oid); @@ -122,16 +133,25 @@ public: CConversation* newConversation(int oid); CContactSearch* newContactSearch(int oid); CContact* newContact(int oid); + CMessage* newMessage(int oid); CConversation::Refs inbox; CSkype(int num_threads = 1); + void SetOnMessageReceivedCallback(OnMessageReceived callback, CSkypeProto* proto); void SetOnConversationAddedCallback(OnConversationAdded callback, CSkypeProto* proto); private: CSkypeProto* proto; - OnConversationAdded callback; + OnMessageReceived onMessageReceivedCallback; + OnConversationAdded onConversationAddedCallback; + + void OnMessage( + const MessageRef & message, + const bool & changesInboxTimestamp, + const MessageRef & supersedesHistoryMessage, + const ConversationRef & conversation); void OnConversationListChange( const ConversationRef &conversation, -- cgit v1.2.3