Timeline constructor

Timeline({
  1. required Room room,
  2. void onUpdate()?,
  3. void onChange(
    1. int index
    )?,
  4. void onInsert(
    1. int index
    )?,
  5. void onRemove(
    1. int index
    )?,
  6. void onNewEvent()?,
  7. required TimelineChunk chunk,
})

Implementation

Timeline(
    {required this.room,
    this.onUpdate,
    this.onChange,
    this.onInsert,
    this.onRemove,
    this.onNewEvent,
    required this.chunk}) {
  sub = room.client.onEvent.stream.listen(_handleEventUpdate);

  // If the timeline is limited we want to clear our events cache
  roomSub = room.client.onSync.stream
      .where((sync) => sync.rooms?.join?[room.id]?.timeline?.limited == true)
      .listen(_removeEventsNotInThisSync);

  sessionIdReceivedSub =
      room.onSessionKeyReceived.stream.listen(_sessionKeyReceived);
  cancelSendEventSub =
      room.client.onCancelSendEvent.stream.listen(_cleanUpCancelledEvent);

  // we want to populate our aggregated events
  for (final e in events) {
    addAggregatedEvent(e);
  }

  // we are using a fragmented timeline
  if (chunk.nextBatch != '') {
    allowNewEvent = false;
    isFragmentedTimeline = true;
  }
}