From e2b19b832907325ea7580d3f3ad4679e473dbbea Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Wed, 14 Sep 2016 09:49:53 +0900 Subject: 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. --- room.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'room.h') diff --git a/room.h b/room.h index 8f6a65a6..c64bed6f 100644 --- a/room.h +++ b/room.h @@ -82,13 +82,17 @@ namespace QMatrixClient void userRenamed(User* user, QString oldName); signals: - void newMessage(Event* event); + void aboutToAddHistoricalMessages(const Events& events); + void aboutToAddNewMessages(const Events& events); + void addedMessages(); + /** - * Triggered when the room name, canonical alias or other aliases - * change. Not triggered when displayname changes. + * @brief The room name, the canonical alias or other aliases changed + * + * Not triggered when displayname changes. */ void namesChanged(Room* room); - /** Triggered only for changes in the room displayname. */ + /** @brief The room displayname changed */ void displaynameChanged(Room* room); void topicChanged(); void userAdded(User* user); @@ -101,13 +105,17 @@ namespace QMatrixClient protected: Connection* connection() const; - virtual void processMessageEvent(Event* event); + virtual void doAddNewMessageEvents(const Events& events); + virtual void doAddHistoricalMessageEvents(const Events& events); virtual void processStateEvent(Event* event); virtual void processEphemeralEvent(Event* event); private: class Private; Private* d; + + void addNewMessageEvents(const Events& events); + void addHistoricalMessageEvents(const Events& events); }; } -- cgit v1.2.3