updateState method

void updateState(
  1. STATE_UPDATE stateToUpdate,
  2. AtContact contact,
  3. bool state
)

updates status of contacts for baseContactList and baseBlockedList

Implementation

void updateState(STATE_UPDATE stateToUpdate, AtContact contact, bool state) {
  int indexToUpdate;
  if (stateToUpdate == STATE_UPDATE.unblock) {
    indexToUpdate = baseBlockedList
        .indexWhere((element) => element.contact!.atSign == contact.atSign);
  } else {
    indexToUpdate = baseContactList
        .indexWhere((element) => element.contact!.atSign == contact.atSign);
  }

  if (indexToUpdate == -1) {
    throw Exception('index range error: $indexToUpdate');
  }

  switch (stateToUpdate) {
    case STATE_UPDATE.block:
      baseContactList[indexToUpdate].isBlocking = state;
      break;
    case STATE_UPDATE.unblock:
      baseBlockedList[indexToUpdate].isBlocking = state;
      break;
    case STATE_UPDATE.delete:
      baseContactList[indexToUpdate].isDeleting = state;
      break;
    case STATE_UPDATE.markFav:
      baseContactList[indexToUpdate].isMarkingFav = state;
      break;
    default:
  }

  if (stateToUpdate == STATE_UPDATE.unblock) {
    blockedContactSink.add(baseBlockedList);
  } else {
    contactSink.add(baseContactList);
  }
}