aboutsummaryrefslogtreecommitdiff
path: root/lib/eventitem.cpp
blob: 302ae053ec14e00095f1be6c454a702c4a1df1c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// SPDX-FileCopyrightText: 2018 Kitsune Ral <kitsune-ral@users.sf.net>
// SPDX-License-Identifier: LGPL-2.1-or-later

#include "eventitem.h"

#include "events/roomavatarevent.h"
#include "events/roommessageevent.h"

using namespace Quotient;

void PendingEventItem::setFileUploaded(const QUrl& remoteUrl)
{
    // TODO: eventually we might introduce hasFileContent to RoomEvent,
    // and unify the code below.
    if (auto* rme = getAs<RoomMessageEvent>()) {
        Q_ASSERT(rme->hasFileContent());
        rme->editContent([remoteUrl](EventContent::TypedBase& ec) {
            ec.fileInfo()->url = remoteUrl;
        });
    }
    if (auto* rae = getAs<RoomAvatarEvent>()) {
        Q_ASSERT(rae->content().fileInfo());
        rae->editContent(
            [remoteUrl](EventContent::FileInfo& fi) { fi.url = remoteUrl; });
    }
    setStatus(EventStatus::FileUploaded);
}

void PendingEventItem::setEncryptedFile(const EncryptedFile& encryptedFile)
{
    if (auto* rme = getAs<RoomMessageEvent>()) {
        Q_ASSERT(rme->hasFileContent());
        rme->editContent([encryptedFile](EventContent::TypedBase& ec) {
            ec.fileInfo()->file = encryptedFile;
        });
    }
}

// Not exactly sure why but this helps with the linker not finding
// Quotient::EventStatus::staticMetaObject when building Quaternion
#include "moc_eventitem.cpp"