forked from thunder-app/thunder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added initial support for incoming inbox feature, changes to readme, …
…and adjustments to compact view
- Loading branch information
Showing
22 changed files
with
572 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import 'package:bloc/bloc.dart'; | ||
import 'package:dio/dio.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:bloc_concurrency/bloc_concurrency.dart'; | ||
import 'package:lemmy/lemmy.dart'; | ||
import 'package:sentry_flutter/sentry_flutter.dart'; | ||
import 'package:stream_transform/stream_transform.dart'; | ||
import 'package:thunder/account/models/account.dart'; | ||
import 'package:thunder/core/auth/helpers/fetch_account.dart'; | ||
import 'package:thunder/core/singletons/lemmy_client.dart'; | ||
|
||
part 'inbox_event.dart'; | ||
part 'inbox_state.dart'; | ||
|
||
const throttleDuration = Duration(seconds: 1); | ||
const timeout = Duration(seconds: 3); | ||
|
||
EventTransformer<E> throttleDroppable<E>(Duration duration) { | ||
return (events, mapper) => droppable<E>().call(events.throttle(duration), mapper); | ||
} | ||
|
||
class InboxBloc extends Bloc<InboxEvent, InboxState> { | ||
InboxBloc() : super(const InboxState()) { | ||
on<GetInboxEvent>( | ||
_getInboxEvent, | ||
transformer: throttleDroppable(throttleDuration), | ||
); | ||
} | ||
|
||
Future<void> _getInboxEvent(GetInboxEvent event, emit) async { | ||
try { | ||
emit(state.copyWith(status: InboxStatus.loading)); | ||
|
||
Account? account = await fetchActiveProfileAccount(); | ||
Lemmy lemmy = LemmyClient.instance.lemmy; | ||
|
||
if (account?.jwt == null) { | ||
return emit(state.copyWith(status: InboxStatus.success)); | ||
} | ||
|
||
// Fetch all the things | ||
PrivateMessagesResponse privateMessagesResponse = await lemmy.getPrivateMessages( | ||
GetPrivateMessages(auth: account!.jwt!), | ||
); | ||
|
||
GetPersonMentionsResponse personMentions = await lemmy.getPersonMentions(GetPersonMentions( | ||
auth: account.jwt!, | ||
sort: CommentSortType.New, | ||
)); | ||
|
||
GetRepliesResponse repliesResponse = await lemmy.getReplies(GetReplies( | ||
auth: account.jwt!, | ||
)); | ||
|
||
return emit(state.copyWith( | ||
status: InboxStatus.success, | ||
privateMessages: privateMessagesResponse.privateMessages, | ||
mentions: personMentions.mentions, | ||
replies: repliesResponse.replies, | ||
)); | ||
} on DioException catch (e, s) { | ||
await Sentry.captureException(e, stackTrace: s); | ||
return emit(state.copyWith(status: InboxStatus.failure, errorMessage: e.message)); | ||
} catch (e, s) { | ||
await Sentry.captureException(e, stackTrace: s); | ||
return emit(state.copyWith(status: InboxStatus.failure, errorMessage: e.toString())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
part of 'inbox_bloc.dart'; | ||
|
||
abstract class InboxEvent extends Equatable { | ||
const InboxEvent(); | ||
|
||
@override | ||
List<Object> get props => []; | ||
} | ||
|
||
class GetInboxEvent extends InboxEvent { | ||
const GetInboxEvent(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
part of 'inbox_bloc.dart'; | ||
|
||
enum InboxStatus { initial, loading, refreshing, success, empty, failure } | ||
|
||
class InboxState extends Equatable { | ||
const InboxState({ | ||
this.status = InboxStatus.initial, | ||
this.errorMessage, | ||
this.privateMessages = const [], | ||
this.mentions = const [], | ||
this.replies = const [], | ||
}); | ||
|
||
final InboxStatus status; | ||
final String? errorMessage; | ||
|
||
final List<PrivateMessageView> privateMessages; | ||
final List<PersonMentionView> mentions; | ||
final List<CommentReplyView> replies; | ||
|
||
InboxState copyWith({ | ||
required InboxStatus status, | ||
String? errorMessage, | ||
List<PrivateMessageView>? privateMessages, | ||
List<PersonMentionView>? mentions, | ||
List<CommentReplyView>? replies, | ||
}) { | ||
return InboxState( | ||
status: status, | ||
errorMessage: errorMessage ?? this.errorMessage, | ||
privateMessages: privateMessages ?? [], | ||
mentions: mentions ?? [], | ||
replies: replies ?? [], | ||
); | ||
} | ||
|
||
@override | ||
List<Object?> get props => [status, errorMessage]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export 'pages/inbox_page.dart'; |
Oops, something went wrong.