/** * Get the room object for the corresponding room id. * The left rooms are not included. * * @param roomId the room id * @param create create the room it does not exist. * @return the corresponding room */ public Room getRoom(String roomId, boolean create) { return getRoom(mStore, roomId, create); }
/** * Get the room object for the corresponding room id. Creates and initializes the object if there is none. * * @param roomId the room id * @return the corresponding room */ public Room getRoom(String roomId) { return getRoom(roomId, true); }
/** * Get the room object for the corresponding room id. * By default, the left rooms are not included. * * @param roomId the room id * @param testLeftRooms true to test if the room is a left room * @param create create the room it does not exist. * @return the corresponding room */ public Room getRoom(String roomId, boolean testLeftRooms, boolean create) { Room room = null; if (null != roomId) { room = mStore.getRoom(roomId); if ((null == room) && testLeftRooms) { room = mLeftRoomsStore.getRoom(roomId); } if ((null == room) && create) { room = getRoom(mStore, roomId, create); } } return room; }
@Override public void onSuccess(Void info) { Room room = getDataHandler().getRoom(fRoomId); if (null != room) { room.markAllAsRead(null); } if (null != callback) { callback.onSuccess(fRoomId); } } });
/** * Tells if a room is encrypted * * @param roomId the room id * @return true if the room is encrypted */ public boolean isRoomEncrypted(String roomId) { boolean res = false; if (null != roomId) { synchronized (mRoomEncryptors) { res = mRoomEncryptors.containsKey(roomId); if (!res) { Room room = mSession.getDataHandler().getRoom(roomId); if (null != room) { res = room.getState().isEncrypted(); } } } } return res; }
/** * Method to create a in memory timeline. * It will create a memory store and a room * * @param dataHandler the data handler * @param roomId the room id * @param eventId the event id or null */ private static EventTimeline inMemoryTimeline(@NonNull final MXDataHandler dataHandler, @NonNull final String roomId, @Nullable final String eventId) { final MXMemoryStore store = new MXMemoryStore(dataHandler.getCredentials(), null); final Room room = dataHandler.getRoom(store, roomId, true); final EventTimeline eventTimeline = new MXEventTimeline(store, dataHandler, room, roomId, eventId, false); room.setTimeline(eventTimeline); room.setReadyState(true); return eventTimeline; } }
@Override public void onSuccess(ChunkEvents info) { Room room = getRoom(roomId); if (info.chunk != null) { for (Event event : info.chunk) { room.getState().applyState(event, true, getStore()); } } callback.onSuccess(room.getState().getLoadedMembers()); } });
@Override public void onSuccess(final RoomResponse roomResponse) { final String roomId = roomResponse.roomId; Room joinedRoom = mDataHandler.getRoom(roomId); // wait until the initial sync is done if (!joinedRoom.isJoined()) { joinedRoom.setOnInitialSyncCallback(new SimpleApiCallback<Void>(callback) { @Override public void onSuccess(Void info) { callback.onSuccess(roomId); } }); } else { // to initialise the notification counters joinedRoom.markAllAsRead(null); callback.onSuccess(roomId); } } });
@Override public void onSuccess(String roomId) { Log.d(LOG_TAG, "getConferenceUserRoom : the room creation succeeds"); Room room = mSession.getDataHandler().getRoom(roomId); if (null != room) { room.setIsConferenceUserRoom(true); mSession.getDataHandler().getStore().commit(); callback.onSuccess(room); } }
private void checkAllName(RoomNameScenarioData roomNameScenarioData, String expectedName) { for (MXSession session : roomNameScenarioData.userSessions) { Assert.assertEquals(expectedName, session.getDataHandler().getRoom(roomNameScenarioData.roomId).getState().name); } } }
private void RoomSummary_CheckMembership(boolean withLazyLoading) throws Exception { final LazyLoadingScenarioData data = mLazyLoadingTestHelper.createScenario(withLazyLoading); mTestHelper.syncSession(data.aliceSession, false); final Room aliceRoom = data.aliceSession.getDataHandler().getRoom(data.roomId); final RoomSummary aliceRoomSummary = aliceRoom.getRoomSummary(); Assert.assertNotNull(aliceRoomSummary); Assert.assertTrue(aliceRoomSummary.isJoined()); mTestHelper.syncSession(data.samSession, false); final Room samRoom = data.samSession.getDataHandler().getRoom(data.roomId); final RoomSummary samRoomSummary = samRoom.getRoomSummary(); Assert.assertNotNull(samRoomSummary); Assert.assertTrue(samRoomSummary.isJoined()); mLazyLoadingTestHelper.clearAllSessions(data); }
private void RoomMembers_CheckAlreadyLoadedCount(final boolean withLazyLoading) throws Exception { final LazyLoadingScenarioData data = mLazyLoadingTestHelper.createScenario(withLazyLoading); mTestHelper.syncSession(data.aliceSession, false); final Room aliceRoom = data.aliceSession.getDataHandler().getRoom(data.roomId); final List<RoomMember> members = aliceRoom.getState().getLoadedMembers(); if (withLazyLoading) { Assert.assertEquals(1, members.size()); } else { Assert.assertEquals(4, members.size()); } mLazyLoadingTestHelper.clearAllSessions(data); }
private void RoomMembers_CheckJoinedCountAsync(final boolean withLazyLoading) throws Exception { final LazyLoadingScenarioData data = mLazyLoadingTestHelper.createScenario(withLazyLoading); mTestHelper.syncSession(data.aliceSession, false); final Room aliceRoom = data.aliceSession.getDataHandler().getRoom(data.roomId); final CountDownLatch lock = new CountDownLatch(1); aliceRoom.getJoinedMembersAsync(new TestApiCallback<List<RoomMember>>(lock) { @Override public void onSuccess(List<RoomMember> roomMembers) { Assert.assertEquals(3, roomMembers.size()); super.onSuccess(roomMembers); } }); mTestHelper.await(lock); mLazyLoadingTestHelper.clearAllSessions(data); }
private void RoomMembers_CheckActiveCountAsync(final boolean withLazyLoading) throws Exception { final LazyLoadingScenarioData data = mLazyLoadingTestHelper.createScenario(withLazyLoading); mTestHelper.syncSession(data.aliceSession, false); final Room aliceRoom = data.aliceSession.getDataHandler().getRoom(data.roomId); final CountDownLatch lock = new CountDownLatch(1); aliceRoom.getActiveMembersAsync(new TestApiCallback<List<RoomMember>>(lock) { @Override public void onSuccess(List<RoomMember> roomMembers) { Assert.assertEquals(4, roomMembers.size()); super.onSuccess(roomMembers); } }); mTestHelper.await(lock); mLazyLoadingTestHelper.clearAllSessions(data); }
private void RoomMembers_CheckTotalCountAsync(final boolean withLazyLoading) throws Exception { final LazyLoadingScenarioData data = mLazyLoadingTestHelper.createScenario(withLazyLoading); mTestHelper.syncSession(data.aliceSession, false); final Room aliceRoom = data.aliceSession.getDataHandler().getRoom(data.roomId); final CountDownLatch lock = new CountDownLatch(1); aliceRoom.getMembersAsync(new TestApiCallback<List<RoomMember>>(lock) { @Override public void onSuccess(List<RoomMember> roomMembers) { Assert.assertEquals(4, roomMembers.size()); super.onSuccess(roomMembers); } }); mTestHelper.await(lock); mLazyLoadingTestHelper.clearAllSessions(data); }
private void RoomState_InitialSync(final boolean withLazyLoading) throws Exception { final LazyLoadingScenarioData data = mLazyLoadingTestHelper.createScenario(withLazyLoading); mTestHelper.syncSession(data.aliceSession, false); final Room aliceRoom = data.aliceSession.getDataHandler().getRoom(data.roomId); if (withLazyLoading) { Assert.assertEquals(1, aliceRoom.getState().getLoadedMembers().size()); } else { Assert.assertEquals(4, aliceRoom.getState().getLoadedMembers().size()); } Assert.assertEquals(1, aliceRoom.getNumberOfInvitedMembers()); Assert.assertEquals(3, aliceRoom.getNumberOfJoinedMembers()); mLazyLoadingTestHelper.clearAllSessions(data); }
private void RoomSummary_CheckRoomSummaryIsNullAfterLeavingFromAnotherDevice(boolean withLazyLoading) throws Exception { final LazyLoadingScenarioData data = mLazyLoadingTestHelper.createScenario(withLazyLoading); final CountDownLatch lock = new CountDownLatch(1); data.aliceSession.getDataHandler().getDataRetriever().getRoomsRestClient().leaveRoom(data.roomId, new TestApiCallback<Void>(lock)); mTestHelper.await(lock); mTestHelper.syncSession(data.bobSession, false); final Room bobRoom = data.bobSession.getDataHandler().getRoom(data.roomId); mTestHelper.sendTextMessage(bobRoom, "New bob message", 50); mTestHelper.syncSession(data.aliceSession, false); final RoomSummary roomSummary = data.aliceSession.getDataHandler().getStore().getSummary(data.roomId); Assert.assertNull(roomSummary); mLazyLoadingTestHelper.clearAllSessions(data); }
private void RoomState_IncomingMessage(final boolean withLazyLoading) throws Exception { final LazyLoadingScenarioData data = mLazyLoadingTestHelper.createScenario(withLazyLoading); mTestHelper.syncSession(data.aliceSession, false); mTestHelper.syncSession(data.samSession, false); final Room aliceRoom = data.aliceSession.getDataHandler().getRoom(data.roomId); final CountDownLatch lock = new CountDownLatch(1); aliceRoom.getTimeline().addEventTimelineListener(new EventTimeline.Listener() { @Override public void onEvent(Event event, EventTimeline.Direction direction, RoomState roomState) { lock.countDown(); } }); final Room samRoom = data.samSession.getDataHandler().getRoom(data.roomId); mTestHelper.sendTextMessage(samRoom, "A message from Sam", 1); mTestHelper.await(lock); if (withLazyLoading) { // Sam is now loaded Assert.assertEquals(2, aliceRoom.getState().getLoadedMembers().size()); } else { Assert.assertEquals(4, aliceRoom.getState().getLoadedMembers().size()); } Assert.assertEquals(1, aliceRoom.getNumberOfInvitedMembers()); Assert.assertEquals(3, aliceRoom.getNumberOfJoinedMembers()); mLazyLoadingTestHelper.clearAllSessions(data); }
@Test public void test06_testAliceInAEncryptedRoom() throws Exception { Log.e(LOG_TAG, "test06_testAliceInAEncryptedRoom"); Context context = InstrumentationRegistry.getContext(); CryptoTestData cryptoTestData = mCryptoTestHelper.doE2ETestWithAliceInARoom(); MXSession aliceSession = cryptoTestData.getFirstSession(); String aliceRoomId = cryptoTestData.getRoomId(); final String message = "Hello myself!"; Room roomFromAlicePOV = aliceSession.getDataHandler().getRoom(aliceRoomId); Assert.assertTrue(roomFromAlicePOV.isEncrypted()); CountDownLatch lock1 = new CountDownLatch(1); // the IOS client echoes the message // the android client does not roomFromAlicePOV.sendEvent(mCryptoTestHelper.buildTextEvent(message, aliceSession, aliceRoomId), new TestApiCallback<Void>(lock1)); mTestHelper.await(lock1); cryptoTestData.clear(context); }
private void RoomState_Permalink(final boolean withLazyLoading) throws Exception { final LazyLoadingScenarioData data = mLazyLoadingTestHelper.createScenario(withLazyLoading); mTestHelper.syncSession(data.aliceSession, false); final Room aliceRoom = data.aliceSession.getDataHandler().getRoom(data.roomId); final Event lastEvent = aliceRoom.getDataHandler().getStore().getLatestEvent(data.roomId); final EventTimeline eventTimeline = EventTimelineFactory.pastTimeline(data.aliceSession.getDataHandler(), lastEvent.roomId, lastEvent.eventId); final CountDownLatch lock = new CountDownLatch(1); eventTimeline.resetPaginationAroundInitialEvent(10, new SimpleApiCallback<Void>() { @Override public void onSuccess(Void info) { lock.countDown(); } }); mTestHelper.await(lock); final RoomState roomState = eventTimeline.getState(); if (withLazyLoading) { Assert.assertEquals(1, roomState.getLoadedMembers().size()); } else { Assert.assertEquals(4, roomState.getLoadedMembers().size()); } Assert.assertEquals(1, aliceRoom.getNumberOfInvitedMembers()); Assert.assertEquals(3, aliceRoom.getNumberOfJoinedMembers()); mLazyLoadingTestHelper.clearAllSessions(data); }