use of org.matrix.androidsdk.data.timeline.EventTimeline in project matrix-android-sdk by matrix-org.
the class RoomStateTest method RoomState_Permalink.
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);
}
use of org.matrix.androidsdk.data.timeline.EventTimeline in project matrix-android-sdk by matrix-org.
the class CryptoTest method test12_testAliceAndBobInAEncryptedRoomBackPaginationFromHomeServer.
@Test
public void test12_testAliceAndBobInAEncryptedRoomBackPaginationFromHomeServer() throws Exception {
Log.e(LOG_TAG, "test12_testAliceAndBobInAEncryptedRoomBackPaginationFromHomeServer");
Context context = InstrumentationRegistry.getContext();
final Map<String, Object> results = new HashMap<>();
CryptoTestData cryptoTestData = mCryptoTestHelper.doE2ETestWithAliceAndBobInARoomWithEncryptedMessages(true);
final MXSession aliceSession = cryptoTestData.getFirstSession();
final String aliceRoomId = cryptoTestData.getRoomId();
final MXSession bobSession = cryptoTestData.getSecondSession();
String eventId = bobSession.getDataHandler().getStore().getLatestEvent(aliceRoomId).eventId;
EventTimeline timeline = EventTimelineFactory.pastTimeline(bobSession.getDataHandler(), aliceRoomId, eventId);
final CountDownLatch lock2 = new CountDownLatch(6);
final List<Event> receivedEvents = new ArrayList<>();
EventTimeline.Listener eventTimelineListener = new EventTimeline.Listener() {
public void onEvent(Event event, EventTimeline.Direction direction, RoomState roomState) {
if (TextUtils.equals(event.getType(), Event.EVENT_TYPE_MESSAGE)) {
receivedEvents.add(event);
lock2.countDown();
}
}
};
timeline.addEventTimelineListener(eventTimelineListener);
timeline.backPaginate(new TestApiCallback<Integer>(lock2) {
@Override
public void onSuccess(Integer info) {
results.put("backPaginate", "backPaginate");
super.onSuccess(info);
}
});
mTestHelper.await(lock2);
Assert.assertTrue(results.containsKey("backPaginate"));
Assert.assertEquals(5, receivedEvents.size());
mCryptoTestHelper.checkEncryptedEvent(receivedEvents.get(0), aliceRoomId, mCryptoTestHelper.getMessagesFromAlice().get(1), aliceSession);
mCryptoTestHelper.checkEncryptedEvent(receivedEvents.get(1), aliceRoomId, mCryptoTestHelper.getMessagesFromBob().get(2), bobSession);
mCryptoTestHelper.checkEncryptedEvent(receivedEvents.get(2), aliceRoomId, mCryptoTestHelper.getMessagesFromBob().get(1), bobSession);
mCryptoTestHelper.checkEncryptedEvent(receivedEvents.get(3), aliceRoomId, mCryptoTestHelper.getMessagesFromBob().get(0), bobSession);
mCryptoTestHelper.checkEncryptedEvent(receivedEvents.get(4), aliceRoomId, mCryptoTestHelper.getMessagesFromAlice().get(0), aliceSession);
cryptoTestData.clear(context);
}
use of org.matrix.androidsdk.data.timeline.EventTimeline in project matrix-android-sdk by matrix-org.
the class RoomStateTest method RoomState_PermalinkWithForwardPagination.
// Test lazy loaded members sent by the HS when paginating forward
// - Come back to Bob message
// - We should only know Bob membership
// - Paginate forward to get Alice next message
// - We should know Alice membership now
private void RoomState_PermalinkWithForwardPagination(final boolean withLazyLoading) throws Exception {
final LazyLoadingScenarioData data = mLazyLoadingTestHelper.createScenario(withLazyLoading);
mTestHelper.syncSession(data.aliceSession, false);
final CountDownLatch lock = new CountDownLatch(1);
final EventTimeline eventTimeline = EventTimelineFactory.pastTimeline(data.aliceSession.getDataHandler(), data.roomId, data.bobMessageId);
eventTimeline.addEventTimelineListener(new EventTimeline.Listener() {
int messageCount = 0;
@Override
public void onEvent(Event event, EventTimeline.Direction direction, RoomState roomState) {
if (TextUtils.equals(event.getType(), Event.EVENT_TYPE_MESSAGE)) {
messageCount++;
Log.d("TAG", "Receiving message #" + messageCount + ": " + JsonUtils.toMessage(event.getContent()).body);
if (messageCount == 1) {
// We received the Event from bob
Assert.assertEquals(event.sender, data.bobSession.getMyUserId());
// Bob is known
Assert.assertNotNull(eventTimeline.getState().getMember(data.bobSession.getMyUserId()));
// With LazyLoading, Alice and Sam are not known by Alice yet
Assert.assertEquals(withLazyLoading, eventTimeline.getState().getMember(data.aliceSession.getMyUserId()) == null);
Assert.assertEquals(withLazyLoading, eventTimeline.getState().getMember(data.samSession.getMyUserId()) == null);
} else if (messageCount == 2) {
// We received the Event from Alice
Assert.assertEquals(event.sender, data.aliceSession.getMyUserId());
// Alice and Bob are known
Assert.assertNotNull(eventTimeline.getState().getMember(data.aliceSession.getMyUserId()));
Assert.assertNotNull(eventTimeline.getState().getMember(data.bobSession.getMyUserId()));
// With LazyLoading, Sam is not known by Alice yet
Assert.assertEquals(withLazyLoading, eventTimeline.getState().getMember(data.samSession.getMyUserId()) == null);
lock.countDown();
}
} else {
Log.d("TAG", "Receiving other event: " + event.getType());
}
}
});
eventTimeline.resetPaginationAroundInitialEvent(0, new SimpleApiCallback<Void>() {
@Override
public void onSuccess(Void info) {
eventTimeline.forwardPaginate(new SimpleApiCallback<Integer>() {
@Override
public void onSuccess(Integer info) {
// Ignore
}
});
}
});
mTestHelper.await(lock);
mLazyLoadingTestHelper.clearAllSessions(data);
}
use of org.matrix.androidsdk.data.timeline.EventTimeline in project matrix-android-sdk by matrix-org.
the class RoomStateTest method RoomState_PermalinkWithBackPagination.
// Test lazy loaded members sent by the HS when paginating backward
// - Come back to Bob message
// - We should only know Bob membership
// - Paginate backward to get Alice next message
// - We should know Alice membership now
private void RoomState_PermalinkWithBackPagination(final boolean withLazyLoading) throws Exception {
final LazyLoadingScenarioData data = mLazyLoadingTestHelper.createScenario(withLazyLoading);
mTestHelper.syncSession(data.aliceSession, false);
final CountDownLatch lock = new CountDownLatch(1);
final EventTimeline eventTimeline = EventTimelineFactory.pastTimeline(data.aliceSession.getDataHandler(), data.roomId, data.bobMessageId);
eventTimeline.addEventTimelineListener(new EventTimeline.Listener() {
int messageCount = 0;
@Override
public void onEvent(Event event, EventTimeline.Direction direction, RoomState roomState) {
if (TextUtils.equals(event.getType(), Event.EVENT_TYPE_MESSAGE)) {
messageCount++;
Log.d("TAG", "Receiving message #" + messageCount + ": " + JsonUtils.toMessage(event.getContent()).body);
if (messageCount == 1) {
// We received the Event from bob
Assert.assertEquals(event.sender, data.bobSession.getMyUserId());
// Bob is known
Assert.assertNotNull(eventTimeline.getState().getMember(data.bobSession.getMyUserId()));
// With LazyLoading, Alice and Sam are not known by Alice yet
Assert.assertEquals(withLazyLoading, eventTimeline.getState().getMember(data.aliceSession.getMyUserId()) == null);
Assert.assertEquals(withLazyLoading, eventTimeline.getState().getMember(data.samSession.getMyUserId()) == null);
} else if (messageCount == 2) {
// We received the Event from Alice
Assert.assertEquals(event.sender, data.aliceSession.getMyUserId());
// Alice and Bob are known
Assert.assertNotNull(eventTimeline.getState().getMember(data.aliceSession.getMyUserId()));
Assert.assertNotNull(eventTimeline.getState().getMember(data.bobSession.getMyUserId()));
// With LazyLoading, Sam is not known by Alice yet
Assert.assertEquals(withLazyLoading, eventTimeline.getState().getMember(data.samSession.getMyUserId()) == null);
lock.countDown();
}
} else {
Log.d("TAG", "Receiving other event: " + event.getType());
}
}
});
eventTimeline.resetPaginationAroundInitialEvent(0, new SimpleApiCallback<Void>() {
@Override
public void onSuccess(Void info) {
eventTimeline.backPaginate(new SimpleApiCallback<Integer>() {
@Override
public void onSuccess(Integer info) {
// ignore
}
});
}
});
mTestHelper.await(lock);
mLazyLoadingTestHelper.clearAllSessions(data);
}
use of org.matrix.androidsdk.data.timeline.EventTimeline in project matrix-android-sdk by matrix-org.
the class RoomStateTest method RoomState_BackPaginate.
private void RoomState_BackPaginate(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);
final EventTimeline liveTimeline = aliceRoom.getTimeline();
liveTimeline.addEventTimelineListener(new EventTimeline.Listener() {
int messageCount = 0;
@Override
public void onEvent(Event event, EventTimeline.Direction direction, RoomState roomState) {
messageCount++;
if (TextUtils.equals(event.getType(), Event.EVENT_TYPE_MESSAGE)) {
Log.d("TAG", "Receiving message #" + messageCount + ": " + JsonUtils.toMessage(event.getContent()).body);
} else {
Log.d("TAG", "Receiving event: #" + messageCount + " of type " + event.getType());
}
if (messageCount == 10) {
Assert.assertNotNull(liveTimeline.getState().getMember(data.aliceSession.getMyUserId()));
// With LazyLoading, Bob and Sam are not known by Alice yet
Assert.assertEquals(withLazyLoading, liveTimeline.getState().getMember(data.bobSession.getMyUserId()) == null);
Assert.assertEquals(withLazyLoading, liveTimeline.getState().getMember(data.samSession.getMyUserId()) == null);
Assert.assertEquals(withLazyLoading, roomState.getMember(data.bobSession.getMyUserId()) == null);
Assert.assertEquals(withLazyLoading, roomState.getMember(data.samSession.getMyUserId()) == null);
} else if (messageCount == 50) {
// Bob is known now
Assert.assertNotNull(liveTimeline.getState().getMember(data.bobSession.getMyUserId()));
// With LazyLoading, Sam is not known by Alice yet
Assert.assertEquals(withLazyLoading, liveTimeline.getState().getMember(data.samSession.getMyUserId()) == null);
Assert.assertEquals(withLazyLoading, roomState.getMember(data.samSession.getMyUserId()) == null);
} else if (messageCount == 105) {
// All users are known now
Assert.assertNotNull(liveTimeline.getState().getMember(data.aliceSession.getMyUserId()));
Assert.assertNotNull(liveTimeline.getState().getMember(data.bobSession.getMyUserId()));
Assert.assertNotNull(liveTimeline.getState().getMember(data.samSession.getMyUserId()));
lock.countDown();
}
}
});
recursiveBackPaginate(liveTimeline, 0, 30, 120);
mTestHelper.await(lock);
mLazyLoadingTestHelper.clearAllSessions(data);
}
Aggregations