Example #1
0
StorageKey RosterPlugin::getStorage(gloox::Stanza*s)
{
    if (!rosterStorage_)
        return StorageKey();
    QString jid=QString::fromStdString(s->from().bare());
    int idx=rosterStorage_->getStorage(jid);
    if (idx<=0 && autoCreateStorage_)
        idx=rosterStorage_->createStorage(jid);
    if (idx<=0)
        return StorageKey();
    return StorageKey(pluginId, idx);
}
void Manager::Impl::showNextNotification() {
	// Show only one notification at a time in Unity / Notify OSD.
	if (_poorSupported) {
		for (auto b = _notifications.begin(); !_notifications.isEmpty() && b->isEmpty();) {
			_notifications.erase(b);
		}
		if (!_notifications.isEmpty()) {
			return;
		}
	}

	QueuedNotification data;
	while (!_queuedNotifications.isEmpty()) {
		data = _queuedNotifications.front();
		_queuedNotifications.pop_front();
		if (data.peer) {
			break;
		}
	}
	if (!data.peer) {
		return;
	}

	auto peerId = data.peer->id;
	auto msgId = data.msgId;
	auto notification = MakeShared<NotificationData>(data.title, data.body, _capabilities, peerId, msgId);
	if (!notification->valid()) {
		return;
	}

	StorageKey key;
	if (data.hideNameAndPhoto) {
		key = StorageKey(0, 0);
	} else {
		key = data.peer->userpicUniqueKey();
	}
	notification->setImage(_cachedUserpics.get(key, data.peer));

	auto i = _notifications.find(peerId);
	if (i != _notifications.cend()) {
		auto j = i->find(msgId);
		if (j != i->cend()) {
			auto oldNotification = j.value();
			i->erase(j);
			oldNotification->close();
			i = _notifications.find(peerId);
		}
	}
	if (i == _notifications.cend()) {
		i = _notifications.insert(peerId, QMap<MsgId, Notification>());
	}
	_notifications[peerId].insert(msgId, notification);
	if (!notification->show()) {
		i = _notifications.find(peerId);
		if (i != _notifications.cend()) {
			i->remove(msgId);
			if (i->isEmpty()) _notifications.erase(i);
		}
		showNextNotification();
	}
}