Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into feature/create-p…
Browse files Browse the repository at this point in the history
…ost-before-community
  • Loading branch information
micahmo committed Oct 19, 2023
2 parents 0da587c + d45ab48 commit aa93dcc
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 40 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- Show trending communities on search page - contribution from @micahmo
- Added new post sharing options - contribution from @micahmo
- Added Read All in inbox. - contribution from @ggichure
- Open links to posts in the app instead of browser - contribution from @micahmo
- Open links to posts and comments in the app instead of browser - contribution from @micahmo
- Added support for lemmy 0.19.x authentication - contribution from @micahmo
- Added support for accessibility profiles in settings - contribution from @micahmo
- Added option to enable/disable full screen navigation swipe gesture to go back (applies when LTR gestures are disabled)
Expand Down
2 changes: 1 addition & 1 deletion lib/globals.dart
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const String currentVersion = '0.2.5-1+21';
const String currentVersion = '0.2.5-2+22';
1 change: 1 addition & 0 deletions lib/search/pages/search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class _SearchPageState extends State<SearchPage> with AutomaticKeepAliveClientMi
child: Stack(
children: [
TextField(
keyboardType: TextInputType.url,
focusNode: searchTextFieldFocus,
onChanged: (value) => debounce(const Duration(milliseconds: 300), _onChange, [context, value]),
controller: _controller,
Expand Down
33 changes: 2 additions & 31 deletions lib/shared/comment_reference.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:thunder/thunder/bloc/thunder_bloc.dart';
import 'package:thunder/utils/date_time.dart';
import 'package:thunder/utils/instance.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:thunder/utils/navigate_comment.dart';
import 'package:thunder/utils/numbers.dart';

import '../core/enums/swipe_action.dart';
Expand Down Expand Up @@ -95,37 +96,7 @@ class _CommentReferenceState extends State<CommentReference> {
${formatTimeToString(dateTime: (widget.comment.comment.updated ?? widget.comment.comment.published).toIso8601String())}\n
${widget.comment.comment.content}""",
child: InkWell(
onTap: () async {
AccountBloc accountBloc = context.read<AccountBloc>();
AuthBloc authBloc = context.read<AuthBloc>();
ThunderBloc thunderBloc = context.read<ThunderBloc>();

final ThunderState state = context.read<ThunderBloc>().state;
final bool reduceAnimations = state.reduceAnimations;

// To to specific post for now, in the future, will be best to scroll to the position of the comment
await Navigator.of(context).push(
SwipeablePageRoute(
transitionDuration: reduceAnimations ? const Duration(milliseconds: 100) : null,
backGestureDetectionWidth: 45,
canOnlySwipeFromEdge: disableFullPageSwipe(isUserLoggedIn: authBloc.state.isLoggedIn, state: thunderBloc.state, isPostPage: true) || !state.enableFullScreenSwipeNavigationGesture,
builder: (context) => MultiBlocProvider(
providers: [
BlocProvider.value(value: accountBloc),
BlocProvider.value(value: authBloc),
BlocProvider.value(value: thunderBloc),
BlocProvider(create: (context) => PostBloc()),
],
child: PostPage(
selectedCommentId: widget.comment.comment.id,
selectedCommentPath: widget.comment.comment.path,
postId: widget.comment.post.id,
onPostUpdated: (PostViewMedia postViewMedia) => {},
),
),
),
);
},
onTap: () async => await navigateToComment(context, widget.comment),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0),
child: Column(
Expand Down
19 changes: 18 additions & 1 deletion lib/shared/common_markdown_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:thunder/shared/image_preview.dart';
import 'package:thunder/utils/links.dart';
import 'package:thunder/thunder/bloc/thunder_bloc.dart';
import 'package:thunder/utils/instance.dart';
import 'package:thunder/utils/navigate_comment.dart';
import 'package:thunder/utils/navigate_post.dart';
import 'package:thunder/utils/navigate_user.dart';

Expand Down Expand Up @@ -116,7 +117,23 @@ class CommonMarkdownBody extends StatelessWidget {
}
}

// TODO: Try navigating to comment
// Try navigating to comment
int? commentId = await getLemmyCommentId(parsedUrl);
if (commentId != null) {
try {
FullCommentView fullCommentView = await lemmy.run(GetComment(
id: commentId,
auth: account?.jwt,
));

if (context.mounted) {
navigateToComment(context, fullCommentView.commentView);
return;
}
} catch (e) {
// Ignore exception, if it's not a valid comment, we'll perform the next fallback
}
}

// Fallback: open link in browser
if (url != null) {
Expand Down
26 changes: 26 additions & 0 deletions lib/utils/instance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,32 @@ Future<int?> getLemmyPostId(String text) async {
return null;
}

final RegExp _comment = RegExp(r'^(https?:\/\/)(.*)\/comment\/([0-9]*).*$');
Future<int?> getLemmyCommentId(String text) async {
LemmyApiV3 lemmy = LemmyClient.instance.lemmyApiV3;

final RegExpMatch? commentMatch = _comment.firstMatch(text);
if (commentMatch != null) {
final String? instance = commentMatch.group(2);
final int? commentId = int.tryParse(commentMatch.group(3)!);
if (commentId != null) {
if (instance == lemmy.host) {
return commentId;
} else {
// This is a comment on another instance. Try to resolve it
try {
final ResolveObjectResponse resolveObjectResponse = await lemmy.run(ResolveObject(q: text));
return resolveObjectResponse.comment?.comment.id;
} catch (e) {
return null;
}
}
}
}

return null;
}

class GetInstanceIconResponse {
final String? icon;
final bool success;
Expand Down
43 changes: 43 additions & 0 deletions lib/utils/navigate_comment.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lemmy_api_client/v3.dart';
import 'package:swipeable_page_route/swipeable_page_route.dart';
import 'package:thunder/account/bloc/account_bloc.dart';
import 'package:thunder/core/auth/bloc/auth_bloc.dart';
import 'package:thunder/core/models/post_view_media.dart';
import 'package:thunder/post/bloc/post_bloc.dart';
import 'package:thunder/post/pages/post_page.dart';
import 'package:thunder/thunder/bloc/thunder_bloc.dart';
import 'package:thunder/utils/swipe.dart';

Future<void> navigateToComment(BuildContext context, CommentView commentView) async {
AccountBloc accountBloc = context.read<AccountBloc>();
AuthBloc authBloc = context.read<AuthBloc>();
ThunderBloc thunderBloc = context.read<ThunderBloc>();

final ThunderState state = context.read<ThunderBloc>().state;
final bool reduceAnimations = state.reduceAnimations;

// To to specific post for now, in the future, will be best to scroll to the position of the comment
await Navigator.of(context).push(
SwipeablePageRoute(
transitionDuration: reduceAnimations ? const Duration(milliseconds: 100) : null,
backGestureDetectionWidth: 45,
canOnlySwipeFromEdge: disableFullPageSwipe(isUserLoggedIn: authBloc.state.isLoggedIn, state: thunderBloc.state, isPostPage: true) || !state.enableFullScreenSwipeNavigationGesture,
builder: (context) => MultiBlocProvider(
providers: [
BlocProvider.value(value: accountBloc),
BlocProvider.value(value: authBloc),
BlocProvider.value(value: thunderBloc),
BlocProvider(create: (context) => PostBloc()),
],
child: PostPage(
selectedCommentId: commentView.comment.id,
selectedCommentPath: commentView.comment.path,
postId: commentView.post.id,
onPostUpdated: (PostViewMedia postViewMedia) => {},
),
),
),
);
}
10 changes: 5 additions & 5 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -925,10 +925,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -1539,10 +1539,10 @@ packages:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
sha256: "14f1f70c51119012600c5f1f60ca68efda5a9b6077748163c6af2893ec5df8fc"
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
version: "0.2.1-beta"
web_socket_channel:
dependency: transitive
description:
Expand Down Expand Up @@ -1624,5 +1624,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.1.0 <4.0.0"
dart: ">=3.2.0-157.0.dev <4.0.0"
flutter: ">=3.13.0"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: thunder
description: An open-source cross-platform Lemmy client for iOS and Android built with Flutter
publish_to: "none"
version: 0.2.5-1+21
version: 0.2.5-2+22

environment:
sdk: "^3.0.0"
Expand Down

0 comments on commit aa93dcc

Please sign in to comment.