use of org.matrix.androidsdk.data.RoomSummary in project matrix-android-sdk by matrix-org.
the class MXDataHandler method deleteRoomEvent.
/**
* Delete an event.
*
* @param event The event to be stored.
*/
public void deleteRoomEvent(Event event) {
if (isAlive()) {
Room room = getRoom(event.roomId);
if (null != room) {
mStore.deleteEvent(event);
Event lastEvent = mStore.getLatestEvent(event.roomId);
RoomState beforeLiveRoomState = room.getState().deepCopy();
RoomSummary summary = mStore.getSummary(event.roomId);
if (null == summary) {
summary = new RoomSummary(null, lastEvent, beforeLiveRoomState, mCredentials.userId);
} else {
summary.setLatestReceivedEvent(lastEvent, beforeLiveRoomState);
}
if (TextUtils.equals(summary.getReadReceiptEventId(), event.eventId)) {
summary.setReadReceiptEventId(lastEvent.eventId);
}
if (TextUtils.equals(summary.getReadMarkerEventId(), event.eventId)) {
summary.setReadMarkerEventId(lastEvent.eventId);
}
mStore.storeSummary(summary);
}
} else {
Log.e(LOG_TAG, "deleteRoomEvent : the session is not anymore active");
}
}
use of org.matrix.androidsdk.data.RoomSummary in project matrix-android-sdk by matrix-org.
the class MatrixMessageListFragment method onEventSent.
@Override
public void onEventSent(final Event event, final String prevEventId) {
// onEvent is not called because the server event echo manages an event sent by itself
if ((null == mAdapter.getMessageRow(event.eventId)) && canAddEvent(event)) {
if (null != mAdapter.getMessageRow(prevEventId)) {
mAdapter.updateEventById(event, prevEventId);
} else {
// refresh the listView only when it is a live timeline or a search
mAdapter.add(new MessageRow(event, mRoom.getLiveState()), true);
}
if (mFutureReadMarkerEventId != null && prevEventId.equals(mFutureReadMarkerEventId)) {
mFutureReadMarkerEventId = null;
// Move read marker to the newly sent message
mRoom.setReadMakerEventId(event.eventId);
RoomSummary summary = mRoom.getDataHandler().getStore().getSummary(mRoom.getRoomId());
if (summary != null) {
String readReceiptEventId = summary.getReadReceiptEventId();
// Inform adapter of the new read marker position
mAdapter.updateReadMarker(event.eventId, readReceiptEventId);
}
}
} else {
MessageRow row = mAdapter.getMessageRow(prevEventId);
if (null != row) {
mAdapter.remove(row);
}
}
}
use of org.matrix.androidsdk.data.RoomSummary in project matrix-android-sdk by matrix-org.
the class MXFileStore method loadSummary.
/**
* Load the room summary from the files system.
*
* @param roomId the room id.
* @return true if the operation succeeds;
*/
private boolean loadSummary(final String roomId) {
boolean succeed = true;
// do not check if the room exists here.
// if the user is invited to a room, the room object is not created until it is joined.
RoomSummary summary = null;
try {
File messagesListFile = new File(mStoreRoomsSummaryFolderFile, roomId);
Object summaryAsVoid = readObject("loadSummary " + roomId, messagesListFile);
if (null == summaryAsVoid) {
Log.e(LOG_TAG, "loadSummary failed");
return false;
}
summary = (RoomSummary) summaryAsVoid;
} catch (Exception e) {
succeed = false;
Log.e(LOG_TAG, "loadSummary failed : " + e.getMessage());
}
if (null != summary) {
// summary.getLatestReceivedEvent().finalizeDeserialization();
Room room = getRoom(summary.getRoomId());
// it is restored from the room
if (null != room) {
summary.setLatestRoomState(room.getState());
}
mRoomSummaries.put(roomId, summary);
}
return succeed;
}
use of org.matrix.androidsdk.data.RoomSummary in project matrix-android-sdk by matrix-org.
the class MXDataHandler method deleteRoom.
/**
* Delete a room from its room id.
* The room data is copied into the left rooms store.
*
* @param roomId the room id
*/
public void deleteRoom(String roomId) {
// copy the room from a store to another one
Room r = this.getStore().getRoom(roomId);
if (null != r) {
if (mAreLeftRoomsSynced) {
Room leftRoom = getRoom(mLeftRoomsStore, roomId, true);
leftRoom.setIsLeft(true);
// copy the summary
RoomSummary summary = getStore().getSummary(roomId);
if (null != summary) {
mLeftRoomsStore.storeSummary(new RoomSummary(summary, summary.getLatestReceivedEvent(), summary.getLatestRoomState(), getUserId()));
}
// copy events and receiptData
// it is not required but it is better, it could be useful later
// the room summary should be enough to be displayed in the recent pages
ArrayList<ReceiptData> receipts = new ArrayList<>();
Collection<Event> events = getStore().getRoomMessages(roomId);
if (null != events) {
for (Event e : events) {
receipts.addAll(getStore().getEventReceipts(roomId, e.eventId, false, false));
mLeftRoomsStore.storeLiveRoomEvent(e);
}
for (ReceiptData receipt : receipts) {
mLeftRoomsStore.storeReceipt(receipt, roomId);
}
}
// copy the state
leftRoom.getLiveTimeLine().setState(r.getLiveTimeLine().getState());
}
// remove the previous definition
getStore().deleteRoom(roomId);
}
}
use of org.matrix.androidsdk.data.RoomSummary in project matrix-android-sdk by matrix-org.
the class MXDataHandler method checkPermanentStorageData.
/**
* Update the missing data fields loaded from a permanent storage.
*/
void checkPermanentStorageData() {
if (!isAlive()) {
Log.e(LOG_TAG, "checkPermanentStorageData : the session is not anymore active");
return;
}
// When the data are extracted from a persistent storage,
// some fields are not retrieved :
// They are used to retrieve some data
// so add the missing links.
Collection<Room> rooms = mStore.getRooms();
for (Room room : rooms) {
room.init(mStore, room.getRoomId(), this);
}
Collection<RoomSummary> summaries = mStore.getSummaries();
for (RoomSummary summary : summaries) {
if (null != summary.getLatestRoomState()) {
summary.getLatestRoomState().setDataHandler(this);
}
}
}
Aggregations