use of org.matrix.androidsdk.data.RoomPreviewData in project matrix-android-sdk by matrix-org.
the class MatrixMessagesFragment method previewRoom.
/**
* Trigger a room preview i.e trigger an initial sync before filling the message list.
*/
private void previewRoom() {
Log.d(LOG_TAG, "Make a room preview of " + mRoom.getRoomId());
if (null != mMatrixMessagesListener) {
RoomPreviewData roomPreviewData = mMatrixMessagesListener.getRoomPreviewData();
if (null != roomPreviewData) {
if (null != roomPreviewData.getRoomResponse()) {
Log.d(LOG_TAG, "A preview data is provided with sync response");
RoomResponse roomResponse = roomPreviewData.getRoomResponse();
// initialize the timeline with the initial sync response
RoomSync roomSync = new RoomSync();
roomSync.state = new RoomSyncState();
roomSync.state.events = roomResponse.state;
roomSync.timeline = new RoomSyncTimeline();
roomSync.timeline.events = roomResponse.messages.chunk;
roomSync.timeline.limited = true;
roomSync.timeline.prevBatch = roomResponse.messages.end;
mEventTimeline.handleJoinedRoomSync(roomSync, true);
Log.d(LOG_TAG, "The room preview is done -> fill the room history");
mHasPendingInitialHistory = true;
} else {
Log.d(LOG_TAG, "A preview data is provided with no sync response : assume that it is not possible to get a room preview");
if (null != getActivity()) {
if (null != mMatrixMessagesListener) {
mMatrixMessagesListener.hideInitLoading();
}
}
}
return;
}
}
mSession.getRoomsApiClient().initialSync(mRoom.getRoomId(), new ApiCallback<RoomResponse>() {
@Override
public void onSuccess(RoomResponse roomResponse) {
// initialize the timeline with the initial sync response
RoomSync roomSync = new RoomSync();
roomSync.state = new RoomSyncState();
roomSync.state.events = roomResponse.state;
roomSync.timeline = new RoomSyncTimeline();
roomSync.timeline.events = roomResponse.messages.chunk;
mEventTimeline.handleJoinedRoomSync(roomSync, true);
Log.d(LOG_TAG, "The room preview is done -> fill the room history");
requestInitialHistory();
}
private void onError(String errorMessage) {
Log.e(LOG_TAG, "The room preview of " + mRoom.getRoomId() + "failed " + errorMessage);
if (null != getActivity()) {
getActivity().finish();
}
}
@Override
public void onNetworkError(Exception e) {
onError(e.getLocalizedMessage());
}
@Override
public void onMatrixError(MatrixError e) {
onError(e.getLocalizedMessage());
}
@Override
public void onUnexpectedError(Exception e) {
onError(e.getLocalizedMessage());
}
});
}
Aggregations