Search in sources :

Example 1 with RoomSummary

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");
    }
}
Also used : Event(org.matrix.androidsdk.rest.model.Event) Room(org.matrix.androidsdk.data.Room) RoomState(org.matrix.androidsdk.data.RoomState) RoomSummary(org.matrix.androidsdk.data.RoomSummary)

Example 2 with RoomSummary

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);
        }
    }
}
Also used : MessageRow(org.matrix.androidsdk.adapters.MessageRow) RoomSummary(org.matrix.androidsdk.data.RoomSummary)

Example 3 with RoomSummary

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;
}
Also used : File(java.io.File) Room(org.matrix.androidsdk.data.Room) RoomSummary(org.matrix.androidsdk.data.RoomSummary)

Example 4 with RoomSummary

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);
    }
}
Also used : ArrayList(java.util.ArrayList) Event(org.matrix.androidsdk.rest.model.Event) ReceiptData(org.matrix.androidsdk.rest.model.ReceiptData) Room(org.matrix.androidsdk.data.Room) RoomSummary(org.matrix.androidsdk.data.RoomSummary)

Example 5 with RoomSummary

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);
        }
    }
}
Also used : Room(org.matrix.androidsdk.data.Room) RoomSummary(org.matrix.androidsdk.data.RoomSummary)

Aggregations

RoomSummary (org.matrix.androidsdk.data.RoomSummary)6 Room (org.matrix.androidsdk.data.Room)4 File (java.io.File)2 Event (org.matrix.androidsdk.rest.model.Event)2 HandlerThread (android.os.HandlerThread)1 ArrayList (java.util.ArrayList)1 MessageRow (org.matrix.androidsdk.adapters.MessageRow)1 RoomState (org.matrix.androidsdk.data.RoomState)1 ReceiptData (org.matrix.androidsdk.rest.model.ReceiptData)1