diff options
author | George Hazan <george.hazan@gmail.com> | 2015-02-06 23:36:02 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-02-06 23:36:02 +0000 |
commit | b2f86045d3b3dc2a454f127f186429b60e493072 (patch) | |
tree | f56c5696ef3ebf62b1a97e4abbfcbc332adbbd28 /protocols/WhatsApp/src/proto.h | |
parent | 8c6ce1ceb218db86d059372e18277c16b1ab20cb (diff) |
merge from branch
git-svn-id: http://svn.miranda-ng.org/main/trunk@12029 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/WhatsApp/src/proto.h')
-rw-r--r-- | protocols/WhatsApp/src/proto.h | 177 |
1 files changed, 89 insertions, 88 deletions
diff --git a/protocols/WhatsApp/src/proto.h b/protocols/WhatsApp/src/proto.h index b0c5c8a6bf..b07d8aed87 100644 --- a/protocols/WhatsApp/src/proto.h +++ b/protocols/WhatsApp/src/proto.h @@ -3,11 +3,28 @@ class WASocketConnection;
+#include "WhatsAPI++/WAConnection.h"
+
+struct WAChatInfo
+{
+ WAChatInfo(TCHAR *_jid, TCHAR *_nick) :
+ tszJid(_jid), tszNick(_nick)
+ {
+ bActive = false;
+ }
+
+ map<std::string, std::tstring> m_unsentMsgs;
+ ptrT tszJid, tszNick, tszOwner;
+ bool bActive;
+
+ MCONTACT hContact;
+};
+
class WhatsAppProto : public PROTO<WhatsAppProto>, public WAListener, public WAGroupListener
{
public:
WhatsAppProto(const char *proto_name, const TCHAR *username);
- ~WhatsAppProto( );
+ ~WhatsAppProto();
inline bool isOnline() const
{ return (m_pConnection != NULL);
@@ -21,20 +38,20 @@ public: { return (m_iStatus == ID_STATUS_INVISIBLE);
}
- // PROTO_INTERFACE
+ // PROTO_INTERFACE ///////////////////////////////////////////////////////////////////
- virtual MCONTACT __cdecl AddToList(int flags, PROTOSEARCHRESULT* psr);
- virtual MCONTACT __cdecl AddToListByEvent(int flags, int iContact, MEVENT hDbEvent) { return NULL; }
+ virtual MCONTACT __cdecl AddToList(int flags, PROTOSEARCHRESULT* psr);
+ virtual MCONTACT __cdecl AddToListByEvent(int flags, int iContact, MEVENT hDbEvent) { return NULL; }
- virtual int __cdecl Authorize(MEVENT hDbEvent);
- virtual int __cdecl AuthDeny(MEVENT hDbEvent, const PROTOCHAR* szReason) { return 1; }
- virtual int __cdecl AuthRecv(MCONTACT hContact, PROTORECVEVENT*) { return 1; }
- virtual int __cdecl AuthRequest(MCONTACT hContact, const PROTOCHAR* szMessage);
+ virtual int __cdecl Authorize(MEVENT hDbEvent);
+ virtual int __cdecl AuthDeny(MEVENT hDbEvent, const PROTOCHAR* szReason) { return 1; }
+ virtual int __cdecl AuthRecv(MCONTACT hContact, PROTORECVEVENT*) { return 1; }
+ virtual int __cdecl AuthRequest(MCONTACT hContact, const PROTOCHAR* szMessage);
- virtual HANDLE __cdecl FileAllow(MCONTACT hContact, HANDLE hTransfer, const PROTOCHAR* szPath) { return NULL; }
- virtual int __cdecl FileCancel(MCONTACT hContact, HANDLE hTransfer) { return 1; }
- virtual int __cdecl FileDeny(MCONTACT hContact, HANDLE hTransfer, const PROTOCHAR* szReason) { return 1; }
- virtual int __cdecl FileResume(HANDLE hTransfer, int* action, const PROTOCHAR** szFilename) { return 1; }
+ virtual HANDLE __cdecl FileAllow(MCONTACT hContact, HANDLE hTransfer, const PROTOCHAR* szPath) { return NULL; }
+ virtual int __cdecl FileCancel(MCONTACT hContact, HANDLE hTransfer) { return 1; }
+ virtual int __cdecl FileDeny(MCONTACT hContact, HANDLE hTransfer, const PROTOCHAR* szReason) { return 1; }
+ virtual int __cdecl FileResume(HANDLE hTransfer, int* action, const PROTOCHAR** szFilename) { return 1; }
virtual DWORD_PTR __cdecl GetCaps(int type, MCONTACT hContact = NULL);
virtual int __cdecl GetInfo(MCONTACT hContact, int infoType) { return 1; }
@@ -65,86 +82,76 @@ public: virtual int __cdecl UserIsTyping(MCONTACT hContact, int type);
- virtual int __cdecl OnEvent(PROTOEVENTTYPE iEventType, WPARAM wParam, LPARAM lParam) { return 1; }
+ virtual int __cdecl OnEvent(PROTOEVENTTYPE iEventType, WPARAM wParam, LPARAM lParam);
- //////////////////////////////////////////////////////////////////////////////////////
- // Services
+ // Services //////////////////////////////////////////////////////////////////////////
INT_PTR __cdecl SvcCreateAccMgrUI(WPARAM, LPARAM);
- INT_PTR __cdecl OnJoinChat(WPARAM, LPARAM);
- INT_PTR __cdecl OnLeaveChat(WPARAM, LPARAM);
- INT_PTR __cdecl OnCreateGroup(WPARAM, LPARAM);
- //////////////////////////////////////////////////////////////////////////////////////
- // Events
+ // Events ////////////////////////////////////////////////////////////////////////////
int __cdecl OnOptionsInit(WPARAM, LPARAM);
- int __cdecl OnModulesLoaded(WPARAM, LPARAM);
int __cdecl OnBuildStatusMenu(WPARAM, LPARAM);
- int __cdecl OnChatOutgoing(WPARAM, LPARAM);
- int __cdecl OnPrebuildContactMenu(WPARAM, LPARAM);
- INT_PTR __cdecl OnAddContactToGroup(WPARAM, LPARAM, LPARAM);
- INT_PTR __cdecl OnRemoveContactFromGroup(WPARAM, LPARAM, LPARAM);
- INT_PTR __cdecl OnChangeGroupSubject(WPARAM, LPARAM);
- INT_PTR __cdecl OnLeaveGroup(WPARAM, LPARAM);
+ // Worker Threads ////////////////////////////////////////////////////////////////////
- // Loops
- bool NegotiateConnection();
void __cdecl stayConnectedLoop(void*);
void __cdecl sentinelLoop(void*);
- //////////////////////////////////////////////////////////////////////////////////////
- // Processing Threads
+ // Processing Threads ////////////////////////////////////////////////////////////////
void __cdecl ProcessBuddyList(void*);
void __cdecl SearchAckThread(void*);
- //////////////////////////////////////////////////////////////////////////////////////
- // Worker Threads
-
- void __cdecl SendGetGroupInfoWorker(void*);
- void __cdecl SendSetGroupNameWorker(void*);
- void __cdecl SendCreateGroupWorker(void*);
+ // Contacts handling /////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////////////////
- // Contacts handling
+ MCONTACT AddToContactList(const std::string &jid, const char *new_name = NULL);
- MCONTACT AddToContactList(const std::string &jid, BYTE type = 0, bool dont_check = false,
- const char *new_name = NULL, bool isChatRoom = false, bool isHidden = false);
-
- bool IsMyContact(MCONTACT hContact, bool include_chat = false);
MCONTACT ContactIDToHContact(const std::string&);
void SetAllContactStatuses(int status, bool reset_client = false);
void UpdateStatusMsg(MCONTACT hContact);
TCHAR* GetContactDisplayName(const string &jid);
- void InitContactMenus();
- void HandleReceiveGroups(const std::vector<string> &groups, bool isOwned);
void RequestFriendship(MCONTACT hContact);
- bool IsGroupChat(MCONTACT hC, bool checkIsAdmin = false)
- {
- return getByte(hC, "SimpleChatRoom", 0) > (checkIsAdmin ? 1 : 0);
- }
+ // Group chats ///////////////////////////////////////////////////////////////////////
+
+ std::vector<string> m_szInviteJids;
+ map<std::string, WAChatInfo*> m_chats;
+ mir_cs m_csChats;
+
+ void ChatLogMenuHook(WAChatInfo *pInfo, GCHOOK *gch);
+ void NickListMenuHook(WAChatInfo *pInfo, GCHOOK *gch);
+
+ void AddChatUser(WAChatInfo *pInfo, const TCHAR *ptszJid);
+ void EditChatSubject(WAChatInfo *pInfo);
+ void InviteChatUser(WAChatInfo *pInfo);
+ void KickChatUser(WAChatInfo *pInfo, const TCHAR *ptszJid);
+ TCHAR* GetChatUserNick(const std::string &jid);
+
+ void onGroupMessageReceived(const FMessage &fmsg);
- LONG GetSerial();
+ WAChatInfo* InitChat(const std::string &jidjid, const std::string &nick);
+ WAChatInfo* SafeGetChat(const std::string &jid);
- //////////////////////////////////////////////////////////////////////////////////////
- // Registration
+ int __cdecl onGroupChatEvent(WPARAM, LPARAM);
+ int __cdecl OnChatMenu(WPARAM, LPARAM);
+ INT_PTR __cdecl OnCreateGroup(WPARAM, LPARAM);
+
+ // Registration //////////////////////////////////////////////////////////////////////
bool Register(int state, const string &cc, const string &number, const string &code, string &password);
private:
-
- //////////////////////////////////////////////////////////////////////////////////////
- // Helpers
+ // Helpers //////////////////////////////////////////////////////////////////////////
LONG m_iSerial;
+ __forceinline LONG GetSerial()
+ { return ::_InterlockedIncrement(&m_iSerial);
+ }
void ToggleStatusMenuItems(BOOL bEnable);
- //////////////////////////////////////////////////////////////////////////////////////
- // Avatars
+ /// Avatars //////////////////////////////////////////////////////////////////////////
std::tstring GetAvatarFileName(MCONTACT);
std::tstring m_tszAvatarFolder;
@@ -154,14 +161,11 @@ private: INT_PTR __cdecl GetMyAvatar(WPARAM, LPARAM);
INT_PTR __cdecl SetMyAvatar(WPARAM, LPARAM);
- //////////////////////////////////////////////////////////////////////////////////////
- // Handles, Locks
-
+ // Private data //////////////////////////////////////////////////////////////////////
+
HGENMENU m_hMenuRoot;
HANDLE m_hMenuCreateGroup;
- HANDLE signon_lock_;
- HANDLE log_lock_;
HANDLE update_loop_lock_;
WASocketConnection *conn;
@@ -170,18 +174,16 @@ private: time_t m_tLastWriteTime;
std::vector<unsigned char> m_Challenge;
- string m_szPhoneNumber;
- string m_szJid, m_szNick;
+ std::string m_szPhoneNumber;
+ std::string m_szJid, m_szNick;
std::map<string, MCONTACT> hContactByJid;
map<MCONTACT, map<MCONTACT, bool>> isMemberByGroupContact;
- //////////////////////////////////////////////////////////////////////////////////////
- // WhatsApp Events
-
protected:
- virtual void onMessageForMe(FMessage *paramFMessage, bool paramBoolean);
- virtual void onMessageStatusUpdate(FMessage *paramFMessage);
- virtual void onMessageError(FMessage *message, int paramInt) { ; }
+ // WAListener methods ////////////////////////////////////////////////////////////////
+ virtual void onMessageForMe(const FMessage ¶mFMessage);
+ virtual void onMessageStatusUpdate(const FMessage ¶mFMessage);
+ virtual void onMessageError(const FMessage &message, int paramInt) { ; }
virtual void onPing(const std::string &id) throw (WAException);
virtual void onPingResponseReceived() { }
virtual void onAvailable(const std::string ¶mString, bool paramBoolean);
@@ -195,29 +197,28 @@ protected: virtual void onDirtyResponse(int paramHashtable) { }
virtual void onRelayRequest(const std::string ¶mString1, int paramInt, const std::string ¶mString2) { }
virtual void onSendGetPicture(const std::string &jid, const std::vector<unsigned char>& data, const std::string &id);
- virtual void onPictureChanged(const std::string &from, const std::string &author, bool set);
- virtual void onDeleteAccount(bool result) { }
-
- virtual void onGroupAddUser(const std::string ¶mString1, const std::string ¶mString2);
- virtual void onGroupRemoveUser(const std::string ¶mString1, const std::string ¶mString2);
- virtual void onGroupNewSubject(const std::string &from, const std::string &author, const std::string &newSubject, int paramInt);
- virtual void onServerProperties(std::map<std::string, std::string>* nameValueMap) { }
- virtual void onGroupCreated(const std::string ¶mString1, const std::string ¶mString2);
- virtual void onGroupInfo(const std::string ¶mString1, const std::string ¶mString2, const std::string ¶mString3, const std::string ¶mString4, int paramInt1, int paramInt2);
- virtual void onGroupInfoFromList(const std::string ¶mString1, const std::string ¶mString2, const std::string ¶mString3, const std::string ¶mString4, int paramInt1, int paramInt2);
- virtual void onOwningGroups(const std::vector<string>& paramVector);
+ virtual void onPictureChanged(const std::string &jid, const std::string &id, bool set);
+ virtual void onContactChanged(const std::string &jid, bool added);
+ virtual void onDeleteAccount(bool result) {}
+
+ // WAGroupListener methods ///////////////////////////////////////////////////////////
+ virtual void onGroupAddUser(const std::string &gjid, const std::string &ujid, int ts);
+ virtual void onGroupRemoveUser(const std::string &gjid, const std::string &ujid, int ts);
+ virtual void onGroupNewSubject(const std::string &from, const std::string &author, const std::string &newSubject, int ts);
+ virtual void onGroupMessage(const FMessage ¶mFMessage);
+ virtual void onServerProperties(std::map<std::string, std::string>* nameValueMap) {}
+ virtual void onGroupCreated(const std::string &gjid, const std::string &nick);
+ virtual void onGroupInfo(const std::string &jid, const std::string &owner, const std::string &subject, const std::string &subject_owner, int time_subject, int time_created);
virtual void onSetSubject(const std::string ¶mString) { }
- virtual void onAddGroupParticipants(const std::string ¶mString, const std::vector<string>& paramVector, int paramHashtable) { }
- virtual void onRemoveGroupParticipants(const std::string ¶mString, const std::vector<string>& paramVector, int paramHashtable) { }
- virtual void onGetParticipants(const std::string &gjid, const std::vector<string>& participants);
- virtual void onParticipatingGroups(const std::vector<string>& paramVector);
+ virtual void onAddGroupParticipants(const std::string ¶mString, const std::vector<string> ¶mVector, int paramHashtable) { }
+ virtual void onRemoveGroupParticipants(const std::string ¶mString, const std::vector<string> ¶mVector, int paramHashtable) { }
+ virtual void onGetParticipants(const std::string &gjid, const std::vector<string> &participants);
virtual void onLeaveGroup(const std::string ¶mString);
- //////////////////////////////////////////////////////////////////////////////////////
- // Information providing
+ // Information providing /////////////////////////////////////////////////////////////
void NotifyEvent(const TCHAR *title, const TCHAR *info, MCONTACT contact, DWORD flags, TCHAR *url = NULL);
void NotifyEvent(const std::string &title, const std::string &info, MCONTACT contact, DWORD flags, TCHAR *url = NULL);
};
-#endif
\ No newline at end of file +#endif
|