chatstatefilter.cpp
/*
Copyright (c) 2005-2023 by Jakob Schröter <js@camaya.net>
This file is part of the gloox library. http://camaya.net/gloox
This software is distributed under a license. The full license
agreement can be found in the file LICENSE in this distribution.
This software may not be copied, modified, sold or distributed
other than expressed in the named license agreement.
This software is distributed without any warranty.
*/
#include "chatstatefilter.h"
#include "chatstatehandler.h"
#include "messageeventhandler.h"
#include "messagesession.h"
#include "message.h"
#include "chatstate.h"
namespace gloox
{
ChatStateFilter::ChatStateFilter( MessageSession* parent )
: MessageFilter( parent ), m_chatStateHandler( 0 ), m_lastSent( ChatStateGone ),
m_enableChatStates( true )
{
}
ChatStateFilter::~ChatStateFilter()
{
}
void ChatStateFilter::filter( Message& msg )
{
if( m_enableChatStates && m_chatStateHandler )
{
const ChatState* state = msg.findExtension<ChatState>( ExtChatState );
if( !state )
return;
m_enableChatStates = ( state->state() != ChatStateInvalid );
if( m_enableChatStates && msg.body().empty() )
m_chatStateHandler->handleChatState( msg.from(), state->state() );
}
}
void ChatStateFilter::setChatState( ChatStateType state )
{
if( !m_enableChatStates || state == m_lastSent || state == ChatStateInvalid )
return;
Message m( Message::Chat, m_parent->target() );
m.addExtension( new ChatState( state ) );
m_lastSent = state;
send( m );
}
void ChatStateFilter::decorate( Message& msg )
{
if( m_enableChatStates )
msg.addExtension( new ChatState( ChatStateActive ) );
}
}
gloox::ChatStateFilter::setChatState
void setChatState(ChatStateType state)
Definition chatstatefilter.cpp:49
gloox::ChatStateFilter::decorate
virtual void decorate(Message &msg)
Definition chatstatefilter.cpp:62
gloox::ChatStateFilter::ChatStateFilter
ChatStateFilter(MessageSession *parent)
Definition chatstatefilter.cpp:24
gloox::ChatStateFilter::m_lastSent
ChatStateType m_lastSent
Definition chatstatefilter.h:96
gloox::ChatStateFilter::filter
virtual void filter(Message &msg)
Definition chatstatefilter.cpp:34
gloox::ChatStateFilter::m_chatStateHandler
ChatStateHandler * m_chatStateHandler
Definition chatstatefilter.h:93
gloox::ChatStateFilter::~ChatStateFilter
virtual ~ChatStateFilter()
Definition chatstatefilter.cpp:30
gloox::ChatStateFilter::m_enableChatStates
bool m_enableChatStates
Definition chatstatefilter.h:99
gloox::ChatState
An implementation of Chat State Notifications (XEP-0085) as a StanzaExtension.
Definition chatstate.h:34
gloox::ChatState::state
ChatStateType state() const
Definition chatstate.h:60
gloox::MessageFilter::MessageFilter
MessageFilter(MessageSession *parent)
Definition messagefilter.cpp:20
gloox::MessageSession
An abstraction of a message session between any two entities.
Definition messagesession.h:146
gloox::Message
An abstraction of a message stanza.
Definition message.h:34
gloox::Message::body
const std::string body(const std::string &lang="default") const
Definition message.h:87
gloox::Message::Chat
@ Chat
Definition message.h:46
gloox::Stanza::addExtension
void addExtension(const StanzaExtension *se)
Definition stanza.cpp:52
gloox::Stanza::from
const JID & from() const
Definition stanza.h:51
gloox::Stanza::findExtension
const StanzaExtension * findExtension(int type) const
Definition stanza.cpp:57
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::ChatStateType
ChatStateType
Definition gloox.h:1105
gloox::ChatStateInvalid
@ ChatStateInvalid
Definition gloox.h:1112
gloox::ChatStateActive
@ ChatStateActive
Definition gloox.h:1106
gloox::ChatStateGone
@ ChatStateGone
Definition gloox.h:1110
gloox::ExtChatState
@ ExtChatState
Definition stanzaextension.h:50