use of org.matrix.androidsdk.data.Room 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.Room 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);
}
}
}
use of org.matrix.androidsdk.data.Room in project matrix-android-sdk by matrix-org.
the class MXDataHandler method refreshUnreadCounters.
/**
* Refresh the unread summary counters of the updated rooms.
*/
private void refreshUnreadCounters() {
Set<String> roomIdsList;
synchronized (mUpdatedRoomIdList) {
roomIdsList = new HashSet<>(mUpdatedRoomIdList);
mUpdatedRoomIdList.clear();
}
// refresh the unread counter
for (String roomId : roomIdsList) {
Room room = mStore.getRoom(roomId);
if (null != room) {
room.refreshUnreadCounter();
}
}
}
use of org.matrix.androidsdk.data.Room in project matrix-android-sdk by matrix-org.
the class MXDataHandler method retrieveLeftRooms.
/**
* Retrieve the historical rooms
*
* @param callback the asynchronous callback.
*/
public void retrieveLeftRooms(ApiCallback<Void> callback) {
// already loaded
if (mAreLeftRoomsSynced) {
if (null != callback) {
callback.onSuccess(null);
}
} else {
int count;
synchronized (mLeftRoomsRefreshCallbacks) {
if (null != callback) {
mLeftRoomsRefreshCallbacks.add(callback);
}
count = mLeftRoomsRefreshCallbacks.size();
}
// start the request only for the first listener
if (1 == count) {
mIsRetrievingLeftRooms = true;
Log.d(LOG_TAG, "## refreshHistoricalRoomsList() : requesting");
mEventsRestClient.syncFromToken(null, 0, 30000, null, LEFT_ROOMS_FILTER, new ApiCallback<SyncResponse>() {
@Override
public void onSuccess(final SyncResponse syncResponse) {
Runnable r = new Runnable() {
@Override
public void run() {
if (null != syncResponse.rooms.leave) {
Set<String> roomIds = syncResponse.rooms.leave.keySet();
// Handle first joined rooms
for (String roomId : roomIds) {
Room room = getRoom(mLeftRoomsStore, roomId, true);
// sanity check
if (null != room) {
room.setIsLeft(true);
room.handleJoinedRoomSync(syncResponse.rooms.leave.get(roomId), true);
RoomMember selfMember = room.getState().getMember(getUserId());
// keep only the left rooms (i.e not the banned / kicked ones)
if ((null == selfMember) || !TextUtils.equals(selfMember.membership, RoomMember.MEMBERSHIP_LEAVE)) {
mLeftRoomsStore.deleteRoom(roomId);
}
}
}
Log.d(LOG_TAG, "## refreshHistoricalRoomsList() : " + mLeftRoomsStore.getRooms().size() + " left rooms");
}
mIsRetrievingLeftRooms = false;
mAreLeftRoomsSynced = true;
synchronized (mLeftRoomsRefreshCallbacks) {
for (ApiCallback<Void> c : mLeftRoomsRefreshCallbacks) {
c.onSuccess(null);
}
mLeftRoomsRefreshCallbacks.clear();
}
}
};
Thread t = new Thread(r);
t.setPriority(Thread.MIN_PRIORITY);
t.start();
}
@Override
public void onNetworkError(Exception e) {
synchronized (mLeftRoomsRefreshCallbacks) {
Log.d(LOG_TAG, "## refreshHistoricalRoomsList() : failed " + e.getMessage());
for (ApiCallback<Void> c : mLeftRoomsRefreshCallbacks) {
c.onNetworkError(e);
}
mLeftRoomsRefreshCallbacks.clear();
}
}
@Override
public void onMatrixError(MatrixError e) {
synchronized (mLeftRoomsRefreshCallbacks) {
Log.d(LOG_TAG, "## refreshHistoricalRoomsList() : failed " + e.getMessage());
for (ApiCallback<Void> c : mLeftRoomsRefreshCallbacks) {
c.onMatrixError(e);
}
mLeftRoomsRefreshCallbacks.clear();
}
}
@Override
public void onUnexpectedError(Exception e) {
synchronized (mLeftRoomsRefreshCallbacks) {
Log.d(LOG_TAG, "## refreshHistoricalRoomsList() : failed " + e.getMessage());
for (ApiCallback<Void> c : mLeftRoomsRefreshCallbacks) {
c.onUnexpectedError(e);
}
mLeftRoomsRefreshCallbacks.clear();
}
}
});
}
}
}
use of org.matrix.androidsdk.data.Room in project matrix-android-sdk by matrix-org.
the class MXSession method roomIdsWithTag.
/**
* Get the list of roomIds that are tagged the specified tag.
* The returned array is ordered according to the room tag order.
*
* @param tag RoomTag.ROOM_TAG_XXX values
* @return the room IDs list.
*/
public List<String> roomIdsWithTag(final String tag) {
List<Room> roomsWithTag = roomsWithTag(tag);
List<String> roomIdsList = new ArrayList<>();
for (Room room : roomsWithTag) {
roomIdsList.add(room.getRoomId());
}
return roomIdsList;
}
Aggregations