-
Notifications
You must be signed in to change notification settings - Fork 5
/
facebookchatsession.cpp
87 lines (68 loc) · 2.78 KB
/
facebookchatsession.cpp
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
#include <KComponentData>
#include "kopeteprotocol.h"
#include "kopetecontact.h"
#include "kopetechatsessionmanager.h"
#include "facebookchatsession.h"
FacebookChatSession::FacebookChatSession( Kopete::Protocol *protocol, const Kopete::Contact *user, Kopete::ContactPtrList others, Facebook::ChatService *service )
: Kopete::ChatSession(user, others, protocol)
, m_service(service)
{
Kopete::ChatSessionManager::self ()->registerChatSession (this);
setComponentData (protocol->componentData ());
QObject::connect (this, SIGNAL(messageSent(Kopete::Message &,
Kopete::ChatSession *)),
this, SLOT(slotMessageSent(Kopete::Message &,
Kopete::ChatSession *)));
QObject::connect (this, SIGNAL(myselfTyping(bool)),
this, SLOT (slotSendTyping(bool)));
}
FacebookChatSession::~FacebookChatSession()
{
}
void FacebookChatSession::slotSendTyping(bool typ)
{
// send typing notification here
Q_UNUSED(typ);
}
void FacebookChatSession::slotMessageSent(Kopete::Message &message, Kopete::ChatSession *chat)
{
Q_UNUSED(chat)
// convert to the what the server wants
// For this 'protocol', there's nothing to do
// send it
Facebook::ChatMessage fbmessage;
fbmessage.setTo(message.to().first()->contactId());
fbmessage.setText(message.plainBody());
m_service->sendMessage( fbmessage );
message.setState( Kopete::Message::StateSending );
this->appendMessage(message);
this->messageSucceeded();
m_messagesSentQueue[fbmessage.messageId()] = message;
m_messagesTimeoutQueue.append(fbmessage.messageId());
QTimer::singleShot (60 * 1000, this,
SLOT (slotMessageTimeout()));
}
void FacebookChatSession::slotMessageTimeout()
{
QString messageId = m_messagesTimeoutQueue.takeFirst();
if(m_messagesSentQueue.contains(messageId))
this->receivedMessageState(m_messagesSentQueue[messageId].id(), Kopete::Message::StateError );
}
void FacebookChatSession::slotMessageAck( const QString &messageId )
{
this->receivedMessageState(m_messagesSentQueue[messageId].id(), Kopete::Message::StateSent );
m_messagesSentQueue.remove(messageId);
// remove the blinking icon when there are no messages
// waiting for delivery
if (m_messagesSentQueue.empty ())
messageSucceeded ();
}
void FacebookChatSession::slotMessageError( const QString &messageId )
{
this->receivedMessageState(m_messagesSentQueue[messageId].id(), Kopete::Message::StateError );
m_messagesSentQueue.remove(messageId);
// remove the blinking icon when there are no messages
// waiting for delivery
if (m_messagesSentQueue.empty ())
messageSucceeded ();
}