Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show cross-posts #851

Merged
merged 7 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Added support for receiving share intents. Android only. - contribution from @ggichure
- Added ability to block instances from long-press menu and user settings
- Add more search options - contribution from @micahmo
- Added support for display cross-posts - contribution from @micahmo

### Changed
- Collapsed comments are easier to expand - contribution from @micahmo
Expand Down
3 changes: 3 additions & 0 deletions lib/community/pages/create_post_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class CreatePostPage extends StatefulWidget {
final DraftPost? previousDraftPost;

// used create post from action sheet
final String? title;
final String? text;
final File? image;
final String? url;
Expand All @@ -45,6 +46,7 @@ class CreatePostPage extends StatefulWidget {
this.previousDraftPost,
this.onUpdateDraft,
this.image,
this.title,
this.text,
this.url,
this.prePopulated = false,
Expand Down Expand Up @@ -100,6 +102,7 @@ class _CreatePostPageState extends State<CreatePostPage> {
});

if (widget.prePopulated == true) {
_titleTextController.text = widget.title ?? '';
_bodyTextController.text = widget.text ?? '';
_urlTextController.text = widget.url ?? '';
_getDataFromLink();
Expand Down
1 change: 1 addition & 0 deletions lib/core/enums/local_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum LocalSettings {
showPostAuthor(name: 'setting_general_show_post_author', label: 'Show Post Author'),
dimReadPosts(name: 'setting_dim_read_posts', label: 'Dim Read Posts'),
useAdvancedShareSheet(name: 'setting_use_advanced_share_sheet', label: 'Use Advanced Share Sheet'),
showCrossPosts(name: 'setting_show_cross_posts', label: 'Show Cross-Posts'),

/// -------------------------- Post Page Related Settings --------------------------
// Comment Related Settings
Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@
"search": "Search",
"@search": {},
"account": "Account",
"crossPostedTo": "Cross-posted to",
"andXMore": "and {count} more",
"createNewCrossPost": "Create new cross-post",
"@account": {},
"inbox": "Inbox",
"@inbox": {},
Expand Down
9 changes: 7 additions & 2 deletions lib/post/bloc/post_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,17 @@ class PostBloc extends Bloc<PostEvent, PostState> {

GetPostResponse? getPostResponse;

if (event.postId != null) {
getPostResponse = await lemmy.run(GetPost(id: event.postId!, auth: account?.jwt)).timeout(timeout, onTimeout: () {
// Retrieve the full post for moderators and cross-posts
int? postId = event.postId ?? event.postView?.postView.post.id;
if (postId != null) {
getPostResponse = await lemmy.run(GetPost(id: postId, auth: account?.jwt)).timeout(timeout, onTimeout: () {
throw Exception(AppLocalizations.of(GlobalContext.context)!.timeoutComments);
});
}

PostViewMedia? postView = event.postView;
List<CommunityModeratorView>? moderators;
List<PostView>? crossPosts;

if (getPostResponse != null) {
// Parse the posts and add in media information which is used elsewhere in the app
Expand All @@ -120,6 +123,7 @@ class PostBloc extends Bloc<PostEvent, PostState> {
postView = posts.first;

moderators = getPostResponse.moderators;
crossPosts = getPostResponse.crossPosts;
}

// If we can't get mods from the post response, fallback to getting the whole community.
Expand All @@ -140,6 +144,7 @@ class PostBloc extends Bloc<PostEvent, PostState> {
postView: postView,
communityId: postView?.postView.post.communityId,
moderators: moderators,
crossPosts: crossPosts,
selectedCommentPath: event.selectedCommentPath,
selectedCommentId: event.selectedCommentId,
newlyCreatedCommentId: event.newlyCreatedCommentId));
Expand Down
5 changes: 5 additions & 0 deletions lib/post/bloc/post_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class PostState extends Equatable {
this.commentCount = 0,
this.communityId,
this.moderators,
this.crossPosts,
this.hasReachedCommentEnd = false,
this.errorMessage,
this.sortType,
Expand All @@ -36,6 +37,7 @@ class PostState extends Equatable {
final int? postId;
final int? communityId;
final List<CommunityModeratorView>? moderators;
final List<PostView>? crossPosts;
final PostViewMedia? postView;

// Comment related data
Expand Down Expand Up @@ -71,6 +73,7 @@ class PostState extends Equatable {
bool? hasReachedCommentEnd,
int? communityId,
List<CommunityModeratorView>? moderators,
List<PostView>? crossPosts,
String? errorMessage,
CommentSortType? sortType,
IconData? sortTypeIcon,
Expand All @@ -93,6 +96,7 @@ class PostState extends Equatable {
hasReachedCommentEnd: hasReachedCommentEnd ?? this.hasReachedCommentEnd,
communityId: communityId ?? this.communityId,
moderators: moderators ?? this.moderators,
crossPosts: crossPosts ?? this.crossPosts,
errorMessage: errorMessage ?? this.errorMessage,
sortType: sortType ?? this.sortType,
sortTypeIcon: sortTypeIcon ?? this.sortTypeIcon,
Expand All @@ -116,6 +120,7 @@ class PostState extends Equatable {
commentCount,
communityId,
moderators,
crossPosts,
errorMessage,
hasReachedCommentEnd,
sortType,
Expand Down
1 change: 1 addition & 0 deletions lib/post/pages/post_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ class _PostPageState extends State<PostPage> {
itemPositionsListener: _itemPositionsListener,
hasReachedCommentEnd: state.hasReachedCommentEnd,
moderators: state.moderators,
crossPosts: state.crossPosts,
),
);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/post/pages/post_page_success.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class PostPageSuccess extends StatefulWidget {
final bool viewFullCommentsRefreshing;

final List<CommunityModeratorView>? moderators;
final List<PostView>? crossPosts;

const PostPageSuccess({
super.key,
Expand All @@ -52,6 +53,7 @@ class PostPageSuccess extends StatefulWidget {
this.moddingCommentId,
this.viewFullCommentsRefreshing = false,
required this.moderators,
required this.crossPosts,
});

@override
Expand Down Expand Up @@ -160,6 +162,7 @@ class _PostPageSuccessState extends State<PostPageSuccess> {
});
},
moderators: widget.moderators,
crossPosts: widget.crossPosts,
),
),
],
Expand Down
3 changes: 3 additions & 0 deletions lib/post/widgets/comment_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class CommentSubview extends StatefulWidget {
final DateTime now;

final List<CommunityModeratorView>? moderators;
final List<PostView>? crossPosts;

const CommentSubview({
super.key,
Expand All @@ -58,6 +59,7 @@ class CommentSubview extends StatefulWidget {
this.viewFullCommentsRefreshing = false,
required this.now,
required this.moderators,
required this.crossPosts,
});

@override
Expand Down Expand Up @@ -135,6 +137,7 @@ class _CommentSubviewState extends State<CommentSubview> with SingleTickerProvid
useDisplayNames: state.useDisplayNames,
postViewMedia: widget.postViewMedia!,
moderators: widget.moderators,
crossPosts: widget.crossPosts,
);
}
if (widget.hasReachedCommentEnd == false && widget.comments.isEmpty) {
Expand Down
Loading