summaryrefslogtreecommitdiff
path: root/protocols/Skype/src/skype_events.cpp
blob: 8ceb136173abc8c2551d10dc104336f476233487 (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
#include "skype_proto.h"

int CSkypeProto::OnModulesLoaded(WPARAM, LPARAM)
{
	this->RegisterChat();
	this->HookEvent(ME_OPT_INITIALISE, &CSkypeProto::OnOptionsInit);
	this->HookEvent(ME_USERINFO_INITIALISE, &CSkypeProto::OnUserInfoInit);
	
	this->login = ::DBGetString(NULL, this->m_szModuleName, "sid");
	this->rememberPassword = this->GetSettingByte("RememberPassword") > 0;

	return 0;
}

int CSkypeProto::OnPreShutdown(WPARAM, LPARAM)
{
	this->SetStatus(ID_STATUS_OFFLINE);

	return 0;
}

int CSkypeProto::OnContactDeleted(WPARAM wParam, LPARAM lParam)
{
	this->RevokeAuth(wParam, lParam);

	return 0;
}

void CSkypeProto::OnMessageSended(CConversation::Ref conversation, CMessage::Ref message)
{
	uint timestamp;
	message->GetPropTimestamp(timestamp);

	SEString data;

	message->GetPropAuthor(data);
	char *sid = ::mir_strdup((const char*)data);

	message->GetPropBodyXml(data);
	char *text = ::mir_strdup((const char*)data);

	Participant::Refs participants;
	conversation->GetParticipants(participants, CConversation::OTHER_CONSUMERS);
		
	for (uint i = 0; i < participants.size(); i ++)
	{			
		participants[i]->GetPropIdentity(data);
		char *contactSid = ::mir_strdup((const char *)data);
		//todo: get nickname
		this->RaiseMessageSendedEvent(
			timestamp,
			contactSid,
			contactSid,
			text);
	}
}

void CSkypeProto::OnMessageReceived(CConversation::Ref conversation, CMessage::Ref message)
{
	uint timestamp;
	message->GetPropTimestamp(timestamp);

	SEString data;

	message->GetPropAuthor(data);
	char *sid = ::mir_strdup((const char*)data);

	message->GetPropAuthorDisplayname(data);
	char *nick = ::mir_strdup((const char*)data);

	message->GetPropBodyXml(data);
	char *text = ::mir_strdup((const char*)data);

	this->RaiseMessageReceivedEvent(
		(DWORD)timestamp, 
		sid, 
		nick, 
		text);

	/*const char *msg = (const char*)propValues[2];
	int len = ::strlen(msg) + 8;
	wchar_t *xml = new wchar_t[len];
	::mir_sntprintf(xml, len, L"<m>%s</m>", ::mir_utf8decodeW(msg));

	int bytesProcessed = 0;
	HXML hXml = xi.parseString(xml, &bytesProcessed, NULL);*/
}

void CSkypeProto::OnMessage(CConversation::Ref conversation, CMessage::Ref message)
{
	CMessage::TYPE messageType;
	message->GetPropType(messageType);

	CMessage::SENDING_STATUS sendingStatus;
	message->GetPropSendingStatus(sendingStatus);

	if (messageType == CMessage::POSTED_TEXT)
	{
		if (sendingStatus == CMessage::SENT)
			this->OnMessageSended(conversation, message);
		else if (!sendingStatus)
			this->OnMessageReceived(conversation, message);
	}
}