Merge branch 'soru/update-matrix-scheme' into 'main'

chore: Update matrix scheme parsing to match updated MSC

See merge request famedly/famedlysdk!657
This commit is contained in:
Krille Fear 2021-02-24 05:40:04 +00:00
commit 62ad8569ae
2 changed files with 7 additions and 11 deletions

View File

@ -97,11 +97,10 @@ extension MatrixIdExtension on String {
final identifiers = <String>[];
for (var i = 0; i < pathSegments.length - 1; i += 2) {
final thisSigil = {
'user': '@',
'u': '@',
'roomid': '!',
'room': '#',
'group': '+',
'event': '\$',
'r': '#',
'e': '\$',
}[pathSegments[i].toLowerCase()];
if (thisSigil == null) {
break;

View File

@ -88,26 +88,23 @@ void main() {
.parseIdentifierIntoParts();
expect(res.via, <String>{'fox.com', 'fox.org'});
res = 'matrix:user/her:example.org'.parseIdentifierIntoParts();
res = 'matrix:u/her:example.org'.parseIdentifierIntoParts();
expect(res.primaryIdentifier, '@her:example.org');
expect(res.secondaryIdentifier, null);
res = 'matrix:user/bad'.parseIdentifierIntoParts();
res = 'matrix:u/bad'.parseIdentifierIntoParts();
expect(res, null);
res = 'matrix:roomid/rid:example.org'.parseIdentifierIntoParts();
expect(res.primaryIdentifier, '!rid:example.org');
expect(res.secondaryIdentifier, null);
expect(res.action, null);
res = 'matrix:room/us:example.org?action=chat'.parseIdentifierIntoParts();
res = 'matrix:r/us:example.org?action=chat'.parseIdentifierIntoParts();
expect(res.primaryIdentifier, '#us:example.org');
expect(res.secondaryIdentifier, null);
expect(res.action, 'chat');
res = 'matrix:room/us:example.org/event/lol823y4bcp3qo4'
res = 'matrix:r/us:example.org/e/lol823y4bcp3qo4'
.parseIdentifierIntoParts();
expect(res.primaryIdentifier, '#us:example.org');
expect(res.secondaryIdentifier, '\$lol823y4bcp3qo4');
res = 'matrix:group/them:example.org'.parseIdentifierIntoParts();
expect(res.primaryIdentifier, '+them:example.org');
expect(res.secondaryIdentifier, null);
res = 'matrix:roomid/rid:example.org?via=fox.com&via=fox.org'
.parseIdentifierIntoParts();
expect(res.primaryIdentifier, '!rid:example.org');