Skip to content

Commit

Permalink
Merge pull request #21 from pangeachat/sentry-fixes
Browse files Browse the repository at this point in the history
Sentry Fixes
  • Loading branch information
wcjord authored Jan 2, 2024
2 parents 4946ffe + 700fc83 commit d1152d5
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 108 deletions.
19 changes: 14 additions & 5 deletions lib/config/routes.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import 'dart:async';

import 'package:flutter/cupertino.dart';

import 'package:go_router/go_router.dart';

import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/pages/archive/archive.dart';
import 'package:fluffychat/pages/chat/chat.dart';
Expand Down Expand Up @@ -42,6 +38,9 @@ import 'package:fluffychat/widgets/layouts/empty_page.dart';
import 'package:fluffychat/widgets/layouts/two_column_layout.dart';
import 'package:fluffychat/widgets/log_view.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/cupertino.dart';
import 'package:go_router/go_router.dart';

import '../pangea/pages/analytics/class_analytics/class_analytics.dart';
import '../pangea/pages/analytics/class_list/class_list.dart';

Expand Down Expand Up @@ -254,13 +253,23 @@ abstract class AppRoutes {
GoRoute(
// #Pangea
// path: 'newgroup',
path: 'newgroup/:spaceid',
path: 'newgroup',
// Pangea#
pageBuilder: (context, state) => defaultPageBuilder(
context,
const NewGroup(),
),
redirect: loggedOutRedirect,
routes: [
GoRoute(
path: ':spaceid',
pageBuilder: (context, state) => defaultPageBuilder(
context,
const NewGroup(),
),
redirect: loggedOutRedirect,
),
],
),
GoRoute(
path: 'newspace',
Expand Down
38 changes: 13 additions & 25 deletions lib/pages/chat_list/chat_list_body.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import 'package:flutter/material.dart';

import 'package:animations/animations.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:matrix/matrix.dart';

import 'package:fluffychat/pages/chat_list/chat_list.dart';
import 'package:fluffychat/pages/chat_list/chat_list_item.dart';
import 'package:fluffychat/pages/chat_list/search_title.dart';
Expand All @@ -15,6 +10,10 @@ import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
import 'package:fluffychat/utils/stream_extension.dart';
import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/public_room_bottom_sheet.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:matrix/matrix.dart';

import '../../config/themes.dart';
import '../../widgets/connection_status_header.dart';
import '../../widgets/matrix.dart';
Expand Down Expand Up @@ -196,27 +195,16 @@ class ChatListViewBody extends StatelessWidget {
if (client.prevBatch != null &&
rooms.isEmpty &&
!controller.isSearchMode) ...[
Padding(
padding: const EdgeInsets.all(32.0),
// #Pangea
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
'private_chat_wallpaper.png',
height: 256,
),
],
),
// child: Icon(
// CupertinoIcons.chat_bubble_2,
// size: 128,
// color:
// Theme.of(context).colorScheme.onInverseSurface,
// ),
// Pangea#
),
// #Pangea
// Padding(
// padding: const EdgeInsets.all(32.0),
// child: Icon(
// CupertinoIcons.chat_bubble_2,
// size: 128,
// color:
// Theme.of(context).colorScheme.onInverseSurface,
// ),
// ),
Center(
child: ChatListBodyStartText(
controller: controller,
Expand Down
10 changes: 4 additions & 6 deletions lib/pages/chat_list/start_chat_fab.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import 'dart:core';

import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/pages/chat_list/chat_list.dart';
import 'package:flutter/material.dart';

import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:go_router/go_router.dart';

import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/pages/chat_list/chat_list.dart';

class StartChatFloatingActionButton extends StatelessWidget {
final ActiveFilter activeFilter;
final ValueNotifier<bool> scrolledToTop;
Expand All @@ -29,7 +27,7 @@ class StartChatFloatingActionButton extends StatelessWidget {
void _onPressed(BuildContext context) {
//#Pangea
if (controller.activeSpaceId != null) {
context.go('/rooms/newgroup/${controller.activeSpaceId}');
context.go('/rooms/newgroup/${controller.activeSpaceId ?? ''}');
return;
}
//Pangea#
Expand All @@ -43,7 +41,7 @@ class StartChatFloatingActionButton extends StatelessWidget {
case ActiveFilter.groups:
// #Pangea
// context.go('/rooms/newgroup');
context.go('/rooms/newgroup/${controller.activeSpaceId}');
context.go('/rooms/newgroup/${controller.activeSpaceId ?? ''}');
// Pangea#
break;
case ActiveFilter.spaces:
Expand Down
24 changes: 15 additions & 9 deletions lib/pangea/controllers/subscription_controller.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import 'dart:async';
import 'dart:convert';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:http/http.dart';
import 'package:purchases_flutter/purchases_flutter.dart';
import 'package:url_launcher/url_launcher_string.dart';

import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/pangea/constants/local.key.dart';
import 'package:fluffychat/pangea/controllers/base_controller.dart';
Expand All @@ -23,6 +15,13 @@ import 'package:fluffychat/pangea/utils/error_handler.dart';
import 'package:fluffychat/pangea/utils/firebase_analytics.dart';
import 'package:fluffychat/pangea/widgets/subscription/subscription_paywall.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:http/http.dart';
import 'package:purchases_flutter/purchases_flutter.dart';
import 'package:url_launcher/url_launcher_string.dart';

class SubscriptionController extends BaseController {
late PangeaController _pangeaController;
Expand Down Expand Up @@ -242,8 +241,15 @@ class SubscriptionController extends BaseController {
await Purchases.purchasePackage(selectedSubscription.package!);
GoogleAnalytics.updateUserSubscriptionStatus(true);
} catch (err) {
final errCode = PurchasesErrorHelper.getErrorCode(
err as PlatformException,
);
if (errCode == PurchasesErrorCode.purchaseCancelledError) {
debugPrint("User cancelled purchase");
return;
}
ErrorHandler.logError(
m: "Failed to purchase revenuecat package for user ${_pangeaController.matrixState.client.userID}",
m: "Failed to purchase revenuecat package for user ${_pangeaController.matrixState.client.userID} with error code $errCode",
s: StackTrace.current,
);
return;
Expand Down
47 changes: 19 additions & 28 deletions lib/pangea/extensions/pangea_room_extension.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import 'dart:async';
import 'dart:developer';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import 'package:matrix/matrix.dart';
import 'package:matrix/src/utils/space_child.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

import 'package:fluffychat/pangea/constants/class_default_values.dart';
import 'package:fluffychat/pangea/constants/model_keys.dart';
import 'package:fluffychat/pangea/constants/pangea_room_types.dart';
import 'package:fluffychat/pangea/models/class_model.dart';
import 'package:fluffychat/pangea/models/pangea_message_event.dart';
import 'package:fluffychat/pangea/utils/bot_name.dart';
import 'package:fluffychat/pangea/utils/error_handler.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:matrix/matrix.dart';
import 'package:matrix/src/utils/space_child.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

import '../../config/app_config.dart';
import '../constants/pangea_event_types.dart';
import '../enum/construct_type_enum.dart';
Expand Down Expand Up @@ -150,20 +149,19 @@ extension PangeaRoom on Room {
bool isChild(String roomId) =>
isSpace && spaceChildren.any((room) => room.roomId == roomId);

bool isFirstOrSecondChild(String roomId) =>
isSpace && spaceChildren.any((room) => room.roomId == roomId) ||
spaceChildren
.where(
(sc) => sc.roomId != null,
)
.map(
(sc) => client.getRoomById(sc.roomId!),
)
.any(
(room) =>
room != null &&
room.spaceChildren.any((room) => room.roomId == roomId),
);
bool isFirstOrSecondChild(String roomId) {
return isSpace &&
(spaceChildren.any((room) => room.roomId == roomId) ||
spaceChildren
.where((sc) => sc.roomId != null)
.map((sc) => client.getRoomById(sc.roomId!))
.any(
(room) =>
room != null &&
room.isSpace &&
room.spaceChildren.any((room) => room.roomId == roomId),
));
}

//note this only will return rooms that the user has joined or been invited to
List<SpaceChild> get childrenAndGrandChildren {
Expand Down Expand Up @@ -513,13 +511,6 @@ extension PangeaRoom on Room {
.where((element) => !element.isSpace)
.toList();

if (spaceChildren.length != spaceChats.length) {
// debugger(when: kDebugMode);
ErrorHandler.logError(
m: "spaceChildren.length > chats.length in updateMyLearningAnalyticsForClass",
);
}

final List<Future<List<RecentMessageRecord>>> msgListFutures = [];
for (final chat in spaceChats) {
msgListFutures.add(chat._messageListForChat);
Expand Down
9 changes: 4 additions & 5 deletions lib/pangea/models/it_response_model.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import 'package:flutter/material.dart';

import 'package:collection/collection.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';

import 'package:fluffychat/pangea/constants/choreo_constants.dart';
import 'package:fluffychat/pangea/constants/model_keys.dart';
import 'package:fluffychat/pangea/extensions/my_list_extionsion.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';

import 'lemma.dart';

class ITResponseModel {
Expand Down Expand Up @@ -114,7 +113,7 @@ class Continuance {
.cast<Lemma>()
: [];
return Continuance(
probability: json['probability'],
probability: json['probability'] as double,
level: json['level'],
text: json['text'],
description: json['description'] ?? "",
Expand Down
35 changes: 16 additions & 19 deletions lib/pangea/models/pangea_message_event.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import 'package:flutter/material.dart';

import 'package:collection/collection.dart';
import 'package:matrix/matrix.dart';

import 'package:fluffychat/pangea/constants/model_keys.dart';
import 'package:fluffychat/pangea/constants/pangea_message_types.dart';
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
import 'package:fluffychat/pangea/models/choreo_record.dart';
import 'package:fluffychat/pangea/models/message_data_models.dart';
import 'package:fluffychat/pangea/models/pangea_representation_event.dart';
import 'package:fluffychat/pangea/utils/bot_name.dart';
import 'package:flutter/material.dart';
import 'package:matrix/matrix.dart';

import '../../widgets/matrix.dart';
import '../constants/language_keys.dart';
import '../constants/model_keys.dart';
import '../constants/pangea_event_types.dart';
import '../enum/use_type.dart';
import '../utils/error_handler.dart';
Expand Down Expand Up @@ -85,20 +84,20 @@ class PangeaMessageEvent {

_representations = [];

if (_latestEdit.content[ModelKey.originalSent] != null) {
final bool latestHasTokens =
_latestEdit.content[ModelKey.tokensSent] != null;

if (_latestEdit.content[ModelKey.originalSent] != null && latestHasTokens) {
try {
_representations!.add(
RepresentationEvent(
content: PangeaRepresentation.fromJson(
_latestEdit.content[ModelKey.originalSent]
as Map<String, dynamic>,
),
tokens: _latestEdit.content[ModelKey.tokensSent] != null
? PangeaMessageTokens.fromJson(
_latestEdit.content[ModelKey.tokensSent]
as Map<String, dynamic>,
)
: null,
tokens: PangeaMessageTokens.fromJson(
_latestEdit.content[ModelKey.tokensSent] as Map<String, dynamic>,
),
choreo: _latestEdit.content[ModelKey.choreoRecord] != null
? ChoreoRecord.fromJson(
_latestEdit.content[ModelKey.choreoRecord]
Expand All @@ -116,19 +115,17 @@ class PangeaMessageEvent {
}
}

if (_latestEdit.content[ModelKey.originalWritten] != null) {
if (_latestEdit.content[ModelKey.originalWritten] != null &&
latestHasTokens) {
_representations!.add(
RepresentationEvent(
content: PangeaRepresentation.fromJson(
_latestEdit.content[ModelKey.originalWritten]
as Map<String, dynamic>,
),
tokens: _latestEdit.content[ModelKey.tokensWritten] != null
? PangeaMessageTokens.fromJson(
_latestEdit.content[ModelKey.tokensWritten]
as Map<String, dynamic>,
)
: null,
tokens: PangeaMessageTokens.fromJson(
_latestEdit.content[ModelKey.tokensWritten] as Map<String, dynamic>,
),
timeline: timeline,
),
);
Expand Down
Loading

0 comments on commit d1152d5

Please sign in to comment.