markUnread method

Future<void> markUnread(
  1. bool unread
)

Sets an unread flag manually for this room. This changes the local account data model before syncing it to make sure this works if there is no connection to the homeserver. This does not set a read marker!

Implementation

Future<void> markUnread(bool unread) async {
  if (unread == markedUnread) return;
  if (membership != Membership.join) {
    throw Exception(
      'Can not markUnread on a room with membership $membership',
    );
  }
  final content = MarkedUnread(unread).toJson();
  await _handleFakeSync(
    SyncUpdate(
      nextBatch: '',
      rooms: RoomsUpdate(
        join: {
          id: JoinedRoomUpdate(
            accountData: [
              BasicEvent(
                content: content,
                type: EventType.markedUnread,
              ),
            ],
          ),
        },
      ),
    ),
  );
  await client.setAccountDataPerRoom(
    client.userID!,
    id,
    EventType.markedUnread,
    content,
  );
}