-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TW-898: fix error when unpin message in current selected pin
- Loading branch information
1 parent
d4c2ffa
commit 28d28a1
Showing
15 changed files
with
218 additions
and
83 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,43 @@ | ||
import 'package:fluffychat/app_state/failure.dart'; | ||
import 'package:fluffychat/app_state/success.dart'; | ||
|
||
class UpdatePinnedEventsInitial extends Success { | ||
@override | ||
List<Object?> get props => []; | ||
} | ||
|
||
class UpdatePinnedEventsSuccess extends Success { | ||
final String eventId; | ||
|
||
const UpdatePinnedEventsSuccess(this.eventId); | ||
|
||
@override | ||
List<Object?> get props => [eventId]; | ||
} | ||
|
||
class UpdatePinnedEventsFailure extends Failure { | ||
final Exception exception; | ||
|
||
const UpdatePinnedEventsFailure(this.exception); | ||
|
||
@override | ||
List<Object?> get props => [exception]; | ||
} | ||
|
||
class PinEventsFailure extends Failure { | ||
final Object error; | ||
|
||
const PinEventsFailure(this.error); | ||
|
||
@override | ||
List<Object?> get props => [error]; | ||
} | ||
|
||
class UnpinEventsFailure extends Failure { | ||
final Object error; | ||
|
||
const UnpinEventsFailure(this.error); | ||
|
||
@override | ||
List<Object?> get props => [error]; | ||
} |
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,4 @@ | ||
enum PinnedMessagesActionEnum { | ||
pin, | ||
unpin, | ||
} |
39 changes: 39 additions & 0 deletions
39
lib/domain/usecase/room/update_pinned_messages_interactor.dart
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 @@ | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:fluffychat/app_state/failure.dart'; | ||
import 'package:fluffychat/app_state/success.dart'; | ||
import 'package:fluffychat/domain/app_state/room/update_pinned_events_state.dart'; | ||
import 'package:fluffychat/domain/enums/pinned_messages_action_enum.dart'; | ||
import 'package:matrix/matrix.dart'; | ||
|
||
class UpdatePinnedMessagesInteractor { | ||
Stream<Either<Failure, Success>> execute({ | ||
required Room room, | ||
required List<String> eventIds, | ||
PinnedMessagesActionEnum action = PinnedMessagesActionEnum.unpin, | ||
}) async* { | ||
try { | ||
yield Right(UpdatePinnedEventsInitial()); | ||
final currentPinnedEvents = room.pinnedEventIds.toSet(); | ||
if (action == PinnedMessagesActionEnum.pin) { | ||
currentPinnedEvents.addAll(eventIds); | ||
} else { | ||
currentPinnedEvents.removeAll(eventIds); | ||
} | ||
final result = await room.setPinnedEvents(currentPinnedEvents.toList()); | ||
yield Right(UpdatePinnedEventsSuccess(result)); | ||
} on MatrixException catch (exception) { | ||
Logs().e( | ||
'UpdatePinnedMessagesInteractor::execute(): ErrorCode ${exception.errcode}: ${exception.errorMessage}', | ||
); | ||
yield Left( | ||
UpdatePinnedEventsFailure(exception), | ||
); | ||
} catch (e) { | ||
if (action == PinnedMessagesActionEnum.pin) { | ||
yield Left(PinEventsFailure(e)); | ||
} else { | ||
yield Left(UnpinEventsFailure(e)); | ||
} | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.