summaryrefslogtreecommitdiff
path: root/protocols/Skype/src/skype_chat.h
blob: 75fec78dcd29092a2c3b9b381895705e2d86726f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#pragma once

#include "skype.h"
#include <m_chat.h>

class ChatMember
{
public:
	wchar_t *sid;
	wchar_t *nick;
	int rank;
	WORD status;

	CParticipant::Ref participant;

	ChatMember()
	{
		this->sid = NULL;
		this->nick = NULL;
	}

	ChatMember(const wchar_t *sid)
	{
		this->sid = ::mir_wstrdup(sid);
		this->nick = NULL;
	}

	~ChatMember()
	{
		if (this->sid != NULL)
			::mir_free(this->sid);
		if (this->nick != NULL)
			::mir_free(this->nick);
	}

	bool operator==(const ChatMember &other) const
	{
		return ::lstrcmp(this->sid, other.sid) == 0;
	}
	
	bool operator!=(const ChatMember &other) const
	{
		return !(*this == other);
	}

	ChatMember& operator=(const ChatMember& right)
	{
        if (this == &right)
            return *this;

		::mir_free(this->sid);
		::mir_free(this->nick);
		this->sid = ::mir_wstrdup(right.sid);
		this->nick = ::mir_wstrdup(right.nick);
		this->rank = right.rank;
		this->status = right.status;
        return *this;
	}
};

class ChatRoom
{
private:
	wchar_t *cid;
	wchar_t *name;

	HANDLE hContact;

	ChatMember *me;

	LIST<ChatMember> members;

	CSkypeProto *ppro;

	static wchar_t *Roles[];

	ChatRoom(const wchar_t *cid);

	HANDLE AddChatRoom();

	inline static int CompareMembers(const ChatMember *p1, const ChatMember *p2) { return ::lstrcmpi(p1->sid, p2->sid); }

	void AddMember(ChatMember *member, DWORD timestamp, int flag);

public:
	CConversation::Ref conversation;

	ChatRoom(const wchar_t *cid, const wchar_t *name, CSkypeProto *ppro);
	~ChatRoom();	

	void Start(bool showWindow = false);
	void Start(const ParticipantRefs &participants, bool showWindow = false);

	void LeaveChat();

	void SendEvent(ChatMember *member, int eventType, DWORD timestamp = time(NULL), DWORD flags = GCEF_ADDTOLOG, DWORD itemData = 0, const wchar_t *status = NULL, const wchar_t *message = NULL);
	void SendEvent(const wchar_t *sid, int eventType, DWORD timestamp = time(NULL), DWORD flags = GCEF_ADDTOLOG, DWORD itemData = 0, const wchar_t *status = NULL, const wchar_t *message = NULL);

	bool IsMe(const wchar_t *sid) const;
	bool IsMe(ChatMember *member) const;

	ChatMember *FindChatMember(ChatMember *item);
	ChatMember *FindChatMember(const wchar_t *sid);

	void AddMember(ChatMember *member, DWORD timestamp);
	void AddMember(ChatMember *member);

	void UpdateMember(const wchar_t *sid, const wchar_t *nick, int rank, int status, DWORD timestamp = time(NULL), DWORD flags = GCEF_ADDTOLOG);

	void KickMember(ChatMember *member, const ChatMember *kicker, DWORD timestamp = time(NULL));
	void KickMember(const wchar_t *sid, const wchar_t *kicker, DWORD timestamp = time(NULL));

	void RemoveMember(ChatMember *member, DWORD timestamp = time(NULL));
	void RemoveMember(const wchar_t *sid, DWORD timestamp = time(NULL));

	void OnEvent(const ConversationRef &conversation, const MessageRef &message);

	static int __cdecl OnGCEventHook(WPARAM, LPARAM lParam);
	static int __cdecl OnGCMenuHook(WPARAM, LPARAM lParam);
};