chore: add transactionId getter to Event class

This commit is contained in:
Karthikeyan S 2025-01-08 23:07:32 +05:30
parent a6ee302d64
commit 64030693c9
No known key found for this signature in database
GPG Key ID: 28BA6AEE539ECE2E
3 changed files with 11 additions and 13 deletions

View File

@ -1155,8 +1155,7 @@ class MatrixSdkDatabase extends DatabaseApi with DatabaseFileStorage {
final eventId = timelineEvent.eventId; final eventId = timelineEvent.eventId;
// In case this event has sent from this account we have a transaction ID // In case this event has sent from this account we have a transaction ID
final transactionId = final transactionId = timelineEvent.transactionId;
timelineEvent.unsigned?.tryGet<String>('transaction_id');
await _eventsBox.put( await _eventsBox.put(
TupleKey(roomId, eventId).toString(), TupleKey(roomId, eventId).toString(),
timelineEvent.toJson(), timelineEvent.toJson(),

View File

@ -78,6 +78,8 @@ class Event extends MatrixEvent {
MatrixEvent? get originalSource => _originalSource; MatrixEvent? get originalSource => _originalSource;
String? get transactionId => unsigned?.tryGet<String>('transaction_id');
Event({ Event({
this.status = defaultStatus, this.status = defaultStatus,
required Map<String, dynamic> super.content, required Map<String, dynamic> super.content,
@ -439,10 +441,9 @@ class Event extends MatrixEvent {
final inReplyTo = credentials.inReplyTo == null final inReplyTo = credentials.inReplyTo == null
? null ? null
: await room.getEventById(credentials.inReplyTo!); : await room.getEventById(credentials.inReplyTo!);
txid ??= unsigned?.tryGet<String>('transaction_id');
return await room.sendFileEvent( return await room.sendFileEvent(
file, file,
txid: txid, txid: txid ?? transactionId,
thumbnail: thumbnail, thumbnail: thumbnail,
inReplyTo: inReplyTo, inReplyTo: inReplyTo,
editEventId: credentials.editEventId, editEventId: credentials.editEventId,
@ -455,7 +456,7 @@ class Event extends MatrixEvent {
// in the `sendEvent` method to transition -1 -> 0 -> 1 -> 2 // in the `sendEvent` method to transition -1 -> 0 -> 1 -> 2
return await room.sendEvent( return await room.sendEvent(
content, content,
txid: txid ?? unsigned?.tryGet<String>('transaction_id') ?? eventId, txid: txid ?? transactionId ?? eventId,
); );
} }
@ -967,7 +968,7 @@ class Event extends MatrixEvent {
if (eventId == search) { if (eventId == search) {
return true; return true;
} }
return unsigned?['transaction_id'] == search; return transactionId == search;
} }
/// Get the relationship type of an event. `null` if there is none /// Get the relationship type of an event. `null` if there is none

View File

@ -473,7 +473,7 @@ class Timeline {
for (i = 0; i < events.length; i++) { for (i = 0; i < events.length; i++) {
final searchHaystack = <String>{events[i].eventId}; final searchHaystack = <String>{events[i].eventId};
final txnid = events[i].unsigned?.tryGet<String>('transaction_id'); final txnid = events[i].transactionId;
if (txnid != null) { if (txnid != null) {
searchHaystack.add(txnid); searchHaystack.add(txnid);
} }
@ -489,9 +489,7 @@ class Timeline {
(e) => (e) =>
e.matchesEventOrTransactionId(event.eventId) || e.matchesEventOrTransactionId(event.eventId) ||
event.unsigned != null && event.unsigned != null &&
e.matchesEventOrTransactionId( e.matchesEventOrTransactionId(event.transactionId),
event.unsigned?.tryGet<String>('transaction_id'),
),
); );
} }
@ -516,8 +514,8 @@ class Timeline {
void removeAggregatedEvent(Event event) { void removeAggregatedEvent(Event event) {
aggregatedEvents.remove(event.eventId); aggregatedEvents.remove(event.eventId);
if (event.unsigned != null) { if (event.transactionId != null) {
aggregatedEvents.remove(event.unsigned?['transaction_id']); aggregatedEvents.remove(event.transactionId);
} }
for (final types in aggregatedEvents.values) { for (final types in aggregatedEvents.values) {
for (final events in types.values) { for (final events in types.values) {
@ -548,7 +546,7 @@ class Timeline {
final i = _findEvent( final i = _findEvent(
event_id: event.eventId, event_id: event.eventId,
unsigned_txid: event.unsigned?.tryGet<String>('transaction_id'), unsigned_txid: event.transactionId,
); );
if (i < events.length) { if (i < events.length) {