Update libqmatrixclient again and some code cleanup.

This commit is contained in:
Black Hat 2018-08-06 23:16:35 +08:00
parent a243d6069a
commit c5a55654a0
4 changed files with 69 additions and 66 deletions

@ -1 +1 @@
Subproject commit c0e75a52504a3d31bcca0d4c39745d4d6c1fe917 Subproject commit c8dc0c075497ca8f174b738ee4253ca282cbec8c

View File

@ -91,27 +91,6 @@ ApplicationWindow {
} }
} }
Dialog {
property alias text: errorLabel.text
id: errorDialog
width: 360
modal: true
title: "ERROR"
x: (window.width - width) / 2
y: (window.height - height) / 2
standardButtons: Dialog.Ok
Label {
id: errorLabel
width: parent.width
text: "Label"
wrapMode: Text.Wrap
}
}
Component { Component {
id: loginPage id: loginPage

View File

@ -60,22 +60,28 @@ void MessageEventModel::setRoom(QMatrixClient::Room* room) {
using namespace QMatrixClient; using namespace QMatrixClient;
connect(m_currentRoom, &Room::aboutToAddNewMessages, this, connect(m_currentRoom, &Room::aboutToAddNewMessages, this,
[=](RoomEventsRange events) { [=](RoomEventsRange events) {
const auto pos = m_currentRoom->pendingEvents().size(); beginInsertRows({}, timelineBaseIndex(),
beginInsertRows(QModelIndex(), int(pos), timelineBaseIndex() + int(events.size()) - 1);
int(pos + events.size() - 1));
}); });
connect(m_currentRoom, &Room::aboutToAddHistoricalMessages, this, connect(m_currentRoom, &Room::aboutToAddHistoricalMessages, this,
[=](RoomEventsRange events) { [=](RoomEventsRange events) {
if (rowCount() > 0) if (rowCount() > 0)
rowBelowInserted = rowCount() - 1; // See #312 rowBelowInserted = rowCount() - 1; // See #312
beginInsertRows(QModelIndex(), rowCount(), beginInsertRows({}, rowCount(),
rowCount() + int(events.size()) - 1); rowCount() + int(events.size()) - 1);
}); });
connect(m_currentRoom, &Room::addedMessages, this, [=] { connect(m_currentRoom, &Room::addedMessages, this,
[=](int lowest, int biggest) {
endInsertRows(); endInsertRows();
if (rowBelowInserted > -1) if (biggest < m_currentRoom->maxTimelineIndex()) {
auto rowBelowInserted = m_currentRoom->maxTimelineIndex() -
biggest + timelineBaseIndex() - 1;
refreshEventRoles(rowBelowInserted, refreshEventRoles(rowBelowInserted,
{AboveAuthorRole, AboveSectionRole}); {AboveAuthorRole, AboveSectionRole});
}
for (auto i = m_currentRoom->maxTimelineIndex() - biggest;
i <= m_currentRoom->maxTimelineIndex() - lowest; ++i)
refreshLastUserEvents(i);
}); });
connect(m_currentRoom, &Room::pendingEventAboutToAdd, this, connect(m_currentRoom, &Room::pendingEventAboutToAdd, this,
[this] { beginInsertRows({}, 0, 0); }); [this] { beginInsertRows({}, 0, 0); });
@ -96,6 +102,7 @@ void MessageEventModel::setRoom(QMatrixClient::Room* room) {
movingEvent = false; movingEvent = false;
} }
refreshRow(timelineBaseIndex()); // Refresh the looks refreshRow(timelineBaseIndex()); // Refresh the looks
refreshLastUserEvents(0);
if (m_currentRoom->timelineSize() > 1) // Refresh above if (m_currentRoom->timelineSize() > 1) // Refresh above
refreshEventRoles(timelineBaseIndex() + 1, {ReadMarkerRole}); refreshEventRoles(timelineBaseIndex() + 1, {ReadMarkerRole});
if (timelineBaseIndex() > 0) // Refresh below, see #312 if (timelineBaseIndex() > 0) // Refresh below, see #312
@ -114,9 +121,11 @@ void MessageEventModel::setRoom(QMatrixClient::Room* room) {
{ReadMarkerRole}); {ReadMarkerRole});
refreshEventRoles(lastReadEventId, {ReadMarkerRole}); refreshEventRoles(lastReadEventId, {ReadMarkerRole});
}); });
connect( connect(m_currentRoom, &Room::replacedEvent, this,
m_currentRoom, &Room::replacedEvent, this, [this](const RoomEvent* newEvent) {
[this](const RoomEvent* newEvent) { refreshEvent(newEvent->id()); }); refreshLastUserEvents(refreshEvent(newEvent->id()) -
timelineBaseIndex());
});
connect(m_currentRoom, &Room::fileTransferProgress, this, connect(m_currentRoom, &Room::fileTransferProgress, this,
&MessageEventModel::refreshEvent); &MessageEventModel::refreshEvent);
connect(m_currentRoom, &Room::fileTransferCompleted, this, connect(m_currentRoom, &Room::fileTransferCompleted, this,
@ -132,8 +141,8 @@ void MessageEventModel::setRoom(QMatrixClient::Room* room) {
endResetModel(); endResetModel();
} }
void MessageEventModel::refreshEvent(const QString& eventId) { int MessageEventModel::refreshEvent(const QString& eventId) {
refreshEventRoles(eventId); return refreshEventRoles(eventId);
} }
void MessageEventModel::refreshRow(int row) { refreshEventRoles(row); } void MessageEventModel::refreshRow(int row) { refreshEventRoles(row); }
@ -147,16 +156,17 @@ void MessageEventModel::refreshEventRoles(int row, const QVector<int>& roles) {
emit dataChanged(idx, idx, roles); emit dataChanged(idx, idx, roles);
} }
void MessageEventModel::refreshEventRoles(const QString& eventId, int MessageEventModel::refreshEventRoles(const QString& eventId,
const QVector<int>& roles) { const QVector<int>& roles) {
const auto it = m_currentRoom->findInTimeline(eventId); const auto it = m_currentRoom->findInTimeline(eventId);
if (it == m_currentRoom->timelineEdge()) { if (it == m_currentRoom->timelineEdge()) {
qWarning() << "Trying to refresh inexistent event:" << eventId; qWarning() << "Trying to refresh inexistent event:" << eventId;
return; return -1;
} }
refreshEventRoles( const auto row =
it - m_currentRoom->messageEvents().rbegin() + timelineBaseIndex(), it - m_currentRoom->messageEvents().rbegin() + timelineBaseIndex();
roles); refreshEventRoles(row, roles);
return row;
} }
inline bool hasValidTimestamp(const QMatrixClient::TimelineItem& ti) { inline bool hasValidTimestamp(const QMatrixClient::TimelineItem& ti) {
@ -210,8 +220,8 @@ bool MessageEventModel::isUserActivityNotable(
bool joinFound = false, redactionsFound = false; bool joinFound = false, redactionsFound = false;
// Find the nearest join of this user above, or a no-nonsense event. // Find the nearest join of this user above, or a no-nonsense event.
for (auto it = baseIt, for (auto it = baseIt,
limit = limit = baseIt +
baseIt + std::min<int>(m_currentRoom->timelineEdge() - baseIt, 100); std::min(int(m_currentRoom->timelineEdge() - baseIt), 100);
it != limit; ++it) { it != limit; ++it) {
const auto& e = **it; const auto& e = **it;
if (e.senderId() != senderId) continue; if (e.senderId() != senderId) continue;
@ -231,9 +241,9 @@ bool MessageEventModel::isUserActivityNotable(
// Find the nearest leave of this user below, or a no-nonsense event // Find the nearest leave of this user below, or a no-nonsense event
bool leaveFound = false; bool leaveFound = false;
for (auto it = baseIt.base() - 1, for (auto it = baseIt.base() - 1,
limit = limit = baseIt.base() +
baseIt.base() + std::min(int(m_currentRoom->messageEvents().end() -
std::min<int>(m_currentRoom->messageEvents().end() - baseIt.base(), baseIt.base()),
100); 100);
it != limit; ++it) { it != limit; ++it) {
const auto& e = **it; const auto& e = **it;
@ -258,6 +268,22 @@ bool MessageEventModel::isUserActivityNotable(
return !(joinFound && leaveFound); // Join + (maybe profile changes) + leave return !(joinFound && leaveFound); // Join + (maybe profile changes) + leave
} }
void MessageEventModel::refreshLastUserEvents(int baseTimelineRow) {
if (!m_currentRoom || m_currentRoom->timelineSize() <= baseTimelineRow)
return;
const auto& timelineBottom = m_currentRoom->messageEvents().rbegin();
const auto& lastSender = (*(timelineBottom + baseTimelineRow))->senderId();
const auto limit = timelineBottom + std::min(baseTimelineRow + 100,
m_currentRoom->timelineSize());
for (auto it = timelineBottom + std::max(baseTimelineRow - 100, 0);
it != limit; ++it) {
if ((*it)->senderId() == lastSender) {
auto idx = index(it - timelineBottom);
emit dataChanged(idx, idx);
}
}
}
int MessageEventModel::rowCount(const QModelIndex& parent) const { int MessageEventModel::rowCount(const QModelIndex& parent) const {
if (!m_currentRoom || parent.isValid()) return 0; if (!m_currentRoom || parent.isValid()) return 0;
return m_currentRoom->timelineSize(); return m_currentRoom->timelineSize();
@ -550,28 +576,25 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const {
!Settings().value("UI/show_joinleave", true).toBool()) !Settings().value("UI/show_joinleave", true).toBool())
return EventStatus::Hidden; return EventStatus::Hidden;
} }
if (evt.isRedacted() || memberEvent) { if (memberEvent || evt.isRedacted()) {
if (evt.senderId() == m_currentRoom->localUser()->id() || if (evt.senderId() == m_currentRoom->localUser()->id() ||
Settings().value("UI/show_spammy").toBool()) { Settings().value("UI/show_spammy").toBool()) {
return EventStatus::Normal; // QElapsedTimer et; et.start();
}
QElapsedTimer et;
et.start();
auto hide = !isUserActivityNotable(timelineIt); auto hide = !isUserActivityNotable(timelineIt);
qDebug() << "Checked user activity for" << evt.id() << "in" << et; // qDebug() << "Checked user activity for" << evt.id() <<
// "in" << et;
if (hide) return EventStatus::Hidden; if (hide) return EventStatus::Hidden;
} }
}
if (evt.isRedacted())
return Settings().value("UI/show_redacted").toBool()
? EventStatus::Redacted : EventStatus::Hidden;
if (evt.isStateEvent() && if (evt.isStateEvent() &&
static_cast<const StateEventBase&>(evt).repeatsState() && static_cast<const StateEventBase&>(evt).repeatsState() &&
!Settings().value("UI/show_noop_events").toBool()) !Settings().value("UI/show_noop_events").toBool())
return EventStatus::Hidden; return EventStatus::Hidden;
if (evt.isRedacted())
return Settings().value("UI/show_redacted").toBool()
? EventStatus::Redacted
: EventStatus::Hidden;
return EventStatus::Normal; return EventStatus::Normal;
} }

View File

@ -43,7 +43,7 @@ class MessageEventModel : public QAbstractListModel {
QHash<int, QByteArray> roleNames() const; QHash<int, QByteArray> roleNames() const;
private slots: private slots:
void refreshEvent(const QString& eventId); int refreshEvent(const QString& eventId);
void refreshRow(int row); void refreshRow(int row);
private: private:
@ -56,11 +56,12 @@ class MessageEventModel : public QAbstractListModel {
QDateTime makeMessageTimestamp( QDateTime makeMessageTimestamp(
const QMatrixClient::Room::rev_iter_t& baseIt) const; const QMatrixClient::Room::rev_iter_t& baseIt) const;
QString renderDate(QDateTime timestamp) const; QString renderDate(QDateTime timestamp) const;
bool isUserActivityNotable(const QMatrixClient::Room::rev_iter_t& baseIt) const; bool isUserActivityNotable(
const QMatrixClient::Room::rev_iter_t& baseIt) const;
void refreshLastUserEvents(int baseRow);
void refreshEventRoles(int row, const QVector<int>& roles = {}); void refreshEventRoles(int row, const QVector<int>& roles = {});
void refreshEventRoles(const QString& eventId, int refreshEventRoles(const QString& eventId, const QVector<int>& roles = {});
const QVector<int>& roles = {});
signals: signals:
void roomChanged(); void roomChanged();