Fix null errors in qml

master
Nicolas Werner 4 years ago
parent 77e241b9e5
commit b05c101021
  1. 2
      resources/qml/Avatar.qml
  2. 13
      resources/qml/TimelineView.qml
  3. 2
      resources/qml/delegates/MessageDelegate.qml
  4. 2
      resources/qml/delegates/Reply.qml
  5. 18
      src/timeline/TimelineModel.cpp
  6. 1
      src/timeline/TimelineModel.h
  7. 6
      src/timeline/TimelineViewManager.cpp
  8. 1
      src/timeline/TimelineViewManager.h

@ -14,7 +14,7 @@ Rectangle {
Label { Label {
anchors.fill: parent anchors.fill: parent
text: chat.model.escapeEmoji(String.fromCodePoint(displayName.codePointAt(0))) text: timelineManager.escapeEmoji(String.fromCodePoint(displayName.codePointAt(0)))
textFormat: Text.RichText textFormat: Text.RichText
font.pixelSize: avatar.height/2 font.pixelSize: avatar.height/2
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter

@ -167,8 +167,9 @@ Page {
width: avatarSize width: avatarSize
height: avatarSize height: avatarSize
url: chat.model.roomAvatarUrl.replace("mxc://", "image://MxcImage/")
displayName: chat.model.roomName url: chat.model ? chat.model.roomAvatarUrl.replace("mxc://", "image://MxcImage/") : ""
displayName: chat.model ? chat.model.roomName : qsTr("No room selected")
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
@ -182,7 +183,8 @@ Page {
Layout.row: 0 Layout.row: 0
font.pointSize: fontMetrics.font.pointSize * 1.1 font.pointSize: fontMetrics.font.pointSize * 1.1
text: chat.model.roomName
text: chat.model ? chat.model.roomName : qsTr("No room selected")
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
@ -193,9 +195,10 @@ Page {
Layout.fillWidth: true Layout.fillWidth: true
Layout.column: 2 Layout.column: 2
Layout.row: 1 Layout.row: 1
text: chat.model.roomTopic
Layout.maximumHeight: fontMetrics.lineSpacing * 2 // show 2 lines Layout.maximumHeight: fontMetrics.lineSpacing * 2 // show 2 lines
clip: true clip: true
text: chat.model ? chat.model.roomTopic : ""
} }
ImageButton { ImageButton {
@ -387,7 +390,7 @@ Page {
Label { Label {
id: userName id: userName
text: chat.model.escapeEmoji(modelData.userName) text: timelineManager.escapeEmoji(modelData.userName)
color: timelineManager.userColor(modelData.userId, colors.window) color: timelineManager.userColor(modelData.userId, colors.window)
textFormat: Text.RichText textFormat: Text.RichText

@ -36,7 +36,7 @@ Item {
DelegateChoice { DelegateChoice {
roleValue: MtxEvent.EmoteMessage roleValue: MtxEvent.EmoteMessage
NoticeMessage { NoticeMessage {
formatted: chat.model.escapeEmoji(modelData.userName) + " " + model.data.formattedBody formatted: timelineManager.escapeEmoji(modelData.userName) + " " + model.data.formattedBody
color: timelineManager.userColor(modelData.userId, colors.window) color: timelineManager.userColor(modelData.userId, colors.window)
} }
} }

@ -37,7 +37,7 @@ Item {
Text { Text {
id: userName id: userName
text: chat.model ? chat.model.escapeEmoji(reply.modelData.userName) : "" text: timelineManager.escapeEmoji(reply.modelData.userName)
color: replyComponent.userColor color: replyComponent.userColor
textFormat: Text.RichText textFormat: Text.RichText

@ -719,12 +719,6 @@ TimelineModel::formatDateSeparator(QDate date) const
return date.toString(fmt); return date.toString(fmt);
} }
QString
TimelineModel::escapeEmoji(QString str) const
{
return utils::replaceEmoji(str);
}
void void
TimelineModel::viewRawMessage(QString id) const TimelineModel::viewRawMessage(QString id) const
{ {
@ -1389,7 +1383,7 @@ TimelineModel::formatTypingUsers(const std::vector<QString> &users, QColor bg)
QStringList uidWithoutLast; QStringList uidWithoutLast;
auto formatUser = [this, bg](const QString &user_id) -> QString { auto formatUser = [this, bg](const QString &user_id) -> QString {
auto uncoloredUsername = escapeEmoji(displayName(user_id)); auto uncoloredUsername = utils::replaceEmoji(displayName(user_id));
QString prefix = QString prefix =
QString("<font color=\"%1\">").arg(manager_->userColor(user_id, bg).name()); QString("<font color=\"%1\">").arg(manager_->userColor(user_id, bg).name());
@ -1439,7 +1433,7 @@ TimelineModel::formatJoinRuleEvent(QString id)
return ""; return "";
QString user = QString::fromStdString(event->sender); QString user = QString::fromStdString(event->sender);
QString name = escapeEmoji(displayName(user)); QString name = utils::replaceEmoji(displayName(user));
switch (event->content.join_rule) { switch (event->content.join_rule) {
case mtx::events::state::JoinRule::Public: case mtx::events::state::JoinRule::Public:
@ -1464,7 +1458,7 @@ TimelineModel::formatGuestAccessEvent(QString id)
return ""; return "";
QString user = QString::fromStdString(event->sender); QString user = QString::fromStdString(event->sender);
QString name = escapeEmoji(displayName(user)); QString name = utils::replaceEmoji(displayName(user));
switch (event->content.guest_access) { switch (event->content.guest_access) {
case mtx::events::state::AccessState::CanJoin: case mtx::events::state::AccessState::CanJoin:
@ -1489,7 +1483,7 @@ TimelineModel::formatHistoryVisibilityEvent(QString id)
return ""; return "";
QString user = QString::fromStdString(event->sender); QString user = QString::fromStdString(event->sender);
QString name = escapeEmoji(displayName(user)); QString name = utils::replaceEmoji(displayName(user));
switch (event->content.history_visibility) { switch (event->content.history_visibility) {
case mtx::events::state::Visibility::WorldReadable: case mtx::events::state::Visibility::WorldReadable:
@ -1522,7 +1516,7 @@ TimelineModel::formatPowerLevelEvent(QString id)
return ""; return "";
QString user = QString::fromStdString(event->sender); QString user = QString::fromStdString(event->sender);
QString name = escapeEmoji(displayName(user)); QString name = utils::replaceEmoji(displayName(user));
// TODO: power levels rendering is actually a bit complex. work on this later. // TODO: power levels rendering is actually a bit complex. work on this later.
return tr("%1 has changed the room's permissions.").arg(name); return tr("%1 has changed the room's permissions.").arg(name);
@ -1551,7 +1545,7 @@ TimelineModel::formatMemberEvent(QString id)
} }
QString user = QString::fromStdString(event->state_key); QString user = QString::fromStdString(event->state_key);
QString name = escapeEmoji(displayName(user)); QString name = utils::replaceEmoji(displayName(user));
QString rendered; QString rendered;
// see table https://matrix.org/docs/spec/client_server/latest#m-room-member // see table https://matrix.org/docs/spec/client_server/latest#m-room-member

@ -197,7 +197,6 @@ public:
Q_INVOKABLE QString formatGuestAccessEvent(QString id); Q_INVOKABLE QString formatGuestAccessEvent(QString id);
Q_INVOKABLE QString formatPowerLevelEvent(QString id); Q_INVOKABLE QString formatPowerLevelEvent(QString id);
Q_INVOKABLE QString escapeEmoji(QString str) const;
Q_INVOKABLE void viewRawMessage(QString id) const; Q_INVOKABLE void viewRawMessage(QString id) const;
Q_INVOKABLE void viewDecryptedRawMessage(QString id) const; Q_INVOKABLE void viewDecryptedRawMessage(QString id) const;
Q_INVOKABLE void openUserProfile(QString userid) const; Q_INVOKABLE void openUserProfile(QString userid) const;

@ -206,6 +206,12 @@ TimelineViewManager::setHistoryView(const QString &room_id)
} }
} }
QString
TimelineViewManager::escapeEmoji(QString str) const
{
return utils::replaceEmoji(str);
}
void void
TimelineViewManager::openImageOverlay(QString mxcUrl, QString eventId) const TimelineViewManager::openImageOverlay(QString mxcUrl, QString eventId) const
{ {

@ -50,6 +50,7 @@ public:
bool isNarrowView() const { return isNarrowView_; } bool isNarrowView() const { return isNarrowView_; }
Q_INVOKABLE void openImageOverlay(QString mxcUrl, QString eventId) const; Q_INVOKABLE void openImageOverlay(QString mxcUrl, QString eventId) const;
Q_INVOKABLE QColor userColor(QString id, QColor background); Q_INVOKABLE QColor userColor(QString id, QColor background);
Q_INVOKABLE QString escapeEmoji(QString str) const;
Q_INVOKABLE QString userPresence(QString id) const; Q_INVOKABLE QString userPresence(QString id) const;
Q_INVOKABLE QString userStatus(QString id) const; Q_INVOKABLE QString userStatus(QString id) const;

Loading…
Cancel
Save