bool MySqlStorage::updateAskAttributeToContact(QString jid, QString contactJid, QString ask) { Contact contact = getContact(jid, contactJid); QSqlQuery query; query.prepare("UPDATE qjabberd_contact SET ask = :ask WHERE user_id = :user_id AND jid = :jid"); query.bindValue(":user_id", getUserId(jid)); query.bindValue(":jid", contactJid); if ((contact.getSubscription() != "to") && (contact.getSubscription() != "both")) { query.bindValue(":ask", ask); } return query.exec(); }
bool MySqlStorage::addContactToRoster(QString jid, Contact contact) { if (contactExists(jid, contact.getJid())) { updateNameToContact(jid, contact.getJid(), contact.getName()); updateGroupToContact(jid, contact.getJid(), contact.getGroups()); return true; } else { if (userExists(contact.getJid())) { QJsonDocument document; QJsonObject object; object.insert("groups", QJsonArray::fromStringList(QStringList::fromSet(contact.getGroups()))); document.setObject(object); QSqlQuery query; query.prepare("INSERT INTO qjabberd_contact(user_id, approved, ask, groups, jid, name, subscription, version)" " VALUES(:user_id, :approved, :ask, :groups, :jid, :name, :subscription, :version)"); query.bindValue(":user_id", getUserId(jid)); query.bindValue(":version", contact.getVersion()); query.bindValue(":approved", (int)contact.getApproved()); query.bindValue(":ask", contact.getAsk()); query.bindValue(":jid", contact.getJid()); query.bindValue(":name", contact.getName()); query.bindValue(":subscription", contact.getSubscription()); query.bindValue(":groups", document.toJson()); return query.exec(); } } return false; }