void EventNotifier::handleEventAdded(std::shared_ptr<StanzaEvent> event) { if (event->getConcluded()) { return; } if (std::shared_ptr<MessageEvent> messageEvent = std::dynamic_pointer_cast<MessageEvent>(event)) { JID jid = messageEvent->getStanza()->getFrom(); std::string title = nickResolver->jidToNick(jid); if (!messageEvent->getStanza()->isError() && !messageEvent->getStanza()->getBody().get_value_or("").empty()) { JID activationJID = jid; if (messageEvent->getStanza()->getType() == Message::Groupchat) { activationJID = jid.toBare(); } std::string messageText = messageEvent->getStanza()->getBody().get_value_or(""); if (boost::starts_with(messageText, "/me ")) { messageText = "*" + String::getSplittedAtFirst(messageText, ' ').second + "*"; } notifier->showMessage(Notifier::IncomingMessage, title, messageText, avatarManager->getAvatarPath(jid), boost::bind(&EventNotifier::handleNotificationActivated, this, activationJID)); } } else if(std::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = std::dynamic_pointer_cast<SubscriptionRequestEvent>(event)) { JID jid = subscriptionEvent->getJID(); std::string title = jid; std::string message = str(format(QT_TRANSLATE_NOOP("", "%1% wants to add you to his/her contact list")) % nickResolver->jidToNick(jid)); notifier->showMessage(Notifier::SystemMessage, title, message, boost::filesystem::path(), boost::function<void()>()); } else if(std::shared_ptr<ErrorEvent> errorEvent = std::dynamic_pointer_cast<ErrorEvent>(event)) { notifier->showMessage(Notifier::SystemMessage, QT_TRANSLATE_NOOP("", "Error"), errorEvent->getText(), boost::filesystem::path(), boost::function<void()>()); } else if (std::shared_ptr<MUCInviteEvent> mucInviteEvent = std::dynamic_pointer_cast<MUCInviteEvent>(event)) { std::string title = mucInviteEvent->getInviter(); std::string message = str(format(QT_TRANSLATE_NOOP("", "%1% has invited you to enter the %2% room")) % nickResolver->jidToNick(mucInviteEvent->getInviter()) % mucInviteEvent->getRoomJID()); // FIXME: not show avatar or greyed out avatar for mediated invites notifier->showMessage(Notifier::SystemMessage, title, message, avatarManager->getAvatarPath(mucInviteEvent->getInviter()), boost::bind(&EventNotifier::handleNotificationActivated, this, mucInviteEvent->getInviter())); } }
void ServerStanzaChannel::send(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Stanza> stanza) { JID to = stanza->getTo(); assert(to.isValid()); if (!stanza->getFrom().isValid()) { stanza->setFrom(m_jid); } // For a full JID, first try to route to a session with the full JID if (!to.isBare()) { std::list<SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<ServerFromClientSession> >::const_iterator i = std::find_if(sessions[stanza->getTo().toBare().toString()].begin(), sessions[stanza->getTo().toBare().toString()].end(), HasJID(to)); if (i != sessions[stanza->getTo().toBare().toString()].end()) { (*i)->sendElement(stanza); return; } } // Look for candidate sessions to = to.toBare(); std::vector<SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<ServerFromClientSession> > candidateSessions; for (std::list<SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<ServerFromClientSession> >::const_iterator i = sessions[stanza->getTo().toBare().toString()].begin(); i != sessions[stanza->getTo().toBare().toString()].end(); ++i) { if ((*i)->getRemoteJID().equals(to, JID::WithoutResource)) { candidateSessions.push_back(*i); (*i)->sendElement(stanza); } } if (candidateSessions.empty()) { return; } // Find the session with the highest priority // std::vector<ServerSession*>::const_iterator i = std::max_element(sessions.begin(), sessions.end(), PriorityLessThan()); // (*i)->sendStanza(stanza); return; }
void handleSenderCapsChanged(const JID &jid) { if (receiver_ && (receiver_->getJID().toBare() == jid.toBare())) { boost::shared_ptr<FileReadBytestream> fileStream = boost::make_shared<FileReadBytestream>(sendFilePath_); FileTransferOptions options; options = options.withInBandAllowed(senderCandidates_ & InBandBytestream); options = options.withDirectAllowed(senderCandidates_ & S5B_Direct); options = options.withAssistedAllowed(senderCandidates_ & S5B_Assisted); options = options.withProxiedAllowed(senderCandidates_ & S5B_Proxied); std::cout << "Outgoing transfer options: " << "IBB (" << options.isInBandAllowed() << ")" << ", "; std::cout << "S5B Direct (" << options.isDirectAllowed() << ")" << ", "; std::cout << "S5B Assisted (" << options.isAssistedAllowed() << ")" << ", "; std::cout << "S5B Proxied (" << options.isProxiedAllowed() << ")" << std::endl; outgoingFileTransfer_ = sender_->getFileTransferManager()->createOutgoingFileTransfer(jid.toBare(), sendFilePath_, "Some File!", fileStream, options); if (outgoingFileTransfer_) { outgoingFileTransfer_->onFinished.connect(boost::bind(&FileTransferTest::handleSenderFileTransferFinished, this, _1)); outgoingFileTransfer_->start(); } else { std::cout << "ERROR: No outgoing file transfer returned." << std::endl; endTest(); } } }
void EventNotifier::handleEventAdded(boost::shared_ptr<StanzaEvent> event) { if (event->getConcluded()) { return; } if (boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event)) { JID jid = messageEvent->getStanza()->getFrom(); std::string title = nickResolver->jidToNick(jid); if (!messageEvent->getStanza()->isError() && !messageEvent->getStanza()->getBody().empty()) { JID activationJID = jid; if (messageEvent->getStanza()->getType() == Message::Groupchat) { activationJID = jid.toBare(); } notifier->showMessage(Notifier::IncomingMessage, title, messageEvent->getStanza()->getBody(), avatarManager->getAvatarPath(jid), boost::bind(&EventNotifier::handleNotificationActivated, this, activationJID)); } } else if(boost::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event)) { JID jid = subscriptionEvent->getJID(); std::string title = jid; std::string message = str(format(QT_TRANSLATE_NOOP("", "%1% wants to add you to his/her contact list")) % nickResolver->jidToNick(jid)); notifier->showMessage(Notifier::SystemMessage, title, message, boost::filesystem::path(), boost::function<void()>()); } else if(boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(event)) { notifier->showMessage(Notifier::SystemMessage, QT_TRANSLATE_NOOP("", "Error"), errorEvent->getText(), boost::filesystem::path(), boost::function<void()>()); } }
bool ServerStanzaRouter::routeStanza(boost::shared_ptr<Stanza> stanza) { JID to = stanza->getTo(); assert(to.isValid()); // For a full JID, first try to route to a session with the full JID if (!to.isBare()) { std::vector<ServerSession*>::const_iterator i = std::find_if(clientSessions_.begin(), clientSessions_.end(), HasJID(to)); if (i != clientSessions_.end()) { (*i)->sendStanza(stanza); return true; } } // Look for candidate sessions to = to.toBare(); std::vector<ServerSession*> candidateSessions; for (std::vector<ServerSession*>::const_iterator i = clientSessions_.begin(); i != clientSessions_.end(); ++i) { if ((*i)->getJID().equals(to, JID::WithoutResource) && (*i)->getPriority() >= 0) { candidateSessions.push_back(*i); } } if (candidateSessions.empty()) { return false; } // Find the session with the highest priority std::vector<ServerSession*>::const_iterator i = std::max_element(clientSessions_.begin(), clientSessions_.end(), PriorityLessThan()); (*i)->sendStanza(stanza); return true; }
void QtUserSearchWindow::prepopulateJIDAndName(const JID& jid, const std::string& name) { firstPage_->jid_->setText(P2QSTRING(jid.toBare().toString())); detailsPage_->setJID(jid); lastPage_ = 1; restart(); next(); detailsPage_->setName(name); }
std::vector<std::string> XMPPRosterImpl::getGroupsForJID(const JID& jid) { std::map<JID, XMPPRosterItem>::iterator i = entries_.find(jid.toBare()); if (i != entries_.end()) { return i->second.getGroups(); } else { return std::vector<std::string>(); } }
std::string XMPPRosterImpl::getNameForJID(const JID& jid) const { std::map<JID, XMPPRosterItem>::const_iterator i = entries_.find(jid.toBare()); if (i != entries_.end()) { return i->second.getName(); } else { return ""; } }
RosterItemPayload::Subscription XMPPRosterImpl::getSubscriptionStateForJID(const JID& jid) { std::map<JID, XMPPRosterItem>::iterator i = entries_.find(jid.toBare()); if (i != entries_.end()) { return i->second.getSubscription(); } else { return RosterItemPayload::None; } }
JID QtTreeWidget::jidFromIndex(const QModelIndex& index) const { JID target; if (messageTarget_ == MessageDisplayJID) { target = JID(Q2PSTRING(index.data(DisplayJIDRole).toString())); target = target.toBare(); } if (!target.isValid()) { target = JID(Q2PSTRING(index.data(JIDRole).toString())); } return target; }
void XMPPRosterImpl::addContact(const JID& jid, const std::string& name, const std::vector<std::string>& groups, RosterItemPayload::Subscription subscription) { JID bareJID(jid.toBare()); std::map<JID, XMPPRosterItem>::iterator i = entries_.find(bareJID); if (i != entries_.end()) { std::string oldName = i->second.getName(); std::vector<std::string> oldGroups = i->second.getGroups(); i->second = XMPPRosterItem(jid, name, groups, subscription); onJIDUpdated(bareJID, oldName, oldGroups); } else { entries_.insert(std::make_pair(bareJID, XMPPRosterItem(jid, name, groups, subscription))); onJIDAdded(bareJID); } }
Presence::ref PresenceOracle::getLastPresence(const JID& jid) const { PresencesMap::const_iterator i = entries_.find(jid.toBare()); if (i == entries_.end()) { return Presence::ref(); } PresenceMap presenceMap = i->second; PresenceMap::const_iterator j = presenceMap.find(jid); if (j != presenceMap.end()) { return j->second; } else { return Presence::ref(); } }
void handleCapsChanged(JID jid) { if (jid.toBare() == recipient) { // create ReadBytestream from file boost::shared_ptr<FileReadBytestream> fileStream = boost::make_shared<FileReadBytestream>(file); outgoingFileTransfer = client->getFileTransferManager()->createOutgoingFileTransfer(recipient, file, "Some File!", fileStream); if (outgoingFileTransfer) { outgoingFileTransfer->onFinished.connect(boost::bind(&FileSender::handleFileTransferFinished, this, _1)); std::cout << "Starting file-transfer to " << recipient.toString() << "." << std::endl; outgoingFileTransfer->start(); // TODO: getting notified about FT status and end } else { std::cout << recipient << " doesn't support any kind of file transfer!" << std::endl; client->disconnect(); } } }
JID withResource(const JID& jid, const std::string& resource) { return JID(jid.toBare().toString() + "/" + resource); }
Presence::ref PresenceOracle::getAccountPresence(const JID& jid) const { Presence::ref accountPresence; std::vector<Presence::ref> allPresences = getAllPresence(jid.toBare()); accountPresence = getActivePresence(allPresences); return accountPresence; }
void QtMainWindow::setMyJID(const JID& jid) { meView_->setJID(P2QSTRING(jid.toBare().toString())); }
void XMPPRosterImpl::removeContact(const JID& jid) { entries_.erase(JID(jid.toBare())); onJIDRemoved(jid); }
bool XMPPRosterImpl::containsJID(const JID& jid) { return entries_.find(JID(jid.toBare())) != entries_.end(); }
void ServerStanzaChannel::finishSession(const JID& to, SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<ToplevelElement> element, bool last) { #else void ServerStanzaChannel::finishSession(const JID& to, SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Element> element, bool last) { #endif std::vector<SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<ServerFromClientSession> > candidateSessions; for (std::list<SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<ServerFromClientSession> >::const_iterator i = sessions[to.toBare().toString()].begin(); i != sessions[to.toBare().toString()].end(); ++i) { candidateSessions.push_back(*i); } for (std::vector<SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<ServerFromClientSession> >::const_iterator i = candidateSessions.begin(); i != candidateSessions.end(); ++i) { removeSession(*i); if (element) { (*i)->sendElement(element); } if (last && (*i)->getRemoteJID().isValid()) { Swift::Presence::ref presence = Swift::Presence::create(); presence->setFrom((*i)->getRemoteJID()); presence->setType(Swift::Presence::Unavailable); onPresenceReceived(presence); } (*i)->finishSession(); // std::cout << "FINISH SESSION " << sessions[to.toBare().toString()].size() << "\n"; if (last) { break; } } }
void QtVCardJIDField::setJID(const JID& jid) { std::string jidStr = jid.toBare().toString(); jidLineEdit->setText(P2QSTRING(jidStr)); }
JID VCardUpdateAvatarManager::getAvatarJID(const JID& jid) const { JID bareFrom = jid.toBare(); return (mucRegistry_ && mucRegistry_->isMUC(bareFrom)) ? jid : bareFrom; }
bool BlockList::isBlocked(const JID& jid) const { const std::vector<JID>& items = getItems(); return (std::find(items.begin(), items.end(), jid.toBare()) != items.end()) || (std::find(items.begin(), items.end(), JID(jid.getDomain())) != items.end()) || (std::find(items.begin(), items.end(), jid) != items.end()); }