Extend LocationsModel to include asset and auther roles
Needed for compatibility with the standard map marker.
This commit is contained in:
@@ -54,7 +54,7 @@ void LocationsModel::addLocation(const RoomMessageEvent *event)
|
|||||||
.eventId = event->id(),
|
.eventId = event->id(),
|
||||||
.latitude = latitude,
|
.latitude = latitude,
|
||||||
.longitude = longitude,
|
.longitude = longitude,
|
||||||
.text = event->contentJson()["body"].toString(),
|
.content = event->contentJson(),
|
||||||
.author = dynamic_cast<NeoChatUser *>(m_room->user(event->senderId())),
|
.author = dynamic_cast<NeoChatUser *>(m_room->user(event->senderId())),
|
||||||
};
|
};
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
@@ -80,6 +80,8 @@ QHash<int, QByteArray> LocationsModel::roleNames() const
|
|||||||
{LongitudeRole, "longitude"},
|
{LongitudeRole, "longitude"},
|
||||||
{LatitudeRole, "latitude"},
|
{LatitudeRole, "latitude"},
|
||||||
{TextRole, "text"},
|
{TextRole, "text"},
|
||||||
|
{AssetRole, "asset"},
|
||||||
|
{AuthorRole, "author"},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +93,11 @@ QVariant LocationsModel::data(const QModelIndex &index, int roleName) const
|
|||||||
} else if (roleName == LatitudeRole) {
|
} else if (roleName == LatitudeRole) {
|
||||||
return m_locations[row].latitude;
|
return m_locations[row].latitude;
|
||||||
} else if (roleName == TextRole) {
|
} else if (roleName == TextRole) {
|
||||||
return m_locations[row].text;
|
return m_locations[row].content["body"_ls].toString();
|
||||||
|
} else if (roleName == AssetRole) {
|
||||||
|
return m_locations[row].content["org.matrix.msc3488.asset"_ls].toObject()["type"_ls].toString();
|
||||||
|
} else if (roleName == AuthorRole) {
|
||||||
|
return m_room->getUser(m_locations[row].author);
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ public:
|
|||||||
TextRole = Qt::DisplayRole,
|
TextRole = Qt::DisplayRole,
|
||||||
LongitudeRole,
|
LongitudeRole,
|
||||||
LatitudeRole,
|
LatitudeRole,
|
||||||
|
AssetRole,
|
||||||
|
AuthorRole,
|
||||||
};
|
};
|
||||||
Q_ENUM(Roles)
|
Q_ENUM(Roles)
|
||||||
Q_PROPERTY(NeoChatRoom *room READ room WRITE setRoom NOTIFY roomChanged)
|
Q_PROPERTY(NeoChatRoom *room READ room WRITE setRoom NOTIFY roomChanged)
|
||||||
@@ -42,7 +44,7 @@ private:
|
|||||||
QString eventId;
|
QString eventId;
|
||||||
float latitude;
|
float latitude;
|
||||||
float longitude;
|
float longitude;
|
||||||
QString text;
|
QJsonObject content;
|
||||||
NeoChatUser *author;
|
NeoChatUser *author;
|
||||||
};
|
};
|
||||||
QList<LocationData> m_locations;
|
QList<LocationData> m_locations;
|
||||||
|
|||||||
Reference in New Issue
Block a user