Merge branch 'main' of gitlab.com:famedly/fluffychat into main

This commit is contained in:
Christian Pauly 2021-04-14 13:40:19 +02:00
commit 46e71d6f01
35 changed files with 224 additions and 99 deletions

View file

@ -251,7 +251,7 @@ class _ChatState extends State<Chat> {
}
void openCameraAction(BuildContext context) async {
var file = await ImagePicker().getImage(source: ImageSource.camera);
final file = await ImagePicker().getImage(source: ImageSource.camera);
if (file == null) return;
final bytes = await file.readAsBytes();
await showDialog(
@ -297,7 +297,7 @@ class _ChatState extends State<Chat> {
.getDisplayEvent(timeline)
.getLocalizedBody(MatrixLocals(L10n.of(context)));
}
for (var event in selectedEvents) {
for (final event in selectedEvents) {
if (copyString.isNotEmpty) copyString += '\n\n';
copyString += event.getDisplayEvent(timeline).getLocalizedBody(
MatrixLocals(L10n.of(context)),
@ -356,7 +356,7 @@ class _ChatState extends State<Chat> {
}
void redactEventsAction(BuildContext context) async {
var confirmed = await showOkCancelAlertDialog(
final confirmed = await showOkCancelAlertDialog(
context: context,
title: L10n.of(context).messageWillBeRemovedWarning,
okLabel: L10n.of(context).remove,
@ -365,7 +365,7 @@ class _ChatState extends State<Chat> {
) ==
OkCancelResult.ok;
if (!confirmed) return;
for (var event in selectedEvents) {
for (final event in selectedEvents) {
await showFutureLoadingDialog(
context: context,
future: () => event.status > 0 ? event.redact() : event.remove());
@ -374,7 +374,7 @@ class _ChatState extends State<Chat> {
}
bool get canRedactSelectedEvents {
for (var event in selectedEvents) {
for (final event in selectedEvents) {
if (event.canRedact == false) return false;
}
return true;
@ -512,7 +512,7 @@ class _ChatState extends State<Chat> {
@override
Widget build(BuildContext context) {
matrix = Matrix.of(context);
var client = matrix.client;
final client = matrix.client;
room ??= client.getRoomById(widget.id);
if (room == null) {
return Scaffold(
@ -985,7 +985,7 @@ class _ChatState extends State<Chat> {
selectedEvents.length == 1)) {
return Container();
}
var emojis = List<String>.from(AppEmojis.emojis);
final emojis = List<String>.from(AppEmojis.emojis);
final allReactionEvents = selectedEvents.first
.aggregatedEvents(
timeline, RelationshipTypes.Reaction)

View file

@ -83,7 +83,7 @@ class _ChatDetailsState extends State<ChatDetails> {
final aliases =
aliasEvent != null ? aliasEvent.content['aliases'] ?? [] : [];
if (aliases.indexWhere((s) => s == canonicalAlias) == -1) {
var newAliases = List<String>.from(aliases);
final newAliases = List<String>.from(aliases);
newAliases.add(canonicalAlias);
final response = await showFutureLoadingDialog(
context: context,

View file

@ -116,7 +116,7 @@ class _ChatEncryptionSettingsState extends State<ChatEncryptionSettings> {
onSelected: (action) =>
onSelected(context, action, deviceKeys[i]),
itemBuilder: (c) {
var items = <PopupMenuEntry<String>>[];
final items = <PopupMenuEntry<String>>[];
if (room
.client
.userDeviceKeys[deviceKeys[i].userId]
@ -166,7 +166,7 @@ class _ChatEncryptionSettingsState extends State<ChatEncryptionSettings> {
onSelected: (action) =>
onSelected(context, action, deviceKeys[i]),
itemBuilder: (c) {
var items = <PopupMenuEntry<String>>[];
final items = <PopupMenuEntry<String>>[];
if (deviceKeys[i].blocked ||
!deviceKeys[i].verified) {
items.add(PopupMenuItem(

View file

@ -182,7 +182,7 @@ class _ChatListState extends State<ChatList> {
}
Future<void> waitForFirstSync(BuildContext context) async {
var client = Matrix.of(context).client;
final client = Matrix.of(context).client;
if (client.prevBatch?.isEmpty ?? true) {
await client.onFirstSync.stream.first;
}
@ -371,7 +371,7 @@ class _ChatListState extends State<ChatList> {
future: waitForFirstSync(context),
builder: (BuildContext context, snapshot) {
if (snapshot.hasData) {
var rooms = List<Room>.from(
final rooms = List<Room>.from(
Matrix.of(context).client.rooms);
rooms.removeWhere((room) => room.lastEvent == null);
if (rooms.isEmpty) {

View file

@ -62,7 +62,7 @@ class InvitationSelectionView extends StatelessWidget {
child: CircularProgressIndicator(),
);
}
var contacts = snapshot.data;
final contacts = snapshot.data;
return ListView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,

View file

@ -61,6 +61,7 @@ class _LogViewerState extends State<LogViewer> {
}
class _AnsiParser {
// ignore: constant_identifier_names
static const TEXT = 0, BRACKET = 1, CODE = 2;
final String text;
@ -73,12 +74,13 @@ class _AnsiParser {
spans = [];
var state = TEXT;
StringBuffer buffer;
var text = StringBuffer();
final text = StringBuffer();
var code = 0;
List<int> codes;
// ignore: prefer_final_locals
for (var i = 0, n = s.length; i < n; i++) {
var c = s[i];
final c = s[i];
switch (state) {
case TEXT:
@ -104,7 +106,7 @@ class _AnsiParser {
case CODE:
buffer.write(c);
var codeUnit = c.codeUnitAt(0);
final codeUnit = c.codeUnitAt(0);
if (codeUnit >= 48 && codeUnit <= 57) {
code = code * 10 + codeUnit - 48;
continue;

View file

@ -26,7 +26,7 @@ class _LoginState extends State<Login> {
bool showPassword = false;
void login(BuildContext context) async {
var matrix = Matrix.of(context);
final matrix = Matrix.of(context);
if (usernameController.text.isEmpty) {
setState(() => usernameError = L10n.of(context).pleaseEnterYourUsername);
} else {

View file

@ -121,7 +121,7 @@ class _NewPrivateChatState extends State<NewPrivateChat> {
return L10n.of(context).pleaseEnterAMatrixIdentifier;
}
final matrix = Matrix.of(context);
var mxid = '@' + controller.text.trim();
final mxid = '@' + controller.text.trim();
if (mxid == matrix.client.userID) {
return L10n.of(context).youCannotInviteYourself;
}
@ -187,7 +187,7 @@ class _NewPrivateChatState extends State<NewPrivateChat> {
child: ListView.builder(
itemCount: foundProfiles.length,
itemBuilder: (BuildContext context, int i) {
var foundProfile = foundProfiles[i];
final foundProfile = foundProfiles[i];
return ListTile(
onTap: () {
setState(() {

View file

@ -355,7 +355,7 @@ class _SearchViewState extends State<SearchView> {
? ListView.builder(
itemCount: foundProfiles.length,
itemBuilder: (BuildContext context, int i) {
var foundProfile = foundProfiles[i];
final foundProfile = foundProfiles[i];
return ListTile(
onTap: () async {
final roomID = await showFutureLoadingDialog(

View file

@ -51,7 +51,7 @@ class _SettingsState extends State<Settings> {
OkCancelResult.cancel) {
return;
}
var matrix = Matrix.of(context);
final matrix = Matrix.of(context);
await showFutureLoadingDialog(
context: context,
future: () => matrix.client.logout(),
@ -146,7 +146,7 @@ class _SettingsState extends State<Settings> {
void setJitsiInstanceAction(BuildContext context) async {
const prefix = 'https://';
var input = await showTextInputDialog(
final input = await showTextInputDialog(
context: context,
title: L10n.of(context).editJitsiInstance,
okLabel: L10n.of(context).ok,

View file

@ -38,9 +38,9 @@ class DevicesSettingsState extends State<DevicesSettings> {
useRootNavigator: false,
) ==
OkCancelResult.cancel) return;
var matrix = Matrix.of(context);
var deviceIds = <String>[];
for (var userDevice in devices) {
final matrix = Matrix.of(context);
final deviceIds = <String>[];
for (final userDevice in devices) {
deviceIds.add(userDevice.deviceId);
}
@ -150,10 +150,10 @@ class DevicesSettingsState extends State<DevicesSettings> {
if (!snapshot.hasData || this.devices == null) {
return Center(child: CircularProgressIndicator());
}
Function isOwnDevice = (Device userDevice) =>
final Function isOwnDevice = (Device userDevice) =>
userDevice.deviceId == Matrix.of(context).client.deviceID;
final devices = List<Device>.from(this.devices);
var thisDevice =
final thisDevice =
devices.firstWhere(isOwnDevice, orElse: () => null);
devices.removeWhere(isOwnDevice);
devices.sort((a, b) => b.lastSeenTs.compareTo(a.lastSeenTs));

View file

@ -137,7 +137,7 @@ class _EmotesSettingsState extends State<EmotesSettings> {
@override
Widget build(BuildContext context) {
var client = Matrix.of(context).client;
final client = Matrix.of(context).client;
if (emotes == null) {
emotes = <_EmoteEntry>[];
Map<String, dynamic> emoteSource;

View file

@ -27,10 +27,10 @@ class AudioPlayer extends StatefulWidget {
_AudioPlayerState createState() => _AudioPlayerState();
}
enum AudioPlayerStatus { NOT_DOWNLOADED, DOWNLOADING, DOWNLOADED }
enum AudioPlayerStatus { notDownloaded, downloading, downloaded }
class _AudioPlayerState extends State<AudioPlayer> {
AudioPlayerStatus status = AudioPlayerStatus.NOT_DOWNLOADED;
AudioPlayerStatus status = AudioPlayerStatus.notDownloaded;
final FlutterSoundPlayer flutterSound = FlutterSoundPlayer();
@ -70,14 +70,14 @@ class _AudioPlayerState extends State<AudioPlayer> {
}
Future<void> _downloadAction() async {
if (status != AudioPlayerStatus.NOT_DOWNLOADED) return;
setState(() => status = AudioPlayerStatus.DOWNLOADING);
if (status != AudioPlayerStatus.notDownloaded) return;
setState(() => status = AudioPlayerStatus.downloading);
try {
final matrixFile =
await widget.event.downloadAndDecryptAttachmentCached();
setState(() {
audioFile = matrixFile.bytes;
status = AudioPlayerStatus.DOWNLOADED;
status = AudioPlayerStatus.downloaded;
});
_playAction();
} catch (e, s) {
@ -126,7 +126,7 @@ class _AudioPlayerState extends State<AudioPlayer> {
});
AudioPlayer.currentId = null;
} else if (e != null) {
var txt =
final txt =
'${e.position.inMinutes.toString().padLeft(2, '0')}:${(e.position.inSeconds % 60).toString().padLeft(2, '0')}';
setState(() {
maxPosition = e.duration.inMilliseconds.toDouble();
@ -158,7 +158,7 @@ class _AudioPlayerState extends State<AudioPlayer> {
children: <Widget>[
Container(
width: 30,
child: status == AudioPlayerStatus.DOWNLOADING
child: status == AudioPlayerStatus.downloading
? CircularProgressIndicator(strokeWidth: 2)
: IconButton(
icon: Icon(
@ -171,7 +171,7 @@ class _AudioPlayerState extends State<AudioPlayer> {
? L10n.of(context).audioPlayerPause
: L10n.of(context).audioPlayerPlay,
onPressed: () {
if (status == AudioPlayerStatus.DOWNLOADED) {
if (status == AudioPlayerStatus.downloaded) {
_playAction();
} else {
_downloadAction();
@ -184,7 +184,7 @@ class _AudioPlayerState extends State<AudioPlayer> {
value: currentPosition,
onChanged: (double position) => flutterSound
.seekToPlayer(Duration(milliseconds: position.toInt())),
max: status == AudioPlayerStatus.DOWNLOADED ? maxPosition : 0,
max: status == AudioPlayerStatus.downloaded ? maxPosition : 0,
min: 0,
),
),

View file

@ -25,7 +25,7 @@ class Avatar extends StatelessWidget {
@override
Widget build(BuildContext context) {
var thumbnail = mxContent?.getThumbnail(
final thumbnail = mxContent?.getThumbnail(
client ?? Matrix.of(context).client,
width: size * MediaQuery.of(context).devicePixelRatio,
height: size * MediaQuery.of(context).devicePixelRatio,

View file

@ -38,7 +38,7 @@ class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
.listen(
(u) => setState(() => null),
);
var items = <PopupMenuEntry<String>>[
final items = <PopupMenuEntry<String>>[
widget.room.pushRuleState == PushRuleState.notify
? PopupMenuItem<String>(
value: 'mute',
@ -66,7 +66,7 @@ class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
onSelected: (String choice) async {
switch (choice) {
case 'leave':
var confirmed = await showOkCancelAlertDialog(
final confirmed = await showOkCancelAlertDialog(
context: context,
useRootNavigator: false,
title: L10n.of(context).areYouSure,

View file

@ -248,7 +248,7 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
));
break;
case KeyVerificationState.waitingSas:
var acceptText = widget.request.sasTypes.contains('emoji')
final acceptText = widget.request.sasTypes.contains('emoji')
? L10n.of(context).waitingPartnerEmoji
: L10n.of(context).waitingPartnerNumbers;
body = Column(

View file

@ -36,7 +36,7 @@ class _RecordingDialogState extends State<RecordingDialog> {
_recordedPath = '${tempDir.path}/recording${ext[codec.index]}';
// delete any existing file
var outputFile = File(_recordedPath);
final outputFile = File(_recordedPath);
if (outputFile.existsSync()) {
await outputFile.delete();
}

View file

@ -45,9 +45,9 @@ class Message extends StatelessWidget {
return StateMessage(event, unfold: unfold);
}
var client = Matrix.of(context).client;
final client = Matrix.of(context).client;
final ownMessage = event.senderId == client.userID;
var alignment = ownMessage ? Alignment.topRight : Alignment.topLeft;
final alignment = ownMessage ? Alignment.topRight : Alignment.topLeft;
var color = Theme.of(context).secondaryHeaderColor;
final sameSender = nextEvent != null &&
[EventTypes.Message, EventTypes.Sticker].contains(nextEvent.type)
@ -58,7 +58,7 @@ class Message extends StatelessWidget {
: Theme.of(context).brightness == Brightness.dark
? Colors.white
: Colors.black;
var rowMainAxisAlignment =
final rowMainAxisAlignment =
ownMessage ? MainAxisAlignment.end : MainAxisAlignment.start;
final displayEvent = event.getDisplayEvent(timeline);
@ -72,7 +72,7 @@ class Message extends StatelessWidget {
: Theme.of(context).primaryColor;
}
var rowChildren = <Widget>[
final rowChildren = <Widget>[
Expanded(
child: Container(
alignment: alignment,

View file

@ -12,7 +12,7 @@ class ParticipantListItem extends StatelessWidget {
@override
Widget build(BuildContext context) {
var membershipBatch = <Membership, String>{
final membershipBatch = <Membership, String>{
Membership.join: '',
Membership.ban: L10n.of(context).banned,
Membership.invite: L10n.of(context).invited,

View file

@ -238,7 +238,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
Future<void> initConfig() async {
try {
var configJsonString =
final configJsonString =
utf8.decode((await http.get('config.json')).bodyBytes);
final configJson = json.decode(configJsonString);
AppConfig.loadFromJson(configJson);

View file

@ -90,7 +90,7 @@ class UserBottomSheet extends StatelessWidget {
Widget build(BuildContext context) {
final client = user.room.client;
final presence = client.presences[user.id];
var items = <PopupMenuEntry<String>>[];
final items = <PopupMenuEntry<String>>[];
if (onMention != null) {
items.add(