[Merge] lp:history-service/staging into lp:history-service
Tiago Salem Herrmann
tiago.herrmann at canonical.com
Wed Nov 23 13:18:00 UTC 2016
Review: Needs Fixing
just two more fixes.
Diff comments:
>
> === modified file 'daemon/historydaemon.cpp'
> --- daemon/historydaemon.cpp 2015-11-20 12:53:49 +0000
> +++ daemon/historydaemon.cpp 2016-11-17 16:39:33 +0000
> @@ -23,20 +23,95 @@
> #include "telepathyhelper_p.h"
> #include "filter.h"
> #include "sort.h"
> +#include "utils_p.h"
>
> #include "pluginmanager.h"
> #include "plugin.h"
> #include "pluginthreadview.h"
> #include "plugineventview.h"
> +#include "textevent.h"
>
> #include <QStandardPaths>
> #include <QCryptographicHash>
> #include <TelepathyQt/CallChannel>
> +#include <TelepathyQt/PendingVariantMap>
> #include <TelepathyQt/ReferencedHandles>
>
> +#include <TelepathyQt/PendingVariant>
> +#include <TelepathyQt/PendingOperation>
> +
> +Q_DECLARE_METATYPE(RolesMap)
> +
> +const constexpr static int AdminRole = 2;
> +
> +enum ChannelGroupChangeReason
> +{
> + ChannelGroupChangeReasonNone = 0,
> + ChannelGroupChangeReasonOffline = 1,
> + ChannelGroupChangeReasonKicked = 2,
> + ChannelGroupChangeReasonBusy = 3,
> + ChannelGroupChangeReasonInvited = 4,
> + ChannelGroupChangeReasonBanned = 5,
> + ChannelGroupChangeReasonError = 6,
> + ChannelGroupChangeReasonInvalidContact = 7,
> + ChannelGroupChangeReasonNoAnswer = 8,
> + ChannelGroupChangeReasonRenamed = 9,
> + ChannelGroupChangeReasonPermissionDenied = 10,
> + ChannelGroupChangeReasonSeparated = 11,
> +
> + // additional enum values not included in original ChannelGroupChangeReason
> + // telepathy enumeration but needed here to provide extra info to client when group
> + // is cancelled
> + ChannelGroupChangeReasonGone = 12,
> + ChannelGroupChangeReasonRejected = 13
> +};
> +
> +const QDBusArgument &operator>>(const QDBusArgument &argument, RolesMap &roles)
> +{
> + argument.beginMap();
> + while ( !argument.atEnd() ) {
> + argument.beginMapEntry();
> + uint key,value;
> + argument >> key >> value;
> + argument.endMapEntry();
> + roles[key] = value;
> + }
> +
> + argument.endMap();
> + return argument;
> +}
> +
> +bool foundAsMemberInThread(const Tp::ContactPtr& contact, QVariantMap thread)
> +{
> + Q_FOREACH (QVariant participant, thread[History::FieldParticipants].toList()) {
> + // found if same identifier and as member into thread info
> + if (History::Utils::compareIds(thread[History::FieldAccountId].toString(),
> + contact->id(),
> + participant.toMap()[History::FieldIdentifier].toString()) &&
> + participant.toMap()[History::FieldParticipantState].toUInt() == History::ParticipantStateRegular)
> + {
> + return true;
> + }
> + }
> + return false;
> +}
> +
> +bool foundInThread(const Tp::ContactPtr& contact, QVariantMap thread)
> +{
> + Q_FOREACH (QVariant participant, thread[History::FieldParticipants].toList()) {
> + if (contact->id() == participant.toMap()[History::FieldIdentifier].toString())
we have to use History::Utils::compareIds() here just like we do in foundAsMemberInThread()
> + {
> + return true;
> + }
> + }
> + return false;
> +}
> +
> HistoryDaemon::HistoryDaemon(QObject *parent)
> : QObject(parent), mCallObserver(this), mTextObserver(this)
> {
> + qRegisterMetaType<HandleRolesMap>();
> + qDBusRegisterMetaType<HandleRolesMap>();
> // get the first plugin
> if (!History::PluginManager::instance()->plugins().isEmpty()) {
> mBackend = History::PluginManager::instance()->plugins().first();
> @@ -707,3 +1188,88 @@
> hash += "#-#" + thread[History::FieldThreadId].toString();
> return hash;
> }
> +
> +QVariantMap HistoryDaemon::getInterfaceProperties(const Tp::AbstractInterface *interface)
> +{
> + QDBusInterface propsInterface(interface->service(), interface->path(), "org.freedesktop.DBus.Properties");
> + QDBusReply<QVariantMap> reply = propsInterface.call("GetAll", interface->interface());
> + if (!reply.isValid()) {
> + qWarning() << "Failed to fetch channel properties for interface" << interface->interface() << reply.error().message();
> + }
> + return reply.value();
> +}
> +
> +void HistoryDaemon::writeInformationEvent(const QVariantMap &thread, History::InformationType type, const QString &subject, const QString &sender, const QString &text)
> +{
> + History::TextEvent historyEvent = History::TextEvent(thread[History::FieldAccountId].toString(),
> + thread[History::FieldThreadId].toString(),
> + QString(QCryptographicHash::hash(QByteArray(
> + (QDateTime::currentDateTime().toString() + subject + text).toLatin1()),
Please use toString("yyyy-MM-ddTHH:mm:ss.zzz") to make it really unique, as subject and text might be empty, and simply using currentDateTime() isn't random enough.
> + QCryptographicHash::Md5).toHex()),
> + sender,
> + QDateTime::currentDateTime(),
> + false,
> + text,
> + History::MessageTypeInformation,
> + History::MessageStatusUnknown,
> + QDateTime::currentDateTime(),
> + subject,
> + type);
> + writeEvents(QList<QVariantMap>() << historyEvent.properties(), thread);
> +}
> +
> +void HistoryDaemon::writeRoomChangesInformationEvents(const QVariantMap &thread, const QVariantMap &interfaceProperties)
> +{
> + if (!thread.isEmpty()) {
> + // group subject
> + QString storedSubject = thread[History::FieldChatRoomInfo].toMap()["Subject"].toString();
> + QString newSubject = interfaceProperties["Subject"].toString();
> + if (!newSubject.isEmpty() && storedSubject != newSubject) {
> + //see if we have an actor. If actor is 'me', we have changed that subject
> + QString actor = thread[History::FieldChatRoomInfo].toMap()["Actor"].toString();
> + if (actor == "me") {
> + actor = "self";
> + }
> + writeInformationEvent(thread, History::InformationTypeTitleChanged, newSubject, actor);
> + }
> + }
> +}
> +
> +void HistoryDaemon::writeRolesInformationEvents(const QVariantMap &thread, const Tp::ChannelPtr &channel, const RolesMap &rolesMap)
> +{
> + if (thread.isEmpty()) {
> + return;
> + }
> +
> + if (!thread[History::FieldChatRoomInfo].toMap()["Joined"].toBool()) {
> + return;
> + }
> +
> + // list of identifiers for current channel admins
> + QStringList adminIds;
> +
> + Q_FOREACH(const Tp::ContactPtr contact, channel->groupContacts(false)) {
> + // see if admin role (ChannelAdminRole == 2)
> + if (rolesMap[contact->handle().at(0)] & AdminRole) {
> + adminIds << contact->id();
> + }
> + }
> +
> + Q_FOREACH (QVariant participant, thread[History::FieldParticipants].toList()) {
> + QString participantId = participant.toMap()[History::FieldIdentifier].toString();
> + if (adminIds.contains(participantId)) {
> + // see if already was admin or not (ChannelAdminRole == 2)
> + if (! (participant.toMap()[History::FieldParticipantRoles].toUInt() & AdminRole)) {
> + writeInformationEvent(thread, History::InformationTypeAdminGranted, participantId);
> + }
> + }
> + }
> +
> + //evaluate now self roles
> + if (rolesMap[channel->groupSelfContact()->handle().at(0)] & AdminRole) {
> + uint selfRoles = thread[History::FieldChatRoomInfo].toMap()["SelfRoles"].toUInt();
> + if (! (selfRoles & AdminRole)) {
> + writeInformationEvent(thread, History::InformationTypeSelfAdminGranted);
> + }
> + }
> +}
--
https://code.launchpad.net/~phablet-team/history-service/staging/+merge/308933
Your team Ubuntu Phablet Team is subscribed to branch lp:history-service.
More information about the Ubuntu-reviews
mailing list