diff --git a/src/ruqolacore/CMakeLists.txt b/src/ruqolacore/CMakeLists.txt index cd9c62dc..bc2e5098 100644 --- a/src/ruqolacore/CMakeLists.txt +++ b/src/ruqolacore/CMakeLists.txt @@ -1,162 +1,165 @@ set(Ruqola_ddpapi_SRCS ddpapi/ddpclient.cpp ) set (Ruqola_model_core_srcs model/messagemodel.cpp model/roommodel.cpp model/roomfilterproxymodel.cpp model/usersforroommodel.cpp model/usersforroomfilterproxymodel.cpp model/usersmodel.cpp model/usercompleterfilterproxymodel.cpp model/usercompletermodel.cpp model/statusmodel.cpp model/filesforroommodel.cpp model/filesforroomfilterproxymodel.cpp model/searchchannelmodel.cpp model/searchchannelfilterproxymodel.cpp model/inputcompletermodel.cpp model/loginmethodmodel.cpp model/searchmessagemodel.cpp model/searchmessagefilterproxymodel.cpp model/rocketchataccountmodel.cpp model/rocketchataccountfilterproxymodel.cpp model/emoticonmodel.cpp model/notificationpreferencemodel.cpp ) set(Ruqola_plugins_srcs plugins/pluginauthenticationinterface.cpp plugins/pluginauthentication.cpp ) set(Ruqola_aboutdata_srcs aboutdata/qmlaboutdata.cpp aboutdata/qmlaboutdataauthormodel.cpp ) set (Ruqola_core_srcs ${Ruqola_model_core_srcs} ${Ruqola_plugins_srcs} ${Ruqola_aboutdata_srcs} ${Ruqola_ddpapi_SRCS} authenticationinfo.cpp message.cpp room.cpp roomwrapper.cpp notificationoptionswrapper.cpp ruqola.cpp ruqolautils.cpp rocketchatbackend.cpp notification.cpp messagequeue.cpp rocketchatmessage.cpp typingnotification.cpp changetemporarystatus.cpp user.cpp utils.cpp emoji.cpp emojimanager.cpp clipboardproxy.cpp otr.cpp otrmanager.cpp abstractwebsocket.cpp ruqolawebsocket.cpp messageattachment.cpp messageurl.cpp rocketchataccount.cpp rocketchataccountsettings.cpp ruqolalogger.cpp ruqolaregisterengine.cpp ruqolaserverconfig.cpp rocketchatcache.cpp texthighlighter.cpp textconverter.cpp loadrecenthistorymanager.cpp file.cpp channel.cpp inputtextmanager.cpp authenticationmanager.cpp searchmessage.cpp accountmanager.cpp managerdatapaths.cpp notificationoptions.cpp reactions.cpp reaction.cpp syntaxhighlightingmanager.cpp copyfilejob.cpp emoticon.cpp receivetypingnotificationmanager.cpp serverconfiginfo.cpp notificationpreferences.cpp + + mentions.cpp + mention.cpp ) if (NOT WIN32) set(Ruqola_core_srcs ${Ruqola_core_srcs} unityservicemanager.cpp) endif() ecm_qt_declare_logging_category(Ruqola_core_srcs HEADER ruqola_debug.h IDENTIFIER RUQOLA_LOG CATEGORY_NAME org.kde.ruqola) ecm_qt_declare_logging_category(Ruqola_core_srcs HEADER ruqola_message_debug.h IDENTIFIER RUQOLA_MESSAGE_LOG CATEGORY_NAME org.kde.ruqola.message) ecm_qt_declare_logging_category(Ruqola_core_srcs HEADER ruqola_ddpapi_debug.h IDENTIFIER RUQOLA_DDPAPI_LOG CATEGORY_NAME org.kde.ruqola.ddpapi) ecm_qt_declare_logging_category(Ruqola_core_srcs HEADER ruqola_ddpapi_command_debug.h IDENTIFIER RUQOLA_DDPAPI_COMMAND_LOG CATEGORY_NAME org.kde.ruqola.ddpapi.command) add_library(libruqolacore ${Ruqola_core_srcs}) generate_export_header(libruqolacore BASE_NAME libruqolacore) target_link_libraries(libruqolacore Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Qml Qt5::Quick Qt5::WebSockets Qt5::Network Qt5::NetworkAuth KF5::CoreAddons KF5::I18n KF5::Notifications KF5::SyntaxHighlighting librocketchatrestapi-qt5 ) if (NOT WIN32) target_link_libraries(libruqolacore Qt5::DBus) endif() if (WIN32 OR APPLE) target_link_libraries(libruqolacore KF5::IconThemes) endif() if (Qt5Keychain_FOUND) target_link_libraries(libruqolacore qt5keychain) target_include_directories(libruqolacore PRIVATE ${QTKEYCHAIN_INCLUDE_DIRS}) endif() set_target_properties(libruqolacore PROPERTIES OUTPUT_NAME ruqolacore VERSION ${RUQOLA_LIB_VERSION} SOVERSION ${RUQOLA_LIB_SOVERSION} ) install(TARGETS libruqolacore ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} LIBRARY NAMELINK_SKIP) diff --git a/src/ruqolacore/mention.cpp b/src/ruqolacore/mention.cpp new file mode 100644 index 00000000..37fbf4fc --- /dev/null +++ b/src/ruqolacore/mention.cpp @@ -0,0 +1,31 @@ +/* + 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; +} diff --git a/src/ruqolacore/mention.h b/src/ruqolacore/mention.h new file mode 100644 index 00000000..ad21776c --- /dev/null +++ b/src/ruqolacore/mention.h @@ -0,0 +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 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 new file mode 100644 index 00000000..ae597099 --- /dev/null +++ b/src/ruqolacore/mentions.cpp @@ -0,0 +1,120 @@ +/* + 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; +} + +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(); +} + diff --git a/src/ruqolacore/mentions.h b/src/ruqolacore/mentions.h new file mode 100644 index 00000000..b8711c43 --- /dev/null +++ b/src/ruqolacore/mentions.h @@ -0,0 +1,49 @@ +/* + 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 MENTIONS_H +#define MENTIONS_H + +#include "libruqola_private_export.h" +#include "mention.h" +#include + +class LIBRUQOLACORE_TESTS_EXPORT Mentions +{ +public: + Mentions(); + void setMentions(const QVector &mentions); + Q_REQUIRED_RESULT QVector mentions() const; + + void parseMentions(const QJsonObject &array); + + Q_REQUIRED_RESULT bool operator ==(const Mentions &other) const; + + Q_REQUIRED_RESULT static QJsonObject serialize(const Mentions &mentions); + Q_REQUIRED_RESULT static Mentions fromJSon(const QJsonObject &o); + + Q_REQUIRED_RESULT bool isEmpty() const; + +private: + QVector mMentions; +}; +Q_DECLARE_METATYPE(Mentions) +LIBRUQOLACORE_EXPORT QDebug operator <<(QDebug d, const Mentions &t); + +#endif // MENTIONS_H