Skip to content

Commit

Permalink
Merge pull request #2173 from nextcloud/feat/neon_talk/reply
Browse files Browse the repository at this point in the history
  • Loading branch information
provokateurin committed Jun 21, 2024
2 parents c7b7d37 + 65361ee commit c3116aa
Show file tree
Hide file tree
Showing 20 changed files with 449 additions and 60 deletions.
2 changes: 2 additions & 0 deletions packages/neon/neon_talk/lib/l10n/en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"roomWriteMessage": "Write a message...",
"roomMessageAddEmoji": "Add emoji to message",
"roomMessageSend": "Send message",
"roomMessageReply": "Reply",
"roomMessageReaction": "Add reaction",
"reactionsAddNew": "Add a new reaction",
"reactionsLoading": "Loading reactions",
"roomsCreateNew": "Create new room"
Expand Down
12 changes: 12 additions & 0 deletions packages/neon/neon_talk/lib/l10n/localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ abstract class TalkLocalizations {
/// **'Send message'**
String get roomMessageSend;

/// No description provided for @roomMessageReply.
///
/// In en, this message translates to:
/// **'Reply'**
String get roomMessageReply;

/// No description provided for @roomMessageReaction.
///
/// In en, this message translates to:
/// **'Add reaction'**
String get roomMessageReaction;

/// No description provided for @reactionsAddNew.
///
/// In en, this message translates to:
Expand Down
6 changes: 6 additions & 0 deletions packages/neon/neon_talk/lib/l10n/localizations_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class TalkLocalizationsEn extends TalkLocalizations {
@override
String get roomMessageSend => 'Send message';

@override
String get roomMessageReply => 'Reply';

@override
String get roomMessageReaction => 'Add reaction';

@override
String get reactionsAddNew => 'Add a new reaction';

Expand Down
27 changes: 27 additions & 0 deletions packages/neon/neon_talk/lib/src/blocs/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ abstract class TalkRoomBloc implements InteractiveBloc {
/// Loads the emoji reactions for the [message].
void loadReactions(spreed.$ChatMessageInterface message);

/// Sets a [chatMessage] as the message to [replyTo].
void setReplyChatMessage(spreed.$ChatMessageInterface chatMessage);

/// Removes the current [replyTo] chat message.
void removeReplyChatMessage();

/// The current room data.
BehaviorSubject<Result<spreed.Room>> get room;

Expand All @@ -49,6 +55,9 @@ abstract class TalkRoomBloc implements InteractiveBloc {

/// Map of emoji reactions for the [messages].
BehaviorSubject<BuiltMap<int, BuiltMap<String, BuiltList<spreed.Reaction>>>> get reactions;

/// Current chat message to reply to.
BehaviorSubject<spreed.$ChatMessageInterface?> get replyTo;
}

class _TalkRoomBloc extends InteractiveBloc implements TalkRoomBloc {
Expand Down Expand Up @@ -164,6 +173,9 @@ class _TalkRoomBloc extends InteractiveBloc implements TalkRoomBloc {
@override
final reactions = BehaviorSubject.seeded(BuiltMap());

@override
final replyTo = BehaviorSubject.seeded(null);

@override
void dispose() {
pollLoop = false;
Expand All @@ -173,6 +185,7 @@ class _TalkRoomBloc extends InteractiveBloc implements TalkRoomBloc {
unawaited(messages.close());
unawaited(lastCommonRead.close());
unawaited(reactions.close());
unawaited(replyTo.close());
super.dispose();
}

Expand Down Expand Up @@ -214,10 +227,14 @@ class _TalkRoomBloc extends InteractiveBloc implements TalkRoomBloc {

@override
Future<void> sendMessage(String message) async {
final replyToId = replyTo.value?.id;
replyTo.add(null);

await wrapAction(
() async {
final response = await account.client.spreed.chat.sendMessage(
message: message,
replyTo: replyToId,
token: token,
);

Expand Down Expand Up @@ -294,6 +311,16 @@ class _TalkRoomBloc extends InteractiveBloc implements TalkRoomBloc {
);
}

@override
void setReplyChatMessage(spreed.$ChatMessageInterface chatMessage) {
replyTo.add(chatMessage);
}

@override
void removeReplyChatMessage() {
replyTo.add(null);
}

void updateLastCommonRead(String? header) {
if (header != null) {
final id = int.parse(header);
Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon_talk/lib/src/pages/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class _TalkRoomPageState extends State<TalkRoomPage> {
onRefresh: bloc.refresh,
sliver: SliverPadding(
padding: const EdgeInsets.symmetric(
horizontal: 20,
horizontal: 10,
),
sliver: sliver,
),
Expand Down
Loading

0 comments on commit c3116aa

Please sign in to comment.