Пример #1
0
QString ChatDlg::messageText(const XMPP::Message& m)
{
	bool emote = isEmoteMessage(m);
	QString txt;

	if (m.containsHTML() && PsiOptions::instance()->getOption("options.html.chat.render").toBool() && !m.html().text().isEmpty()) {
		txt = m.html().toString("span");

		if (emote) {
			int cmd = txt.indexOf(me_cmd);
			txt = txt.remove(cmd, me_cmd.length());
		}
		// qWarning("html body:\n%s\n",qPrintable(txt));
	}
	else {
		txt = m.body();

		if (emote)
			txt = txt.mid(me_cmd.length());

		txt = TextUtil::plain2rich(txt);
		txt = TextUtil::linkify(txt);
		// qWarning("regular body:\n%s\n",qPrintable(txt));
	}

	if (PsiOptions::instance()->getOption("options.ui.emoticons.use-emoticons").toBool())
		txt = TextUtil::emoticonify(txt);
	if (PsiOptions::instance()->getOption("options.ui.chat.legacy-formatting").toBool())
		txt = TextUtil::legacyFormat(txt);

	return txt;
}
Пример #2
0
bool GenericChatDialog::isEmoteMessage(const XMPP::Message& m) {
    if (m.body().startsWith(me_cmd) || m.html().text().trimmed().startsWith(me_cmd)) {
        return true;
    }

    return false;
}
Пример #3
0
bool ChatDlg::isEmoteMessage(const XMPP::Message& m)
{
	if (m.body().startsWith(me_cmd) || m.html().text().trimmed().startsWith(me_cmd))
		return true;

	return false;
}
Пример #4
0
void KMessageJabber::slotMessageReceived(const XMPP::Message &message)
{
  if (message.from().full() == mPeerJid)
  {
    QByteArray msg = QByteArray::fromBase64(message.body().toAscii());
    kDebug() << mPeerJid << msg;
    emit received (msg);
  }
}
Пример #5
0
void GatewayTask::slotMessage(const XMPP::Message& msg)
{
    Jid user = msg.from();
    QString legacyNode = msg.to().node();
    QString text = msg.body();

    if ( !legacyNode.isEmpty() ) {
        emit messageToLegacyNode(user, legacyNode, text);
    } else {
        emit messageToService(user, text);
    }
}
Пример #6
0
QString GenericChatDialog::messageText(const XMPP::Message& m) {

    bool emote = isEmoteMessage(m),
        illformed;

    QString txt;

    //reset textFormatter
    textFormatter()->setRemoveEmoteString(false);
    textFormatter()->setTextNodeNumber(0);

    if (m.containsHTML() && PsiOptions::instance()->getOption("options.html.chat.render").toBool()) {
        if (emote) {
            textFormatter()->setRemoveEmoteString(true);
        }
        txt = m.html().toString("span");
    }
    else {
        if (emote) {
            txt = "<span>" + m.body().mid(me_cmd.length()) + "</span>";
        }
        else {
            txt = TextUtil::plain2rich(m.body());
        }
    }

    textFormatter()->setDoEmoticonify(PsiOptions::instance()->getOption("options.ui.emoticons.use-emoticons").toBool());
    textFormatter()->setDoLegacyFormatting(PsiOptions::instance()->getOption("options.ui.chat.legacy-formatting").toBool());

    txt = messageValidator_.validateMessage(txt, &illformed, textFormatter());

    if (illformed) { //html content was illformed, plain version is displayed
        textFormatter()->setTextNodeNumber(0);
        txt = messageValidator_.validateMessage(TextUtil::plain2rich(m.body()), &illformed, textFormatter());
    }

    //qDebug() << "messageText 2" << txt;
    return txt;
}
void JabberGroupMemberContact::handleIncomingMessage ( const XMPP::Message &message )
{
	// message type is always chat in a groupchat
	QString viewType = "kopete_chatwindow";
	Kopete::Message *newMessage = 0L;

	kDebug (JABBER_DEBUG_GLOBAL) << "Received Message Type:" << message.type ();

	Kopete::ChatSession *kmm = manager( Kopete::Contact::CanCreate );
	if(!kmm)
		return;

	if ( message.type () != "error" )
	{
		if (!message.invite().isEmpty())
		{
			/*QString room=message.invite();
			QString originalBody=message.body().isEmpty() ? QString() :
				i18n( "The original message is : <i>\" %1 \"</i><br />" , Qt::escape(message.body()));
			QString mes=i18n("<qt><i>%1</i> has invited you to join the conference <b>%2</b><br />%3<br />"
			                 "If you want to accept and join, just <b>enter your nickname</b> and press OK.<br />"
			                 "If you want to decline, press Cancel.</qt>",
			                 message.from().full(), room , originalBody);
			
			bool ok=false;
			QString futureNewNickName = KInputDialog::getText( i18n( "Invited to a conference - Jabber Plugin" ),
				mes, QString() , &ok , (mManager ? dynamic_cast<QWidget*>(mManager->view(false)) : 0) );
			if ( !ok || !account()->isConnected() || futureNewNickName.isEmpty() )
				return;
			
			XMPP::Jid roomjid(room);
			account()->client()->joinGroupChat( roomjid.domain() , roomjid.node() , futureNewNickName );*/
			return;
		}
		else if (message.body().isEmpty())
		// Then here could be event notifications
		{
			if (message.containsEvent ( XMPP::CancelEvent ) || (message.chatState() != XMPP::StateNone && message.chatState() != XMPP::StateComposing) )
				mManager->receivedTypingMsg ( this, false );
			else if (message.containsEvent ( XMPP::ComposingEvent )|| message.chatState() == XMPP::StateComposing )
				mManager->receivedTypingMsg ( this, true );

			if (message.containsEvent ( XMPP::DisplayedEvent ) )
			{
				//mManager->receivedEventNotification ( i18n("Message has been displayed") );
			}
			else if (message.containsEvent ( XMPP::DeliveredEvent ) )
			{
				//mManager->receivedEventNotification ( i18n("Message has been delivered") );
				mManager->receivedMessageState( message.eventId().toUInt(), Kopete::Message::StateSent );
				mSendsDeliveredEvent = true;
			}
			else if (message.containsEvent ( XMPP::OfflineEvent ) )
			{
				//mManager->receivedEventNotification( i18n("Message stored on the server, contact offline") );
				mManager->receivedMessageState( message.eventId().toUInt(), Kopete::Message::StateSent );
			}
			else if (message.chatState() == XMPP::StateGone )
			{
				/*if(mManager->view( Kopete::Contact::CannotCreate ))
				{   //show an internal message if the user has not already closed his window
					Kopete::Message m=Kopete::Message ( this, mManager->members() );
					m.setPlainBody( i18n("%1 has ended his/her participation in the chat session.", metaContact()->displayName()) );
					m.setDirection( Kopete::Message::Internal );
					m.setImportance(Kopete::Message::Low);
					
					mManager->appendMessage ( m, message.from().resource () );
				}*/
			}

			// XEP-0184: Message Delivery Receipts
			if ( message.messageReceipt() == ReceiptReceived )
			{
				//mManager->receivedEventNotification ( i18n("Message has been delivered") );
				mManager->receivedMessageState( message.messageReceiptId().toUInt(), Kopete::Message::StateSent );
				mSendsDeliveredEvent = true;
			}
		}
		else
		// Then here could be event notification requests
		{
			mRequestComposingEvent = message.containsEvent ( XMPP::ComposingEvent );
			mRequestOfflineEvent = message.containsEvent ( XMPP::OfflineEvent );
			mRequestDeliveredEvent = message.containsEvent ( XMPP::DeliveredEvent );
			mRequestDisplayedEvent = message.containsEvent ( XMPP::DisplayedEvent);

			// XEP-0184: Message Delivery Receipts
			mRequestReceiptDelivery = ( message.messageReceipt() == ReceiptRequest );
		}
	}

	/**
	 * Don't display empty messages, these were most likely just carrying
	 * event notifications or other payload.
	 */
	if ( message.body().isEmpty () )
		return;
	
	Kopete::ContactPtrList contactList = kmm->members();

	// check for errors
	if ( message.type () == "error" )
	{
		newMessage = new Kopete::Message( this, contactList );
		newMessage->setTimestamp( message.timeStamp() );
		newMessage->setPlainBody( i18n("Your message could not be delivered: \"%1\", Reason: \"%2\"",
										  message.body (), message.error().text ) );
		newMessage->setSubject( message.subject() );
		newMessage->setDirection( Kopete::Message::Inbound );
		newMessage->setRequestedPlugin( viewType );
	}
	else
	{
		// store message id for outgoing notifications
		mLastReceivedMessageId = message.id ();
		
		// retrieve and reformat body
		QString body = message.body ();

		if( !message.xencrypted().isEmpty () )
		{
			body = QString ("-----BEGIN PGP MESSAGE-----\n\n") + message.xencrypted () + QString ("\n-----END PGP MESSAGE-----\n");
		}
		else if( !message.xsigned().isEmpty () )
		{
			body = QString ("-----BEGIN PGP MESSAGE-----\n\n") + message.xsigned () + QString ("\n-----END PGP MESSAGE-----\n");
		}

		// convert XMPP::Message into Kopete::Message
		newMessage = new Kopete::Message ( this, contactList );
		newMessage->setTimestamp( message.timeStamp() );
		newMessage->setPlainBody( body );
		newMessage->setDirection( Kopete::Message::Inbound );
		newMessage->setRequestedPlugin( viewType );
		newMessage->setImportance( Kopete::Message::Low );
	}

	// append message to manager
	kmm->appendMessage ( *newMessage );

	delete newMessage;

}
Пример #8
0
void KMessageJabber::slotGroupChatLeft(const XMPP::Message& msg)
{
  kDebug() << msg.from().full() << msg.to().full() << msg.body();
}
Пример #9
0
Error XMPPStream::sendMessage (const xmpp::Message & m) {
	String dst;
	m.encode(dst);
	return send (dst);
}