~ci-train-bot/history-service/history-service-ubuntu-zesty-2629

« back to all changes in this revision

Viewing changes to src/managerdbus.cpp

  • Committer: Bileto Bot
  • Author(s): Gustavo Pichorim Boiko
  • Date: 2017-03-23 01:28:52 UTC
  • mfrom: (230.2.35 staging)
  • Revision ID: ci-train-bot@canonical.com-20170323012852-vzmjcare13zofbna
- Adapt to support VOIP accounts.
- Improve the notifications of participants changing
- Only start saving information events about contacts joining and leaving after the self contact is in the local list of participants.
- Improve Roles management performance by caching the retrieved data.
- Mark entire conversations as read.
- Allow pass multiple fields on sort clause.
- Reduce the dbus traffic when marking messages and threads as read.
- Use a QLockFile to ensure there will be only one instance of the daemon per user. As we now delay the registration on dbus, sometimes we ended up having two instances of the daeon running (because of dbus activation). This change makes sure that won't happen.
- Do not load the participants from threads automatically. If the client really needs it, it can use the newly added API to fetch the participants.
- Make it possible to debug sqlite commands.

Approved by: system-apps-ci-bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include <QDBusReply>
29
29
#include <QDBusMetaType>
30
30
 
 
31
#include <QDebug>
 
32
 
31
33
Q_DECLARE_METATYPE(QList< QVariantMap >)
32
34
 
33
35
namespace History
50
52
    connection.connect(DBusService, DBusObjectPath, DBusInterface, "ThreadsRemoved",
51
53
                       this, SLOT(onThreadsRemoved(QList<QVariantMap>)));
52
54
 
 
55
    connection.connect(DBusService, DBusObjectPath, DBusInterface, "ThreadParticipantsChanged",
 
56
                       this, SLOT(onThreadParticipantsChanged(QVariantMap,
 
57
                                                        QList<QVariantMap>,
 
58
                                                        QList<QVariantMap>,
 
59
                                                        QList<QVariantMap>)));
 
60
 
53
61
    connection.connect(DBusService, DBusObjectPath, DBusInterface, "EventsAdded",
54
62
                       this, SLOT(onEventsAdded(QList<QVariantMap>)));
55
63
    connection.connect(DBusService, DBusObjectPath, DBusInterface, "EventsModified",
70
78
    return threadForProperties(accountId, type, properties, matchFlags, create);
71
79
}
72
80
 
 
81
void ManagerDBus::markThreadsAsRead(const History::Threads &threads)
 
82
{
 
83
    QList<QVariantMap> threadMap = threadsToProperties(threads);
 
84
    if (threadMap.isEmpty()) {
 
85
        return;
 
86
    }
 
87
 
 
88
    mInterface.asyncCall("MarkThreadsAsRead", QVariant::fromValue(threadMap));
 
89
}
 
90
 
73
91
Thread ManagerDBus::threadForProperties(const QString &accountId,
74
92
                                        EventType type,
75
93
                                        const QVariantMap &properties,
87
105
    return thread;
88
106
}
89
107
 
 
108
void ManagerDBus::requestThreadParticipants(const Threads &threads)
 
109
{
 
110
    QList<QVariantMap> ids;
 
111
    Q_FOREACH(const Thread &thread, threads) {
 
112
        QVariantMap id;
 
113
        id[History::FieldAccountId] = thread.accountId();
 
114
        id[History::FieldThreadId] = thread.threadId();
 
115
        id[History::FieldType] = thread.type();
 
116
        ids << id;
 
117
    }
 
118
 
 
119
    QDBusPendingCall call = mInterface.asyncCall("ParticipantsForThreads", QVariant::fromValue(ids));
 
120
    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
 
121
    connect(watcher, &QDBusPendingCallWatcher::finished, [this, threads](QDBusPendingCallWatcher *watcher) {
 
122
        QDBusPendingReply<QList<QVariantMap> > reply = *watcher;
 
123
        Q_FOREACH(const QVariantMap &map, reply.value()) {
 
124
            History::Thread thread = History::Thread::fromProperties(map);
 
125
            Q_EMIT threadParticipantsChanged(thread, History::Participants(), History::Participants(), thread.participants());
 
126
            watcher->deleteLater();
 
127
        }
 
128
    });
 
129
}
 
130
 
90
131
bool ManagerDBus::writeEvents(const Events &events)
91
132
{
92
133
    QList<QVariantMap> eventMap = eventsToProperties(events);
108
149
        return false;
109
150
    }
110
151
 
111
 
    QDBusReply<bool> reply = mInterface.call("RemoveThreads", QVariant::fromValue(threadMap));
112
 
    if (!reply.isValid()) {
113
 
        return false;
114
 
    }
115
 
    return reply.value();
 
152
    mInterface.asyncCall("RemoveThreads", QVariant::fromValue(threadMap));
 
153
    return true;
116
154
}
117
155
 
118
156
bool ManagerDBus::removeEvents(const Events &events)
122
160
        return false;
123
161
    }
124
162
 
125
 
    QDBusReply<bool> reply = mInterface.call("RemoveEvents", QVariant::fromValue(eventMap));
126
 
    if (!reply.isValid()) {
127
 
        return false;
128
 
    }
129
 
    return reply.value();
 
163
    mInterface.asyncCall("RemoveEvents", QVariant::fromValue(eventMap));
 
164
    return true;
130
165
}
131
166
 
132
167
Thread ManagerDBus::getSingleThread(EventType type, const QString &accountId, const QString &threadId, const QVariantMap &properties)
168
203
    Q_EMIT threadsRemoved(threadsFromProperties(threads));
169
204
}
170
205
 
 
206
void ManagerDBus::onThreadParticipantsChanged(const QVariantMap &thread,
 
207
                                        const QList<QVariantMap> &added,
 
208
                                        const QList<QVariantMap> &removed,
 
209
                                        const QList<QVariantMap> &modified)
 
210
{
 
211
    Q_EMIT threadParticipantsChanged(threadsFromProperties(QList<QVariantMap>() << thread).first(),
 
212
                               Participants::fromVariantMapList(added),
 
213
                               Participants::fromVariantMapList(removed),
 
214
                               Participants::fromVariantMapList(modified));
 
215
}
 
216
 
171
217
void ManagerDBus::onEventsAdded(const QList<QVariantMap> &events)
172
218
{
173
219
    Q_EMIT eventsAdded(eventsFromProperties(events));