Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge code to send read receipts into react-sdk RoomView controller
Browse files Browse the repository at this point in the history
  • Loading branch information
dbkr committed Nov 3, 2015
1 parent 5a72f19 commit 86ef0e7
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion src/controllers/organisms/RoomView.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ module.exports = {
messageWrapper.scrollTop = messageWrapper.scrollHeight;
}
break;
case 'user_activity':
this.sendReadReceipt();
break;
}
},

Expand Down Expand Up @@ -172,6 +175,8 @@ module.exports = {

messageWrapper.scrollTop = messageWrapper.scrollHeight;

this.sendReadReceipt();

this.fillSpace();
}
},
Expand Down Expand Up @@ -354,7 +359,7 @@ module.exports = {
}
}
ret.unshift(
<li key={mxEv.getId()}><EventTile mxEvent={mxEv} continuation={continuation} last={last}/></li>
<li ref={this._collectEventNode.bind(this, mxEv.getId())} key={mxEv.getId()}><EventTile mxEvent={mxEv} continuation={continuation} last={last}/></li>
);
++count;
}
Expand Down Expand Up @@ -446,5 +451,53 @@ module.exports = {
uploadingRoomSettings: false,
});
}
},

_collectEventNode: function(eventId, node) {
if (this.eventNodes == undefined) this.eventNodes = {};
this.eventNodes[eventId] = node;
},

_indexForEventId(evId) {
for (var i = 0; i < this.state.room.timeline.length; ++i) {
if (evId == this.state.room.timeline[i].getId()) {
return i;
}
}
return null;
},

sendReadReceipt: function() {
var currentReadUpToEventId = this.state.room.getEventReadUpTo(MatrixClientPeg.get().credentials.userId);
var currentReadUpToEventIndex = this._indexForEventId(currentReadUpToEventId);

var lastReadEventIndex = this._getLastDisplayedEventIndex();
if (lastReadEventIndex === null) return;

if (lastReadEventIndex > currentReadUpToEventIndex) {
MatrixClientPeg.get().sendReadReceipt(this.state.room.timeline[lastReadEventIndex]);
}
},

_getLastDisplayedEventIndex: function() {
if (this.eventNodes === undefined) return null;

var messageWrapper = this.refs.messageWrapper;
if (messageWrapper === undefined) return null;
var wrapperRect = messageWrapper.getDOMNode().getBoundingClientRect();

for (var i = this.state.room.timeline.length-1; i >= 0; --i) {
var ev = this.state.room.timeline[i];
var node = this.eventNodes[ev.getId()];
if (node === undefined) continue;

var domNode = node.getDOMNode();
var boundingRect = domNode.getBoundingClientRect();

if (boundingRect.bottom < wrapperRect.bottom) {
return i;
}
}
return null;
}
};

0 comments on commit 86ef0e7

Please sign in to comment.