From 15e8784daf20cfee4d824ebe00a4ef37a11038cf Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 25 Jan 2016 17:49:41 +0000 Subject: [PATCH 1/2] Add local echo for read receipts. Fixes https://github.com/vector-im/vector-web/issues/623 --- lib/client.js | 8 +++++++- lib/models/room.js | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/client.js b/lib/client.js index f5d6a74a0..ae98f0482 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1369,9 +1369,15 @@ MatrixClient.prototype.sendReceipt = function(event, receiptType, callback) { $receiptType: receiptType, $eventId: event.getId() }); - return this._http.authedRequestWithPrefix( + var promise = this._http.authedRequestWithPrefix( callback, "POST", path, undefined, {}, httpApi.PREFIX_V2_ALPHA ); + + var room = this.getRoom(event.getRoomId()); + if (room) { + room._addLocalEchoReceipt(this.credentials.userId, event, receiptType); + } + return promise; }; /** diff --git a/lib/models/room.js b/lib/models/room.js index 04b5599f8..29b2e8ae9 100644 --- a/lib/models/room.js +++ b/lib/models/room.js @@ -620,6 +620,17 @@ Room.prototype.addReceipt = function(event) { this.emit("Room.receipt", event, this); }; +/** + * Add a temporary local-echo receipt to the room to reflect in the + * client the fact that we've sent one. + * @param {string} user_id The user ID if the receipt sender + * @param {MatrixEvent} e The event that is to be acknowledged + * @param {string} receipt_type The type of receipt + */ +Room.prototype._addLocalEchoReceipt = function(user_id, e, receipt_type) { + this.addReceipt(synthesizeReceipt(user_id, e, receipt_type)); +}; + /** * Update the room-tag event for the room. The previous one is overwritten. * @param {MatrixEvent} event the m.tag event From 0c3abcccf260e41618d78f5a9647bbde18b19563 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 26 Jan 2016 14:11:36 +0000 Subject: [PATCH 2/2] camelCase --- lib/models/room.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/models/room.js b/lib/models/room.js index 29b2e8ae9..145851f34 100644 --- a/lib/models/room.js +++ b/lib/models/room.js @@ -623,12 +623,12 @@ Room.prototype.addReceipt = function(event) { /** * Add a temporary local-echo receipt to the room to reflect in the * client the fact that we've sent one. - * @param {string} user_id The user ID if the receipt sender + * @param {string} userId The user ID if the receipt sender * @param {MatrixEvent} e The event that is to be acknowledged - * @param {string} receipt_type The type of receipt + * @param {string} receiptType The type of receipt */ -Room.prototype._addLocalEchoReceipt = function(user_id, e, receipt_type) { - this.addReceipt(synthesizeReceipt(user_id, e, receipt_type)); +Room.prototype._addLocalEchoReceipt = function(userId, e, receiptType) { + this.addReceipt(synthesizeReceipt(userId, e, receiptType)); }; /**