processMetaCreds method
Called by Tinode when meta.sub is received.
Implementation
@override
void processMetaCreds(List<Credential> creds, bool update) {
// ignore: unrelated_type_equality_checks
if (creds.length == 1 && creds[0] == DEL_CHAR) {
creds = [];
}
if (update) {
creds.forEach((cr) {
// Adding a credential.
var idx = _credentials.indexWhere((el) {
return el.meth == cr.meth && el.val == cr.val;
});
if (cr.val != null) {
if (idx < 0) {
// Not found.
if (cr.done == false || cr.done == null) {
// Unconfirmed credential replaces previous unconfirmed credential of the same method.
idx = _credentials.indexWhere((el) {
return el.meth == cr.meth &&
(el.done == false || cr.done == null);
});
if (idx >= 0) {
// Remove previous unconfirmed credential.
_credentials.removeAt(idx);
}
}
_credentials.add(cr);
} else {
// Found. Maybe change 'done' status.
_credentials[idx].done = cr.done;
}
} else if (cr.resp != null) {
// Handle credential confirmation.
idx = _credentials.indexWhere((el) {
return el.meth == cr.meth && (el.done == false || cr.done == null);
});
if (idx >= 0) {
_credentials[idx].done = true;
}
}
});
} else {
_credentials = creds;
}
onCredsUpdated.add(_credentials);
}