use of org.matrix.androidsdk.adapters.MessageRow in project matrix-android-sdk by matrix-org.
the class MatrixMessageListFragment method getReadMarkerMessageRow.
/**
* Provides the read "marked row".
* The closest row is provided if it is not displayed
*
* @return the currentReadMarkerRow
*/
private MessageRow getReadMarkerMessageRow(MessageRow newMessageRow) {
final String currentReadMarkerEventId = mRoom.getReadMarkerEventId();
MessageRow currentReadMarkerRow = mAdapter.getMessageRow(currentReadMarkerEventId);
if (null == currentReadMarkerRow) {
// crash reported by GA
try {
Event readMarkedEvent = mSession.getDataHandler().getStore().getEvent(currentReadMarkerEventId, mRoom.getRoomId());
// the read marked event might be a non displayable event
if ((null != readMarkedEvent) && !canAddEvent(readMarkedEvent)) {
// retrieve the previous displayed event
currentReadMarkerRow = mAdapter.getClosestRowFromTs(readMarkedEvent.eventId, readMarkedEvent.getOriginServerTs());
// or it is the last known event
if ((null != currentReadMarkerRow) && !canUpdateReadMarker(newMessageRow, currentReadMarkerRow)) {
currentReadMarkerRow = null;
}
// use the next one
if (null == currentReadMarkerRow) {
currentReadMarkerRow = mAdapter.getClosestRowBeforeTs(readMarkedEvent.eventId, readMarkedEvent.getOriginServerTs());
}
}
} catch (Exception e) {
Log.e(LOG_TAG, "## getReadMarkerMessageRow() failed : " + e.getMessage());
}
}
return currentReadMarkerRow;
}
use of org.matrix.androidsdk.adapters.MessageRow in project matrix-android-sdk by matrix-org.
the class MatrixMessageListFragment method addMessageRow.
// create a dummy message row for the message
// It is added to the Adapter
// return the created Message
private MessageRow addMessageRow(RoomMediaMessage roomMediaMessage) {
// a message row can only be added if there is a defined room
if (null != mRoom) {
Event event = roomMediaMessage.getEvent();
MessageRow newMessageRow = new MessageRow(event, mRoom.getState());
mAdapter.add(newMessageRow);
// Move read marker if necessary
MessageRow currentReadMarkerRow = getReadMarkerMessageRow(newMessageRow);
if (canUpdateReadMarker(newMessageRow, currentReadMarkerRow)) {
View childView = mMessageListView.getChildAt(mMessageListView.getChildCount() - 1);
// Previous message was the last read
if ((null != childView) && (childView.getTop() >= 0)) {
// New message is fully visible, keep reference to move the read marker once server echo is received
mFutureReadMarkerEventId = event.eventId;
mAdapter.resetReadMarker();
}
}
scrollToBottom();
getSession().getDataHandler().getStore().commit();
return newMessageRow;
} else {
return null;
}
}
Aggregations