refactor: simplify parseQueryString in parseIdentifierIntoParts

This commit is contained in:
Lukas Lihotzki 2021-09-22 17:31:47 +02:00 committed by Krille Fear
parent 62fe7a1704
commit 8ea01fcee0
1 changed files with 5 additions and 30 deletions

View File

@ -66,36 +66,11 @@ extension MatrixIdExtension on String {
final via = <String>{}; final via = <String>{};
String action; String action;
final parseQueryString = (qs) { final parseQueryString = (String qs) {
if (qs != null) { if (qs == null) return;
// as there might be multiple "via" tags we can't just use Uri.splitQueryString, we need to do our own thing final uri = Uri(query: qs);
for (final parameterStr in qs.split('&')) { via = (uri.queryParametersAll['via'] ?? []).toSet();
final index = parameterStr.indexOf('='); action = uri.queryParameters['action'];
if (index == -1) {
continue;
}
var parameter = parameterStr.substring(0, index);
try {
parameter = Uri.decodeQueryComponent(parameter);
} catch (_) {
// do nothing: the parameter wasn't url-encoded, and we already have the
// plaintext version in the `parameter` variable
}
var value = parameterStr.substring(index + 1);
try {
value = Uri.decodeQueryComponent(value);
} catch (_) {
// do nothing: the value wasn't url-encoded, and we already have the
// plaintext version in the `value` variable
}
if (parameter == 'via') {
via.add(value);
}
if (parameter == 'action') {
action = value;
}
}
}
}; };
// check if we have a "matrix:" uri // check if we have a "matrix:" uri