Commit 33e4c287 authored by Siddhartha Sahu's avatar Siddhartha Sahu Committed by Sven Brauch

Added functions for setting user typing status

REVIEW:112597
parent 99fdc69f
......@@ -40,6 +40,7 @@ class Conversation::ConversationPrivate
bool delegated;
bool valid;
Tp::AccountPtr account;
QTimer *pausedStateTimer;
};
Conversation::Conversation(const Tp::TextChannelPtr &channel,
......@@ -59,6 +60,9 @@ Conversation::Conversation(const Tp::TextChannelPtr &channel,
d->delegated = false;
d->pausedStateTimer = new QTimer(this);
d->pausedStateTimer->setSingleShot(true);
connect(d->pausedStateTimer, SIGNAL(timeout()), this, SLOT(onChatPausedTimerExpired()));
}
Conversation::Conversation(QObject *parent) : QObject(parent)
......@@ -148,6 +152,30 @@ void Conversation::requestClose()
Q_EMIT conversationCloseRequested();
}
void Conversation::updateTextChanged(const QString &message)
{
if (!message.isEmpty()) {
//if the timer is active, it means the user is continuously typing
if (d->pausedStateTimer->isActive()) {
//just restart the timer and don't spam with chat state changes
d->pausedStateTimer->start(5000);
} else {
//if the user has just typed some text, set state to Composing and start the timer
d->messages->textChannel()->requestChatState(Tp::ChannelChatStateComposing);
d->pausedStateTimer->start(5000);
}
} else {
//if the user typed no text/cleared the input field, set Active and stop the timer
d->messages->textChannel()->requestChatState(Tp::ChannelChatStateActive);
d->pausedStateTimer->stop();
}
}
void Conversation::onChatPausedTimerExpired()
{
d->messages->textChannel()->requestChatState(Tp::ChannelChatStatePaused);
}
Conversation::~Conversation()
{
kDebug();
......
......@@ -59,11 +59,13 @@ Q_SIGNALS:
public Q_SLOTS:
void delegateToProperClient();
void requestClose();
void updateTextChanged(const QString &message);
private Q_SLOTS:
void onChannelInvalidated(Tp::DBusProxy *proxy, const QString &errorName, const QString &errorMessage);
void onAccountConnectionChanged(const Tp::ConnectionPtr &connection);
void onCreateChannelFinished(Tp::PendingOperation *op);
void onChatPausedTimerExpired();
private:
class ConversationPrivate;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment