Merge pull request #862 from pangeachat/sentry

don't call fetchOwnProfile is userID is null
This commit is contained in:
ggurdin 2024-10-29 09:12:35 -04:00 committed by GitHub
commit 40bb014eb2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 124 additions and 131 deletions

View file

@ -486,10 +486,11 @@ class ChatController extends State<ChatPageWithRoom>
void setReadMarker({String? eventId}) {
// #Pangea
if (eventId != null &&
(eventId.contains("web") ||
eventId.contains("android") ||
eventId.contains("ios"))) {
if (room.client.userID == null ||
eventId != null &&
(eventId.contains("web") ||
eventId.contains("android") ||
eventId.contains("ios"))) {
return;
}
// Pangea#

View file

@ -186,7 +186,11 @@ class Message extends StatelessWidget {
if (animateIn && resetAnimateIn != null) {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
animateIn = false;
setState(resetAnimateIn);
// #Pangea
if (context.mounted) {
// Pangea#
setState(resetAnimateIn);
}
});
}
return AnimatedSize(

View file

@ -214,62 +214,71 @@ class ClientChooserButton extends StatelessWidget {
var clientCount = 0;
matrix.accountBundles.forEach((key, value) => clientCount += value.length);
return FutureBuilder<Profile>(
future: matrix.client.fetchOwnProfile(),
builder: (context, snapshot) => Stack(
alignment: Alignment.center,
children: [
// #Pangea
// ...List.generate(
// clientCount,
// (index) => KeyBoardShortcuts(
// keysToPress: _buildKeyboardShortcut(index + 1),
// helpLabel: L10n.of(context)!.switchToAccount(index + 1),
// onKeysPressed: () => _handleKeyboardShortcut(
// matrix,
// index,
// context,
// ),
// child: const SizedBox.shrink(),
// ),
// ),
// KeyBoardShortcuts(
// keysToPress: {
// LogicalKeyboardKey.controlLeft,
// LogicalKeyboardKey.tab,
// },
// helpLabel: L10n.of(context)!.nextAccount,
// onKeysPressed: () => _nextAccount(matrix, context),
// child: const SizedBox.shrink(),
// ),
// KeyBoardShortcuts(
// keysToPress: {
// LogicalKeyboardKey.controlLeft,
// LogicalKeyboardKey.shiftLeft,
// LogicalKeyboardKey.tab,
// },
// helpLabel: L10n.of(context)!.previousAccount,
// onKeysPressed: () => _previousAccount(matrix, context),
// child: const SizedBox.shrink(),
// ),
// Pangea#
PopupMenuButton<Object>(
onSelected: (o) => _clientSelected(o, context),
itemBuilder: _bundleMenuItems,
child: Material(
color: Colors.transparent,
borderRadius: BorderRadius.circular(99),
child: Avatar(
mxContent: snapshot.data?.avatarUrl,
name: snapshot.data?.displayName ??
matrix.client.userID!.localpart,
size: 32,
),
// #Pangea
return matrix.client.userID == null
? const SizedBox(
height: 16,
width: 16,
child: CircularProgressIndicator.adaptive(),
)
:
// Pangea#
FutureBuilder<Profile>(
future: matrix.client.fetchOwnProfile(),
builder: (context, snapshot) => Stack(
alignment: Alignment.center,
children: [
// #Pangea
// ...List.generate(
// clientCount,
// (index) => KeyBoardShortcuts(
// keysToPress: _buildKeyboardShortcut(index + 1),
// helpLabel: L10n.of(context)!.switchToAccount(index + 1),
// onKeysPressed: () => _handleKeyboardShortcut(
// matrix,
// index,
// context,
// ),
// child: const SizedBox.shrink(),
// ),
// ),
// KeyBoardShortcuts(
// keysToPress: {
// LogicalKeyboardKey.controlLeft,
// LogicalKeyboardKey.tab,
// },
// helpLabel: L10n.of(context)!.nextAccount,
// onKeysPressed: () => _nextAccount(matrix, context),
// child: const SizedBox.shrink(),
// ),
// KeyBoardShortcuts(
// keysToPress: {
// LogicalKeyboardKey.controlLeft,
// LogicalKeyboardKey.shiftLeft,
// LogicalKeyboardKey.tab,
// },
// helpLabel: L10n.of(context)!.previousAccount,
// onKeysPressed: () => _previousAccount(matrix, context),
// child: const SizedBox.shrink(),
// ),
// Pangea#
PopupMenuButton<Object>(
onSelected: (o) => _clientSelected(o, context),
itemBuilder: _bundleMenuItems,
child: Material(
color: Colors.transparent,
borderRadius: BorderRadius.circular(99),
child: Avatar(
mxContent: snapshot.data?.avatarUrl,
name: snapshot.data?.displayName ??
matrix.client.userID!.localpart,
size: 32,
),
),
),
],
),
),
],
),
);
);
}
Set<LogicalKeyboardKey>? _buildKeyboardShortcut(int index) {

View file

@ -4,7 +4,6 @@ import 'package:fluffychat/pangea/utils/error_handler.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
enum InstructionsEnum {
@ -19,24 +18,16 @@ enum InstructionsEnum {
}
extension InstructionsEnumExtension on InstructionsEnum {
String title(BuildContext context) {
if (!context.mounted) {
ErrorHandler.logError(
e: Exception("Context not mounted"),
m: 'InstructionsEnumExtension.title for $this',
);
debugger(when: kDebugMode);
return '';
}
String title(L10n l10n) {
switch (this) {
case InstructionsEnum.itInstructions:
return L10n.of(context)!.itInstructionsTitle;
return l10n.itInstructionsTitle;
case InstructionsEnum.clickMessage:
return L10n.of(context)!.clickMessageTitle;
return l10n.clickMessageTitle;
case InstructionsEnum.blurMeansTranslate:
return L10n.of(context)!.blurMeansTranslateTitle;
return l10n.blurMeansTranslateTitle;
case InstructionsEnum.tooltipInstructions:
return L10n.of(context)!.tooltipInstructionsTitle;
return l10n.tooltipInstructionsTitle;
case InstructionsEnum.clickAgainToDeselect:
case InstructionsEnum.speechToText:
case InstructionsEnum.l1Translation:
@ -53,46 +44,30 @@ extension InstructionsEnumExtension on InstructionsEnum {
}
}
String body(BuildContext context) {
if (!context.mounted) {
ErrorHandler.logError(
e: Exception("Context not mounted"),
m: 'InstructionsEnumExtension.body for $this',
);
debugger(when: kDebugMode);
return "";
}
String body(L10n l10n) {
switch (this) {
case InstructionsEnum.itInstructions:
return L10n.of(context)!.itInstructionsBody;
return l10n.itInstructionsBody;
case InstructionsEnum.clickMessage:
return L10n.of(context)!.clickMessageBody;
return l10n.clickMessageBody;
case InstructionsEnum.blurMeansTranslate:
return L10n.of(context)!.blurMeansTranslateBody;
return l10n.blurMeansTranslateBody;
case InstructionsEnum.speechToText:
return L10n.of(context)!.speechToTextBody;
return l10n.speechToTextBody;
case InstructionsEnum.l1Translation:
return L10n.of(context)!.l1TranslationBody;
return l10n.l1TranslationBody;
case InstructionsEnum.translationChoices:
return L10n.of(context)!.translationChoicesBody;
return l10n.translationChoicesBody;
case InstructionsEnum.clickAgainToDeselect:
return L10n.of(context)!.clickTheWordAgainToDeselect;
return l10n.clickTheWordAgainToDeselect;
case InstructionsEnum.tooltipInstructions:
return PlatformInfos.isMobile
? L10n.of(context)!.tooltipInstructionsMobileBody
: L10n.of(context)!.tooltipInstructionsBrowserBody;
? l10n.tooltipInstructionsMobileBody
: l10n.tooltipInstructionsBrowserBody;
}
}
bool toggledOff(BuildContext context) {
if (!context.mounted) {
ErrorHandler.logError(
e: Exception("Context not mounted"),
m: 'InstructionsEnumExtension.toggledOff for $this',
);
debugger(when: kDebugMode);
return false;
}
bool toggledOff() {
final instructionSettings =
MatrixState.pangeaController.userController.profile.instructionSettings;
switch (this) {

View file

@ -2,6 +2,7 @@ import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/pangea/enum/instructions_enum.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
class InlineTooltip extends StatelessWidget {
final InstructionsEnum instructionsEnum;
@ -15,7 +16,7 @@ class InlineTooltip extends StatelessWidget {
@override
Widget build(BuildContext context) {
if (instructionsEnum.toggledOff(context)) {
if (instructionsEnum.toggledOff()) {
return const SizedBox();
}
@ -42,7 +43,7 @@ class InlineTooltip extends StatelessWidget {
// Text in the middle
Center(
child: Text(
instructionsEnum.body(context),
instructionsEnum.body(L10n.of(context)!),
style: TextStyle(
color: Theme.of(context).colorScheme.onSurface,
height: 1.5,

View file

@ -80,7 +80,7 @@ class InstructionsController {
}
_instructionsShown[key.toString()] = true;
if (key.toggledOff(context)) {
if (key.toggledOff()) {
return;
}
if (L10n.of(context) == null) {
@ -94,33 +94,36 @@ class InstructionsController {
final botStyle = BotStyle.text(context);
Future.delayed(
const Duration(seconds: 1),
() => OverlayUtil.showPositionedCard(
context: context,
backDropToDismiss: false,
cardToShow: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
CardHeader(
text: key.title(context),
botExpression: BotExpression.idle,
onClose: () => {_instructionsClosed[key.toString()] = true},
),
const SizedBox(height: 10.0),
Padding(
padding: const EdgeInsets.all(6.0),
child: Text(
key.body(context),
style: botStyle,
() {
if (!context.mounted) return;
OverlayUtil.showPositionedCard(
context: context,
backDropToDismiss: false,
cardToShow: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
CardHeader(
text: key.title(L10n.of(context)!),
botExpression: BotExpression.idle,
onClose: () => {_instructionsClosed[key.toString()] = true},
),
),
if (showToggle) InstructionsToggle(instructionsKey: key),
],
),
maxHeight: 300,
maxWidth: 300,
transformTargetId: transformTargetKey,
closePrevOverlay: false,
),
const SizedBox(height: 10.0),
Padding(
padding: const EdgeInsets.all(6.0),
child: Text(
key.body(L10n.of(context)!),
style: botStyle,
),
),
if (showToggle) InstructionsToggle(instructionsKey: key),
],
),
maxHeight: 300,
maxWidth: 300,
transformTargetId: transformTargetKey,
closePrevOverlay: false,
);
},
);
}
}
@ -152,7 +155,7 @@ class InstructionsToggleState extends State<InstructionsToggle> {
return SwitchListTile.adaptive(
activeColor: AppConfig.activeToggleColor,
title: Text(L10n.of(context)!.doNotShowAgain),
value: widget.instructionsKey.toggledOff(context),
value: widget.instructionsKey.toggledOff(),
onChanged: ((value) async {
pangeaController.instructions.setToggledOff(
widget.instructionsKey,