mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-01 03:40:16 +02:00
Don't open more than one SubscriptionRequest window and auto-ack only contacts that the user is already subscribed to
This commit is contained in:
@@ -614,24 +614,46 @@ Jabber_p::handleSubscriptionRequest( const JID& jid, const std::string& /*msg*/
|
|||||||
|
|
||||||
// check if the requester is already on the roster
|
// check if the requester is already on the roster
|
||||||
RosterItem *item = m_client->rosterManager()->getRosterItem(jid);
|
RosterItem *item = m_client->rosterManager()->getRosterItem(jid);
|
||||||
if(item)
|
if(item &&
|
||||||
|
(
|
||||||
|
item->subscription() == gloox::S10nNoneOut || // Contact and user are not subscribed to each other, and user has sent contact a subscription request but contact has not replied yet.
|
||||||
|
item->subscription() == gloox::S10nTo || // User is subscribed to contact (one-way).
|
||||||
|
item->subscription() == gloox::S10nToIn // User is subscribed to contact, and contact has sent user a subscription request but user has not replied yet.
|
||||||
|
)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << "Already on the roster so we assume ack'ing subscription request is okay...";
|
qDebug() << Q_FUNC_INFO << jid.bare().c_str() << "Already on the roster so we assume ack'ing subscription request is okay...";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( !m_subscriptionConfirmBoxes.value(jid).isNull() )
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << jid.bare().c_str() << " confirmBox already open" ;
|
||||||
|
|
||||||
|
// the user decides with the already open box, so we can return false here
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// ask whether to accept subscription request or not
|
// preparing the confirm box for the user
|
||||||
QMessageBox::StandardButton allowSubscription;
|
QWeakPointer<QMessageBox> confirmBox = QWeakPointer<QMessageBox>(new QMessageBox(
|
||||||
allowSubscription = QMessageBox::question( 0,
|
QMessageBox::Question,
|
||||||
tr("Friend Request in Jabber"),
|
tr("Friend Request in Jabber"),
|
||||||
QString(tr("Do you want to be friends with <b>%1</b>?")).arg(QLatin1String(jid.bare().c_str())),
|
QString(tr("Do you want to be friends with <b>%1</b>?")).arg(QLatin1String(jid.bare().c_str())),
|
||||||
QMessageBox::Ok | QMessageBox::Cancel
|
QMessageBox::Ok | QMessageBox::Cancel,
|
||||||
);
|
0));
|
||||||
|
|
||||||
|
// add confirmBox to m_subscriptionConfirmBoxes
|
||||||
|
m_subscriptionConfirmBoxes.insert(jid, confirmBox);
|
||||||
|
|
||||||
|
// display the box and wait for the answer
|
||||||
|
QMessageBox::StandardButton allowSubscription = static_cast<QMessageBox::StandardButton>(confirmBox.data()->exec());
|
||||||
|
|
||||||
|
// we got an answer, deleting the box
|
||||||
|
confirmBox.data()->deleteLater();
|
||||||
|
|
||||||
if(allowSubscription == QMessageBox::Ok)
|
if(allowSubscription == QMessageBox::Ok)
|
||||||
{
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << jid.bare().c_str() << "accepted by user, adding to roster";
|
||||||
StringList groups;
|
StringList groups;
|
||||||
groups.push_back( "Tomahawk" );
|
groups.push_back( "Tomahawk" );
|
||||||
m_client->rosterManager()->subscribe( jid, "", groups, "" );
|
m_client->rosterManager()->subscribe( jid, "", groups, "" );
|
||||||
@@ -639,6 +661,7 @@ Jabber_p::handleSubscriptionRequest( const JID& jid, const std::string& /*msg*/
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qDebug() << Q_FUNC_INFO << jid.bare().c_str() << "declined by user";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#include <QSocketNotifier>
|
#include <QSocketNotifier>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QNetworkProxy>
|
#include <QNetworkProxy>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -164,6 +165,7 @@ private:
|
|||||||
QSharedPointer<gloox::VCardManager> m_vcardManager;
|
QSharedPointer<gloox::VCardManager> m_vcardManager;
|
||||||
QString m_server;
|
QString m_server;
|
||||||
QScopedPointer<QSocketNotifier> m_notifier;
|
QScopedPointer<QSocketNotifier> m_notifier;
|
||||||
|
QHash<gloox::JID, QWeakPointer<QMessageBox> > m_subscriptionConfirmBoxes;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // JABBER_H
|
#endif // JABBER_H
|
||||||
|
Reference in New Issue
Block a user