summaryrefslogtreecommitdiff
path: root/protocols/Skype/src/skype_chat.h
blob: d070cb0b4481319e30a35414246102b8060ae028 (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#pragma once

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

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

public:
	CParticipant::Ref participant;

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

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

	ChatMember(const ChatMember &other)
	{
		this->sid = NULL;
		this->nick = NULL;
		this->operator=(other);
	}

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

	void SetNick(const wchar_t *nick)
	{
		if (this->nick != NULL)
			::mir_free(this->nick);
		this->nick = ::mir_wstrdup(nick);
	}

	wchar_t *GetSid() const
	{
		return this->sid;
	}

	wchar_t *GetNick() const
	{
		if (this->nick == NULL)
			return this->sid;

		return this->nick;
	}

	void SetRank(int rank)
	{
		this->rank = rank;
	}

	int GetRank() const
	{
		return this->rank;
	}

	void SetStatus(int status)
	{
		this->status = status;
	}

	int GetStatus() const
	{
		return this->status;
	}

	void SetPaticipant(const ParticipantRef &participant)
	{
		this->participant = participant;
		//this->participant.fetch();
	}

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

	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 &other)
	{
        if (this == &other)
            return *this;

		if (this->sid != NULL)
			::mir_free(this->sid);
		this->sid = ::mir_wstrdup(other.sid);

		if (this->nick != NULL)
			::mir_free(this->nick);
		this->nick = ::mir_wstrdup(other.nick);

		this->rank = other.rank;
		this->status = other.status;
		this->participant = other.participant;
        return *this;
	}
};

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

	HANDLE hContact;

	

	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 ChatMember::Compare(p1, p2); }

	bool IsMe(const ChatMember &item) const;
	void SendEvent(const ChatMember &item, int eventType, DWORD timestamp = time(NULL), DWORD flags = GCEF_ADDTOLOG, DWORD itemData = 0, const wchar_t *status = NULL, const wchar_t *message = NULL);
	
	void UpdateMember(const ChatMember &item, DWORD timestamp = time(NULL));
	void KickMember(const ChatMember &item, const ChatMember *author, DWORD timestamp = time(NULL));
	void RemoveMember(const ChatMember &item, DWORD timestamp = time(NULL));

public:
	ChatMember *me;
	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(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;

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

	void AddMember(const ChatMember &item, const ChatMember *author, DWORD timestamp = time(NULL));

	void UpdateMember(const wchar_t *sid, const wchar_t *nick, int rank, int status, DWORD timestamp = time(NULL));
	void KickMember(const wchar_t *sid, const wchar_t *author, 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);
};