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

fix(neon_talk): Update parent messages #2189

Merged
merged 3 commits into from
Jul 9, 2024
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
5 changes: 5 additions & 0 deletions packages/neon/neon_talk/lib/src/blocs/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,15 @@ class _TalkRoomBloc extends InteractiveBloc implements TalkRoomBloc {
// If there are multiple messages updating the same parent message only the newest is applied because it already contains all values
for (final newHiddenMessage in newHiddenMessages) {
final parent = newHiddenMessage.parent!;

if (message.id == parent.id) {
// Conversion from ChatMessage to ChatMessageWithParent is necessary because parent messages can't have parents of their own
return spreed.ChatMessageWithParent.fromJson(parent.toJson());
}

if (message.parent?.id == parent.id) {
return message.rebuild((b) => b.parent.replace(parent));
}
}

return message;
Expand Down
39 changes: 36 additions & 3 deletions packages/neon/neon_talk/test/room_bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ Account mockTalkAccount() {
},
}),
200,
headers: {
'content-type': 'application/json',
},
);
},
},
Expand Down Expand Up @@ -115,7 +118,17 @@ Account mockTalkAccount() {
json.encode({
'ocs': {
'meta': {'status': '', 'statuscode': 0},
'data': List.generate(messageCount, (i) => getChatMessage(id: messageCount - i - 1)),
'data': List.generate(
messageCount,
(i) => getChatMessage(
id: messageCount - i - 1,
parent: messageCount - i - 2 >= 0
? getChatMessage(
id: messageCount - i - 2,
)
: null,
),
),
},
}),
200,
Expand Down Expand Up @@ -357,8 +370,8 @@ void main() {
roomBloc.messages.transformResult((e) => BuiltList<int?>(e.map((m) => m.parent?.id))),
emitsInOrder([
Result<BuiltList<int?>>.loading(),
Result.success(BuiltList<int?>([null, null, null])),
Result.success(BuiltList<int?>([message.id, null, null, null])),
Result.success(BuiltList<int?>([1, 0, null])),
Result.success(BuiltList<int?>([1, 1, 0, null])),
]),
);

Expand Down Expand Up @@ -590,6 +603,26 @@ void main() {
),
]),
);
expect(
roomBloc.messages.transformResult((e) => BuiltList<spreed.MessageType?>(e.map((m) => m.parent?.messageType))),
emitsInOrder([
Result<BuiltList<spreed.MessageType?>>.loading(),
Result.success(
BuiltList<spreed.MessageType?>([
spreed.MessageType.comment,
spreed.MessageType.comment,
null,
]),
),
Result.success(
BuiltList<spreed.MessageType?>([
spreed.MessageType.commentDeleted,
null,
null,
]),
),
]),
);

final message = MockChatMessage();
when(() => message.id).thenReturn(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
POST http://localhost/ocs/v2\.php/apps/spreed/api/v4/room\?roomType=3&invite=&roomName=Test&source=&objectType=&objectId=
POST http://localhost/ocs/v2\.php/apps/spreed/api/v4/room
accept: application/json
authorization: Bearer mock
content-type: application/json; charset=utf-8
ocs-apirequest: true
POST http://localhost/ocs/v2\.php/apps/spreed/api/v1/chat/[a-z0-9]{8}\?message=bla&actorDisplayName=&referenceId=&replyTo=0&silent=0
\{"roomType":3,"invite":"","roomName":"Test","source":"","objectType":"","objectId":""\}
POST http://localhost/ocs/v2\.php/apps/spreed/api/v1/chat/[a-z0-9]{8}
accept: application/json
authorization: Bearer mock
content-type: application/json; charset=utf-8
ocs-apirequest: true
\{"message":"bla","actorDisplayName":"","referenceId":"","replyTo":0,"silent":false\}
DELETE http://localhost/ocs/v2\.php/apps/spreed/api/v1/chat/[a-z0-9]{8}/[0-9]+
accept: application/json
authorization: Bearer mock
Expand Down
4 changes: 3 additions & 1 deletion packages/nextcloud/test/spreed_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,9 @@ void main() {

final messageResponse = await client1.spreed.chat.sendMessage(
token: room.token,
message: 'bla',
$body: spreed.ChatSendMessageRequestApplicationJson(
(b) => b..message = 'bla',
),
);

final response = await client1.spreed.chat.deleteMessage(
Expand Down