buildWidgetUrl method
Implementation
Future<Uri> buildWidgetUrl() async {
// See https://github.com/sdn-org/sdn-doc/issues/1236 for a
// description, specifically the section
// `What does the other stuff in content mean?`
final userProfile = await room.client.fetchOwnProfile();
var parsedUri = url;
// a key-value map with the strings to be replaced
final replaceMap = {
r'$sdn_user_id': userProfile.userId,
r'$sdn_room_id': room.id,
r'$sdn_display_name': userProfile.displayName ?? '',
r'$sdn_avatar_url': userProfile.avatarUrl?.toString() ?? '',
// removing potentially dangerous keys containing anything but
// `[a-zA-Z0-9_-]` as well as non string values
if (data != null)
...Map.from(data!)
..removeWhere((key, value) =>
!RegExp(r'^[\w-]+$').hasMatch(key) || !value is String)
..map((key, value) => MapEntry('\$key', value)),
};
replaceMap.forEach((key, value) {
parsedUri = parsedUri.replaceAll(key, Uri.encodeComponent(value));
});
return Uri.parse(parsedUri);
}