Show a map for location events

This commit is contained in:
Tobias Fella
2023-03-24 13:52:17 +00:00
parent 0c985a0af1
commit fb24ffd20d
6 changed files with 102 additions and 0 deletions

View File

@@ -69,6 +69,8 @@ QHash<int, QByteArray> MessageEventModel::roleNames() const
roles[IsRedactedRole] = "isRedacted";
roles[GenericDisplayRole] = "genericDisplay";
roles[IsPendingRole] = "isPending";
roles[LatitudeRole] = "latitude";
roles[LongitudeRole] = "longitude";
return roles;
}
@@ -510,6 +512,8 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
return DelegateType::Audio;
case MessageEventType::Video:
return DelegateType::Video;
case MessageEventType::Location:
return DelegateType::Location;
default:
break;
}
@@ -564,6 +568,9 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
}
if (auto e = eventCast<const RoomMessageEvent>(&evt)) {
if(e->msgtype() == Quotient::MessageEventType::Location) {
return e->contentJson();
}
// Cannot use e.contentJson() here because some
// EventContent classes inject values into the copy of the
// content JSON stored in EventContent::Base
@@ -810,6 +817,24 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
return false;
}
if (role == LatitudeRole) {
const auto geoUri = evt.contentJson()["geo_uri"_ls].toString();
if (geoUri.isEmpty()) {
return {};
}
const auto latitude = geoUri.split(u':')[1].split(u',')[0];
return latitude.toFloat();
}
if (role == LongitudeRole) {
const auto geoUri = evt.contentJson()["geo_uri"_ls].toString();
if (geoUri.isEmpty()) {
return {};
}
const auto latitude = geoUri.split(u':')[1].split(u',')[1];
return latitude.toFloat();
}
if (role == ReadMarkersRole) {
#ifdef QUOTIENT_07
auto userIds = room()->userIdsAtEvent(evt.id());

View File

@@ -26,6 +26,7 @@ public:
Encrypted,
ReadMarker,
Poll,
Location,
Other,
};
Q_ENUM(DelegateType);
@@ -75,6 +76,8 @@ public:
AuthorDisplayNameRole,
IsRedactedRole,
IsPendingRole,
LatitudeRole,
LongitudeRole,
LastRole, // Keep this last
};
Q_ENUM(EventRoles)