Skip to content

Commit 7371f8d

Browse files
committed
Persist txnId to ensure idempotency
1 parent 79aefe9 commit 7371f8d

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

src/models/event.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export const MatrixEvent = function(
168168
/* The txnId with which this event was sent if it was during this session,
169169
allows for a unique ID which does not change when the event comes back down sync.
170170
*/
171-
this._txnId = null;
171+
this._txnId = event.txn_id || null;
172172

173173
/* Set an approximate timestamp for the event relative the local clock.
174174
* This will inherently be approximate because it doesn't take into account
@@ -1098,6 +1098,7 @@ utils.extend(MatrixEvent.prototype, {
10981098
origin_server_ts: this.getTs(),
10991099
unsigned: this.getUnsigned(),
11001100
room_id: this.getRoomId(),
1101+
txn_id: this.getTxnId(),
11011102
};
11021103

11031104
// if this is a redaction then attach the redacts key

src/models/room.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,9 @@ export function Room(roomId, client, myUserId, opts) {
195195
if (serializedPendingEventList) {
196196
JSON.parse(serializedPendingEventList)
197197
.forEach(serializedEvent => {
198-
const txnId = client.makeTxnId();
199198
const event = new MatrixEvent(serializedEvent);
200199
event.setStatus(EventStatus.NOT_SENT);
201-
event.setTxnId(txnId);
202-
this.addPendingEvent(event, txnId);
200+
this.addPendingEvent(event, event.getTxnId());
203201
});
204202
}
205203
}

0 commit comments

Comments
 (0)