diff --git a/src/ruqolacore/mention.cpp b/src/ruqolacore/mention.cpp index 37fbf4fc..eef18541 100644 --- a/src/ruqolacore/mention.cpp +++ b/src/ruqolacore/mention.cpp @@ -1,31 +1,37 @@ /* Copyright (c) 2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "mention.h" Mention::Mention() { } QDebug operator <<(QDebug d, const Mention &t) { //TODO return d; } + +bool Mention::operator ==(const Mention &other) const +{ + //return (mUserNames == other.userNames()) && (mReactionName == other.reactionName()); + return true; +} diff --git a/src/ruqolacore/mention.h b/src/ruqolacore/mention.h index ad21776c..af643750 100644 --- a/src/ruqolacore/mention.h +++ b/src/ruqolacore/mention.h @@ -1,53 +1,53 @@ /* Copyright (c) 2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef MENTION_H #define MENTION_H #include "libruqola_private_export.h" #include class LIBRUQOLACORE_TESTS_EXPORT Mention { Q_GADGET // Q_PROPERTY(int count READ count CONSTANT) // Q_PROPERTY(QString reactionName READ reactionName CONSTANT) // Q_PROPERTY(QString convertedReactionName READ convertedReactionName CONSTANT) public: Mention(); // Q_REQUIRED_RESULT QString reactionName() const; // void setReactionName(const QString &reactionName); // Q_REQUIRED_RESULT QStringList userNames() const; // void setUserNames(const QStringList &userNames); // Q_REQUIRED_RESULT int count() const; -// Q_REQUIRED_RESULT bool operator ==(const Reaction &other) const; + Q_REQUIRED_RESULT bool operator ==(const Mention &other) const; // Q_REQUIRED_RESULT QString convertedReactionName() const; private: // QString mReactionName; // QStringList mUserNames; }; Q_DECLARE_METATYPE(Mention) Q_DECLARE_TYPEINFO(Mention, Q_MOVABLE_TYPE); LIBRUQOLACORE_EXPORT QDebug operator <<(QDebug d, const Mention &t); #endif // MENTION_H diff --git a/src/ruqolacore/mentions.cpp b/src/ruqolacore/mentions.cpp index ae597099..ba1f5243 100644 --- a/src/ruqolacore/mentions.cpp +++ b/src/ruqolacore/mentions.cpp @@ -1,120 +1,118 @@ /* Copyright (c) 2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "mentions.h" #include #include Mentions::Mentions() { } void Mentions::setMentions(const QVector &mentions) { mMentions = mentions; } QVector Mentions::mentions() const { return mMentions; } void Mentions::parseMentions(const QJsonObject &reacts) { mMentions.clear(); // const QStringList lst = reacts.keys(); // QStringList users; // for (const QString &str : lst) { // users.clear(); // const QJsonObject obj = reacts.value(str).toObject(); // QJsonValue usernames = obj.value(QLatin1String("usernames")); // if (!usernames.isUndefined()) { // QJsonArray array = usernames.toArray(); // for (int i = 0; i < array.count(); ++i) { // users.append(array.at(i).toString()); // } // } // if (!users.isEmpty()) { // Mention r; // r.setMentionName(str); // r.setUserNames(users); // mMentions.append(r); // } // } } bool Mentions::operator ==(const Mentions &other) const { - //return mMentions == other.mentions(); - //FIXME - return false; + return mMentions == other.mentions(); } QDebug operator <<(QDebug d, const Mentions &t) { for (int i = 0; i < t.mentions().count(); i++) { d << t.mentions().at(i); } return d; } QJsonObject Mentions::serialize(const Mentions &mentions) { QJsonObject obj; // for (int i = 0; i < mentions.mentions().count(); ++i) { // QJsonObject react; // react[QLatin1String("usernames")] = QJsonArray::fromStringList(mentions.mentions().at(i).userNames()); // obj[mentions.mentions().at(i).mentionName()] = react; // } return obj; } Mentions Mentions::fromJSon(const QJsonObject &o) { // QVector reacts; // const QStringList lst = o.keys(); // QStringList users; // for (const QString &str : lst) { // const QJsonObject obj = o.value(str).toObject(); // QJsonValue usernames = obj.value(QLatin1String("usernames")); // if (!usernames.isUndefined()) { // QJsonArray array = usernames.toArray(); // for (int i = 0; i < array.count(); ++i) { // users.append(array.at(i).toString()); // } // } // if (!users.isEmpty()) { // Mention r; // r.setMentionName(str); // r.setUserNames(users); // reacts.append(r); // } // users.clear(); // } // Mentions final; // final.setMentions(reacts); // return final; return {}; } bool Mentions::isEmpty() const { return mMentions.isEmpty(); }