MCPcopy Create free account
hub / github.com/KDE/neochat / ThreadModel

Method ThreadModel

src/messagecontent/models/threadmodel.cpp:17–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15#include "neochatroom.h"
16
17ThreadModel::ThreadModel(const QString &threadRootId, NeoChatRoom *room)
18 : QConcatenateTablesProxyModel()
19 , m_room(room)
20 , m_threadRootId(threadRootId)
21 , m_threadFetchModel(new ThreadFetchModel(this))
22 , m_threadChatBarModel(new ThreadChatBarModel(this, room))
23{
24 Q_ASSERT(!m_threadRootId.isEmpty());
25 Q_ASSERT(room);
26
27 // HACK: Always keep at least one source model in the concatenate model to work around assert
28 addSourceModel(m_threadFetchModel);
29
30 connect(room, &Quotient::Room::pendingEventAdded, this, [this](const Quotient::RoomEvent *event) {
31 if (auto roomEvent = eventCast<const Quotient::RoomMessageEvent>(event)) {
32 if (roomEvent->isThreaded() && roomEvent->threadRootEventId() == m_threadRootId) {
33 addNewEvent(event);
34 addModels();
35 }
36 }
37 });
38 connect(room, &Quotient::Room::aboutToAddNewMessages, this, [this](Quotient::RoomEventsRange events) {
39 for (const auto &event : events) {
40 if (auto roomEvent = eventCast<const Quotient::RoomMessageEvent>(event)) {
41 if (roomEvent->isThreaded() && roomEvent->threadRootEventId() == m_threadRootId) {
42 addNewEvent(roomEvent);
43 }
44 }
45 }
46 addModels();
47 });
48
49 // If the thread was created by the local user fetchMore() won't find the current
50 // pending event.
51 checkPending();
52 fetchMoreEvents(3);
53 addModels();
54}
55
56void ThreadModel::checkPending()
57{

Callers

nothing calls this directly

Calls 2

isEmptyMethod · 0.45
isThreadedMethod · 0.45

Tested by

no test coverage detected