mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-02-02 16:14:21 +01:00
refactor: Magic numbers
This commit is contained in:
parent
56646cb697
commit
fcdf5a7ee4
@ -99,9 +99,10 @@ class _FluffyChatAppState extends State<FluffyChatApp> {
|
|||||||
initial: AdaptiveThemeMode.system,
|
initial: AdaptiveThemeMode.system,
|
||||||
builder: (theme, darkTheme) => LayoutBuilder(
|
builder: (theme, darkTheme) => LayoutBuilder(
|
||||||
builder: (context, constraints) {
|
builder: (context, constraints) {
|
||||||
|
const maxColumns = 3;
|
||||||
var newColumns =
|
var newColumns =
|
||||||
(constraints.maxWidth / FluffyThemes.columnWidth).floor();
|
(constraints.maxWidth / FluffyThemes.columnWidth).floor();
|
||||||
if (newColumns > 3) newColumns = 3;
|
if (newColumns > maxColumns) newColumns = maxColumns;
|
||||||
columnMode ??= newColumns > 1;
|
columnMode ??= newColumns > 1;
|
||||||
_router ??= GlobalKey<VRouterState>();
|
_router ??= GlobalKey<VRouterState>();
|
||||||
if (columnMode != newColumns > 1) {
|
if (columnMode != newColumns > 1) {
|
||||||
|
@ -552,50 +552,50 @@ class ChatController extends State<Chat> {
|
|||||||
if (eventIndex == -1) {
|
if (eventIndex == -1) {
|
||||||
// event id not found...maybe we can fetch it?
|
// event id not found...maybe we can fetch it?
|
||||||
// the try...finally is here to start and close the loading dialog reliably
|
// the try...finally is here to start and close the loading dialog reliably
|
||||||
final task = Future.microtask(() async {
|
await showFutureLoadingDialog(
|
||||||
// okay, we first have to fetch if the event is in the room
|
context: context,
|
||||||
try {
|
future: () async {
|
||||||
final event = await timeline.getEventById(eventId);
|
// okay, we first have to fetch if the event is in the room
|
||||||
if (event == null) {
|
try {
|
||||||
// event is null...meaning something is off
|
final event = await timeline.getEventById(eventId);
|
||||||
return;
|
if (event == null) {
|
||||||
}
|
// event is null...meaning something is off
|
||||||
} catch (err) {
|
return;
|
||||||
if (err is MatrixException && err.errcode == 'M_NOT_FOUND') {
|
}
|
||||||
// event wasn't found, as the server gave a 404 or something
|
} catch (err) {
|
||||||
return;
|
if (err is MatrixException && err.errcode == 'M_NOT_FOUND') {
|
||||||
}
|
// event wasn't found, as the server gave a 404 or something
|
||||||
rethrow;
|
return;
|
||||||
}
|
}
|
||||||
// okay, we know that the event *is* in the room
|
rethrow;
|
||||||
while (eventIndex == -1) {
|
|
||||||
if (!canLoadMore) {
|
|
||||||
// we can't load any more events but still haven't found ours yet...better stop here
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
await timeline.requestHistory(historyCount: _loadHistoryCount);
|
|
||||||
} catch (err) {
|
|
||||||
if (err is TimeoutException) {
|
|
||||||
// loading the history timed out...so let's do nothing
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
rethrow;
|
// okay, we know that the event *is* in the room
|
||||||
}
|
while (eventIndex == -1) {
|
||||||
eventIndex = filteredEvents.indexWhere((e) => e.eventId == eventId);
|
if (!canLoadMore) {
|
||||||
}
|
// we can't load any more events but still haven't found ours yet...better stop here
|
||||||
});
|
return;
|
||||||
if (context != null) {
|
}
|
||||||
await showFutureLoadingDialog(context: context, future: () => task);
|
try {
|
||||||
} else {
|
await timeline.requestHistory(historyCount: _loadHistoryCount);
|
||||||
await task;
|
} catch (err) {
|
||||||
}
|
if (err is TimeoutException) {
|
||||||
|
// loading the history timed out...so let's do nothing
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
eventIndex =
|
||||||
|
filteredEvents.indexWhere((e) => e.eventId == eventId);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (!mounted) {
|
if (!mounted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await scrollController.scrollToIndex(eventIndex,
|
await scrollController.scrollToIndex(
|
||||||
preferPosition: AutoScrollPosition.middle);
|
eventIndex,
|
||||||
|
preferPosition: AutoScrollPosition.middle,
|
||||||
|
);
|
||||||
_updateScrollController();
|
_updateScrollController();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,11 +294,13 @@ class ChatDetailsController extends State<ChatDetails> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const fixedWidth = 360.0;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
members ??= Matrix.of(context).client.getRoomById(roomId).getParticipants();
|
members ??= Matrix.of(context).client.getRoomById(roomId).getParticipants();
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
width: 360.0,
|
width: fixedWidth,
|
||||||
child: ChatDetailsView(this),
|
child: ChatDetailsView(this),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -27,11 +27,13 @@ class ImageViewerController extends State<ImageViewer> {
|
|||||||
/// Save this file with a system call.
|
/// Save this file with a system call.
|
||||||
void saveFileAction() => widget.event.saveFile(context);
|
void saveFileAction() => widget.event.saveFile(context);
|
||||||
|
|
||||||
|
static const maxScaleFactor = 1.5;
|
||||||
|
|
||||||
/// Go back if user swiped it away
|
/// Go back if user swiped it away
|
||||||
void onInteractionEnds(ScaleEndDetails endDetails) {
|
void onInteractionEnds(ScaleEndDetails endDetails) {
|
||||||
if (PlatformInfos.usesTouchscreen == false) {
|
if (PlatformInfos.usesTouchscreen == false) {
|
||||||
if (endDetails.velocity.pixelsPerSecond.dy >
|
if (endDetails.velocity.pixelsPerSecond.dy >
|
||||||
MediaQuery.of(context).size.height * 1.50) {
|
MediaQuery.of(context).size.height * maxScaleFactor) {
|
||||||
Navigator.of(context, rootNavigator: false).pop();
|
Navigator.of(context, rootNavigator: false).pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,10 +155,7 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
|
|||||||
);
|
);
|
||||||
buttons.add(AdaptiveFlatButton(
|
buttons.add(AdaptiveFlatButton(
|
||||||
label: L10n.of(context).submit,
|
label: L10n.of(context).submit,
|
||||||
onPressed: () {
|
onPressed: () => checkInput(textEditingController.text),
|
||||||
input = textEditingController.text;
|
|
||||||
checkInput(input);
|
|
||||||
},
|
|
||||||
));
|
));
|
||||||
buttons.add(AdaptiveFlatButton(
|
buttons.add(AdaptiveFlatButton(
|
||||||
label: L10n.of(context).skip,
|
label: L10n.of(context).skip,
|
||||||
@ -207,11 +204,9 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
|
|||||||
buttons.add(AdaptiveFlatButton(
|
buttons.add(AdaptiveFlatButton(
|
||||||
label: L10n.of(context).reject,
|
label: L10n.of(context).reject,
|
||||||
textColor: Colors.red,
|
textColor: Colors.red,
|
||||||
onPressed: () {
|
onPressed: () => widget.request
|
||||||
widget.request.rejectVerification().then((_) {
|
.rejectVerification()
|
||||||
Navigator.of(context, rootNavigator: false).pop();
|
.then((_) => Navigator.of(context, rootNavigator: false).pop()),
|
||||||
});
|
|
||||||
},
|
|
||||||
));
|
));
|
||||||
buttons.add(AdaptiveFlatButton(
|
buttons.add(AdaptiveFlatButton(
|
||||||
label: L10n.of(context).accept,
|
label: L10n.of(context).accept,
|
||||||
|
@ -104,6 +104,8 @@ class SearchController extends State<Search> {
|
|||||||
String currentSearchTerm;
|
String currentSearchTerm;
|
||||||
List<Profile> foundProfiles = [];
|
List<Profile> foundProfiles = [];
|
||||||
|
|
||||||
|
static const searchUserDirectoryLimit = 10;
|
||||||
|
|
||||||
void searchUser(BuildContext context, String text) async {
|
void searchUser(BuildContext context, String text) async {
|
||||||
if (text.isEmpty) {
|
if (text.isEmpty) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -115,7 +117,10 @@ class SearchController extends State<Search> {
|
|||||||
final matrix = Matrix.of(context);
|
final matrix = Matrix.of(context);
|
||||||
SearchUserDirectoryResponse response;
|
SearchUserDirectoryResponse response;
|
||||||
try {
|
try {
|
||||||
response = await matrix.client.searchUserDirectory(text, limit: 10);
|
response = await matrix.client.searchUserDirectory(
|
||||||
|
text,
|
||||||
|
limit: searchUserDirectoryLimit,
|
||||||
|
);
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
foundProfiles = List<Profile>.from(response?.results ?? []);
|
foundProfiles = List<Profile>.from(response?.results ?? []);
|
||||||
if (foundProfiles.isEmpty && text.isValidMatrixId && text.sigil == '@') {
|
if (foundProfiles.isEmpty && text.isValidMatrixId && text.sigil == '@') {
|
||||||
|
@ -24,11 +24,13 @@ class SendFileDialog extends StatefulWidget {
|
|||||||
class _SendFileDialogState extends State<SendFileDialog> {
|
class _SendFileDialogState extends State<SendFileDialog> {
|
||||||
bool origImage = false;
|
bool origImage = false;
|
||||||
bool _isSending = false;
|
bool _isSending = false;
|
||||||
|
|
||||||
|
static const maxWidth = 1600;
|
||||||
Future<void> _send() async {
|
Future<void> _send() async {
|
||||||
var file = widget.file;
|
var file = widget.file;
|
||||||
if (file is MatrixImageFile && !origImage) {
|
if (file is MatrixImageFile && !origImage) {
|
||||||
try {
|
try {
|
||||||
file = await resizeImage(file, max: 1600);
|
file = await resizeImage(file, max: maxWidth);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// couldn't resize
|
// couldn't resize
|
||||||
}
|
}
|
||||||
|
@ -198,6 +198,8 @@ class EmotesSettingsController extends State<EmotesSettings> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const maxImageWidth = 1600;
|
||||||
|
|
||||||
void imagePickerAction(
|
void imagePickerAction(
|
||||||
ValueNotifier<ImagePackImageContent> controller) async {
|
ValueNotifier<ImagePackImageContent> controller) async {
|
||||||
final result =
|
final result =
|
||||||
@ -208,7 +210,7 @@ class EmotesSettingsController extends State<EmotesSettings> {
|
|||||||
name: result.fileName,
|
name: result.fileName,
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
file = await resizeImage(file, max: 1600);
|
file = await resizeImage(file, max: maxImageWidth);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user