mirror of
https://github.com/element-hq/element-web
synced 2024-11-27 11:47:23 +03:00
Merge code to send read receipts into react-sdk RoomView controller
This commit is contained in:
parent
5a72f199e1
commit
86ef0e762e
1 changed files with 54 additions and 1 deletions
|
@ -89,6 +89,9 @@ module.exports = {
|
|||
messageWrapper.scrollTop = messageWrapper.scrollHeight;
|
||||
}
|
||||
break;
|
||||
case 'user_activity':
|
||||
this.sendReadReceipt();
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -172,6 +175,8 @@ module.exports = {
|
|||
|
||||
messageWrapper.scrollTop = messageWrapper.scrollHeight;
|
||||
|
||||
this.sendReadReceipt();
|
||||
|
||||
this.fillSpace();
|
||||
}
|
||||
},
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue