Skip to content

Commit

Permalink
Merge pull request #1998 from famedly/karthi/transactionId
Browse files Browse the repository at this point in the history
chore: add transactionId getter to Event class
  • Loading branch information
td-famedly authored Jan 8, 2025
2 parents a6ee302 + 6403069 commit 8d7b4dd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
3 changes: 1 addition & 2 deletions lib/src/database/matrix_sdk_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1155,8 +1155,7 @@ class MatrixSdkDatabase extends DatabaseApi with DatabaseFileStorage {

final eventId = timelineEvent.eventId;
// In case this event has sent from this account we have a transaction ID
final transactionId =
timelineEvent.unsigned?.tryGet<String>('transaction_id');
final transactionId = timelineEvent.transactionId;
await _eventsBox.put(
TupleKey(roomId, eventId).toString(),
timelineEvent.toJson(),
Expand Down
9 changes: 5 additions & 4 deletions lib/src/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class Event extends MatrixEvent {

MatrixEvent? get originalSource => _originalSource;

String? get transactionId => unsigned?.tryGet<String>('transaction_id');

Event({
this.status = defaultStatus,
required Map<String, dynamic> super.content,
Expand Down Expand Up @@ -439,10 +441,9 @@ class Event extends MatrixEvent {
final inReplyTo = credentials.inReplyTo == null
? null
: await room.getEventById(credentials.inReplyTo!);
txid ??= unsigned?.tryGet<String>('transaction_id');
return await room.sendFileEvent(
file,
txid: txid,
txid: txid ?? transactionId,
thumbnail: thumbnail,
inReplyTo: inReplyTo,
editEventId: credentials.editEventId,
Expand All @@ -455,7 +456,7 @@ class Event extends MatrixEvent {
// in the `sendEvent` method to transition -1 -> 0 -> 1 -> 2
return await room.sendEvent(
content,
txid: txid ?? unsigned?.tryGet<String>('transaction_id') ?? eventId,
txid: txid ?? transactionId ?? eventId,
);
}

Expand Down Expand Up @@ -967,7 +968,7 @@ class Event extends MatrixEvent {
if (eventId == search) {
return true;
}
return unsigned?['transaction_id'] == search;
return transactionId == search;
}

/// Get the relationship type of an event. `null` if there is none
Expand Down
12 changes: 5 additions & 7 deletions lib/src/timeline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ class Timeline {
for (i = 0; i < events.length; i++) {
final searchHaystack = <String>{events[i].eventId};

final txnid = events[i].unsigned?.tryGet<String>('transaction_id');
final txnid = events[i].transactionId;
if (txnid != null) {
searchHaystack.add(txnid);
}
Expand All @@ -489,9 +489,7 @@ class Timeline {
(e) =>
e.matchesEventOrTransactionId(event.eventId) ||
event.unsigned != null &&
e.matchesEventOrTransactionId(
event.unsigned?.tryGet<String>('transaction_id'),
),
e.matchesEventOrTransactionId(event.transactionId),
);
}

Expand All @@ -516,8 +514,8 @@ class Timeline {

void removeAggregatedEvent(Event event) {
aggregatedEvents.remove(event.eventId);
if (event.unsigned != null) {
aggregatedEvents.remove(event.unsigned?['transaction_id']);
if (event.transactionId != null) {
aggregatedEvents.remove(event.transactionId);
}
for (final types in aggregatedEvents.values) {
for (final events in types.values) {
Expand Down Expand Up @@ -548,7 +546,7 @@ class Timeline {

final i = _findEvent(
event_id: event.eventId,
unsigned_txid: event.unsigned?.tryGet<String>('transaction_id'),
unsigned_txid: event.transactionId,
);

if (i < events.length) {
Expand Down

0 comments on commit 8d7b4dd

Please sign in to comment.