Search in sources :

Example 26 with Room

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);
    }
}
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 27 with Room

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

Example 28 with Room

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

Example 29 with Room

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();
                    }
                }
            });
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) BingRuleSet(org.matrix.androidsdk.rest.model.bingrules.BingRuleSet) ApiCallback(org.matrix.androidsdk.rest.callback.ApiCallback) SimpleApiCallback(org.matrix.androidsdk.rest.callback.SimpleApiCallback) MXDecryptionException(org.matrix.androidsdk.crypto.MXDecryptionException) UnrecognizedCertificateException(org.matrix.androidsdk.ssl.UnrecognizedCertificateException) HandlerThread(android.os.HandlerThread) SyncResponse(org.matrix.androidsdk.rest.model.sync.SyncResponse) RoomMember(org.matrix.androidsdk.rest.model.RoomMember) MatrixError(org.matrix.androidsdk.rest.model.MatrixError) Room(org.matrix.androidsdk.data.Room)

Example 30 with Room

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

Aggregations

Room (org.matrix.androidsdk.data.Room)60 MatrixError (org.matrix.androidsdk.rest.model.MatrixError)33 Event (org.matrix.androidsdk.rest.model.Event)27 ArrayList (java.util.ArrayList)26 CountDownLatch (java.util.concurrent.CountDownLatch)26 HashMap (java.util.HashMap)25 JsonObject (com.google.gson.JsonObject)24 Test (org.junit.Test)22 RoomState (org.matrix.androidsdk.data.RoomState)22 MXEventListener (org.matrix.androidsdk.listeners.MXEventListener)19 Context (android.content.Context)15 RoomMember (org.matrix.androidsdk.rest.model.RoomMember)12 EventTimeline (org.matrix.androidsdk.data.EventTimeline)8 IMXStore (org.matrix.androidsdk.data.store.IMXStore)8 File (java.io.File)7 MXDeviceInfo (org.matrix.androidsdk.crypto.data.MXDeviceInfo)6 ApiCallback (org.matrix.androidsdk.rest.callback.ApiCallback)6 Credentials (org.matrix.androidsdk.rest.model.login.Credentials)6 List (java.util.List)5 Uri (android.net.Uri)4