Fix a bug that avatar does not show after a state event.

This commit is contained in:
Black Hat 2018-09-10 19:46:04 +08:00
parent e6beb5f6a8
commit 63c7601942
3 changed files with 21 additions and 12 deletions

View File

@ -7,7 +7,7 @@ import Matrique.Settings 0.1
import "qrc:/js/util.js" as Util
RowLayout {
readonly property bool avatarVisible: !(sentByMe || (aboveAuthor === author && section === aboveSection))
readonly property bool avatarVisible: !sentByMe && (aboveAuthor !== author || aboveSection !== section || aboveEventType === "state" || aboveEventType === "emote")
readonly property bool highlighted: !(sentByMe || eventType === "notice" )
readonly property bool sentByMe: author === currentRoom.localUser
readonly property bool isText: eventType === "notice" || eventType === "message"

View File

@ -15,6 +15,7 @@
QHash<int, QByteArray> MessageEventModel::roleNames() const {
QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
roles[EventTypeRole] = "eventType";
roles[AboveEventTypeRole] = "aboveEventType";
roles[EventIdRole] = "eventId";
roles[TimeRole] = "time";
roles[AboveTimeRole] = "aboveTime";
@ -77,7 +78,8 @@ void MessageEventModel::setRoom(MatriqueRoom* room) {
auto rowBelowInserted = m_currentRoom->maxTimelineIndex() -
biggest + timelineBaseIndex() - 1;
refreshEventRoles(rowBelowInserted,
{AboveAuthorRole, AboveSectionRole});
{AboveEventTypeRole, AboveAuthorRole,
AboveSectionRole, AboveTimeRole});
}
for (auto i = m_currentRoom->maxTimelineIndex() - biggest;
i <= m_currentRoom->maxTimelineIndex() - lowest; ++i)
@ -107,7 +109,8 @@ void MessageEventModel::setRoom(MatriqueRoom* room) {
refreshEventRoles(timelineBaseIndex() + 1, {ReadMarkerRole});
if (timelineBaseIndex() > 0) // Refresh below, see #312
refreshEventRoles(timelineBaseIndex() - 1,
{AboveAuthorRole, AboveSectionRole});
{AboveEventTypeRole, AboveAuthorRole,
AboveSectionRole, AboveTimeRole});
});
connect(m_currentRoom, &Room::pendingEventChanged, this,
&MessageEventModel::refreshRow);
@ -621,14 +624,20 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const {
return role == TimeRole ? QVariant(ts) : renderDate(ts);
}
if (role == AboveSectionRole || role == AboveAuthorRole ||
role == AboveTimeRole)
if (role == AboveEventTypeRole || role == AboveSectionRole ||
role == AboveAuthorRole || role == AboveTimeRole)
for (auto r = row + 1; r < rowCount(); ++r) {
auto i = index(r);
if (data(i, SpecialMarksRole) != EventStatus::Hidden)
return data(i, role == AboveSectionRole
? SectionRole
: role == AboveAuthorRole ? AuthorRole : TimeRole);
if (data(i, SpecialMarksRole) != EventStatus::Hidden) switch (role) {
case AboveEventTypeRole:
return data(i, EventTypeRole);
case AboveSectionRole:
return data(i, SectionRole);
case AboveAuthorRole:
return data(i, AuthorRole);
case AboveTimeRole:
return data(i, TimeRole);
}
}
return {};

View File

@ -1,19 +1,19 @@
#ifndef MESSAGEEVENTMODEL_H
#define MESSAGEEVENTMODEL_H
#include "room.h"
#include "matriqueroom.h"
#include "room.h"
#include <QtCore/QAbstractListModel>
class MessageEventModel : public QAbstractListModel {
Q_OBJECT
Q_PROPERTY(
MatriqueRoom* room READ getRoom WRITE setRoom NOTIFY roomChanged)
Q_PROPERTY(MatriqueRoom* room READ getRoom WRITE setRoom NOTIFY roomChanged)
public:
enum EventRoles {
EventTypeRole = Qt::UserRole + 1,
AboveEventTypeRole,
EventIdRole,
TimeRole,
AboveTimeRole,