aboutsummaryrefslogtreecommitdiff
path: root/events/event.h
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2016-09-14 09:49:53 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2016-09-16 23:28:14 +0900
commite2b19b832907325ea7580d3f3ad4679e473dbbea (patch)
tree25ad3e2a543de417823f841427e9f9fb9eb6a4cb /events/event.h
parent53a941afe548be49585aadda336c0e4c05ff3ff1 (diff)
downloadlibquotient-e2b19b832907325ea7580d3f3ad4679e473dbbea.tar.gz
libquotient-e2b19b832907325ea7580d3f3ad4679e473dbbea.zip
Room: change the way messages are ordered
This replaces the one-by-one timestamp-ordering algorithm of adding new messages with copying the whole group of just-arrived messages to either the beginning or the end of the timeline. Since origin timestamps do not provide a reasonable order, findInsertionPos() is entirely deleted. processMessageEvent() is replaced by two functions: addNewMessageEvents() appends at messageEvents.end() while addHistoricalMessageEvents() inserts them at messageEvents.begin(). There's no official way to insert messages in the middle; cases when getPreviousContent() is called in parallel or a RoomMessagesJob runs on a gap somewhere in the middle of the timeline weren't considered before this commit and aren't considered in it. The new ordering requires you to understand where you have got your events from (or rather, where you want to insert them). In particular, updateData() that processes /sync results uses addNewMessageEvents(); getPreviousContent() calls addHistoricalMessageEvents(). In order to notify clients, a single newMessages() signal gives way to 3 new signals: 2 aboutToAdd*Messages() and a common addedMessages(). In addition, clients can derive from Room and use doAdd*Messages() virtual functions to alter/extend the behaviour.
Diffstat (limited to 'events/event.h')
-rw-r--r--events/event.h25
1 files changed, 2 insertions, 23 deletions
diff --git a/events/event.h b/events/event.h
index a66f5e68..6b566be0 100644
--- a/events/event.h
+++ b/events/event.h
@@ -35,7 +35,7 @@ namespace QMatrixClient
RoomMessage, RoomName, RoomAliases, RoomCanonicalAlias,
RoomMember, RoomTopic, Typing, Receipt, Unknown
};
-
+
class Event
{
public:
@@ -61,28 +61,7 @@ namespace QMatrixClient
};
using Events = QVector<Event*>;
- Events eventsFromJson(const QJsonArray& contents);
-
- /**
- * Finds a place in the timeline where a new event/message could be inserted.
- * @return an iterator to an item with the earliest timestamp after
- * the one of 'item'; or timeline.end(), if all events are earlier
- */
- template <class ItemT, class ContT>
- typename ContT::iterator
- findInsertionPos(ContT & timeline, const ItemT *item)
- {
- return std::lower_bound (timeline.begin(), timeline.end(), item,
- [](const typename ContT::value_type a, const ItemT * b) {
- // FIXME: We should not order the message list by origin timestamp.
- // Rather, an order of receiving should be used (which actually
- // poses a question on whether this method is needed at all -
- // or we'd just prepend and append, depending on whether we
- // received something from /sync or from /messages.
- return a->timestamp() < b->timestamp();
- }
- );
- }
+ Events eventsFromJson(const QJsonArray& json);
/**
* @brief Lookup a value by a key in a varargs list