Skip to content

Commit

Permalink
fix(nextcloud)!: Move all query parameters to body to fix many serial…
Browse files Browse the repository at this point in the history
…ization problems

Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Jul 4, 2024
1 parent 5c85655 commit d2787bf
Show file tree
Hide file tree
Showing 132 changed files with 48,844 additions and 12,144 deletions.
3 changes: 3 additions & 0 deletions .cspell/nextcloud.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ displayname
etag
federatedfilesharing
fediverse
groupid
heavyrain
heavyrainshowers
iscustomavatar
Expand All @@ -40,6 +41,7 @@ productname
rainshowers
replyable
requesttoken
reshares
resharing
rgdnvw
roomid
Expand All @@ -54,6 +56,7 @@ stime
stunservers
stylesheet
subadmin
subfiles
subline
systemtags
totalitems
Expand Down
14 changes: 10 additions & 4 deletions packages/neon/neon_dashboard/lib/src/blocs/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ class _DashboardBloc extends InteractiveBloc implements DashboardBloc {
cacheKey: 'dashboard-widgets-v1',
subject: itemsV1,
getRequest: () => account.client.dashboard.dashboardApi.$getWidgetItems_Request(
widgets: v1WidgetIDs.build(),
limit: maxItems,
$body: dashboard.DashboardApiGetWidgetItemsRequestApplicationJson(
(b) => b
..widgets.replace(v1WidgetIDs.build())
..limit = maxItems,
),
),
serializer: account.client.dashboard.dashboardApi.$getWidgetItems_Serializer(),
unwrap: (response) => response.body.ocs.data,
Expand All @@ -114,8 +117,11 @@ class _DashboardBloc extends InteractiveBloc implements DashboardBloc {
cacheKey: 'dashboard-widgets-v2',
subject: itemsV2,
getRequest: () => account.client.dashboard.dashboardApi.$getWidgetItemsV2_Request(
widgets: v2WidgetIDs.build(),
limit: maxItems,
$body: dashboard.DashboardApiGetWidgetItemsV2RequestApplicationJson(
(b) => b
..widgets.replace(v2WidgetIDs.build())
..limit = maxItems,
),
),
serializer: account.client.dashboard.dashboardApi.$getWidgetItemsV2_Serializer(),
unwrap: (response) => response.body.ocs.data,
Expand Down
116 changes: 62 additions & 54 deletions packages/neon/neon_dashboard/test/bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:neon_framework/testing.dart';

Account mockDashboardAccount() => mockServer({
RegExp(r'/ocs/v2\.php/apps/dashboard/api/v1/widgets'): {
'get': (match, queryParameters) => Response(
'get': (match, bodyBytes) => Response(
json.encode({
'ocs': {
'meta': {'status': '', 'statuscode': 0},
Expand Down Expand Up @@ -38,13 +38,55 @@ Account mockDashboardAccount() => mockServer({
),
},
RegExp(r'/ocs/v2\.php/apps/dashboard/api/v1/widget-items'): {
'get': (match, queryParameters) => Response(
json.encode({
'ocs': {
'meta': {'status': '', 'statuscode': 0},
'data': {
for (final key in queryParameters['widgets[]']!)
key: [
'get': (match, bodyBytes) {
final data = json.decode(utf8.decode(bodyBytes)) as Map<String, dynamic>;

return Response(
json.encode({
'ocs': {
'meta': {'status': '', 'statuscode': 0},
'data': {
for (final key in (data['widgets'] as List).cast<String>())
key: [
{
'subtitle': '',
'title': key,
'link': '',
'iconUrl': '',
'overlayIconUrl': '',
'sinceId': '',
},
],
'tooMany1': [
for (var i = 0; i < 8; i++)
{
'subtitle': '',
'title': '$i',
'link': '',
'iconUrl': '',
'overlayIconUrl': '',
'sinceId': '',
},
],
},
},
}),
200,
);
},
},
RegExp(r'/ocs/v2\.php/apps/dashboard/api/v2/widget-items'): {
'get': (match, bodyBytes) {
final data = json.decode(utf8.decode(bodyBytes)) as Map<String, dynamic>;

return Response(
json.encode({
'ocs': {
'meta': {'status': '', 'statuscode': 0},
'data': {
for (final key in (data['widgets'] as List).cast<String>())
key: {
'items': [
{
'subtitle': '',
'title': key,
Expand All @@ -54,7 +96,11 @@ Account mockDashboardAccount() => mockServer({
'sinceId': '',
},
],
'tooMany1': [
'emptyContentMessage': '',
'halfEmptyContentMessage': '',
},
'tooMany2': {
'items': [
for (var i = 0; i < 8; i++)
{
'subtitle': '',
Expand All @@ -65,53 +111,15 @@ Account mockDashboardAccount() => mockServer({
'sinceId': '',
},
],
'emptyContentMessage': '',
'halfEmptyContentMessage': '',
},
},
}),
200,
),
},
RegExp(r'/ocs/v2\.php/apps/dashboard/api/v2/widget-items'): {
'get': (match, queryParameters) => Response(
json.encode({
'ocs': {
'meta': {'status': '', 'statuscode': 0},
'data': {
for (final key in queryParameters['widgets[]']!)
key: {
'items': [
{
'subtitle': '',
'title': key,
'link': '',
'iconUrl': '',
'overlayIconUrl': '',
'sinceId': '',
},
],
'emptyContentMessage': '',
'halfEmptyContentMessage': '',
},
'tooMany2': {
'items': [
for (var i = 0; i < 8; i++)
{
'subtitle': '',
'title': '$i',
'link': '',
'iconUrl': '',
'overlayIconUrl': '',
'sinceId': '',
},
],
'emptyContentMessage': '',
'halfEmptyContentMessage': '',
},
},
},
}),
200,
),
},
}),
200,
);
},
},
});

Expand Down
9 changes: 6 additions & 3 deletions packages/neon/neon_files/lib/src/widgets/file_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,12 @@ class FilePreviewImage extends NeonApiImage {
required super.account,
}) : super(
getRequest: (client) => client.core.preview.$getPreview_Request(
file: file.uri.path,
x: width,
y: height,
$body: PreviewGetPreviewRequestApplicationJson(
(b) => b
..file = file.uri.path
..x = width
..y = height,
),
),
etag: file.etag,
expires: null,
Expand Down
6 changes: 3 additions & 3 deletions packages/neon/neon_notifications/test/bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Account mockNotificationsAccount() {

return mockServer({
RegExp(r'/ocs/v2\.php/apps/notifications/api/v2/notifications/([0-9]+)'): {
'delete': (match, queryParameters) {
'delete': (match, bodyBytes) {
final id = int.parse(match.group(1)!);
notifications.removeWhere((n) => n['notification_id'] == id);

Expand All @@ -42,7 +42,7 @@ Account mockNotificationsAccount() {
},
},
RegExp(r'/ocs/v2\.php/apps/notifications/api/v2/notifications'): {
'get': (match, queryParameters) => Response(
'get': (match, bodyBytes) => Response(
json.encode({
'ocs': {
'meta': {'status': '', 'statuscode': 0},
Expand All @@ -51,7 +51,7 @@ Account mockNotificationsAccount() {
}),
200,
),
'delete': (match, queryParameters) {
'delete': (match, bodyBytes) {
notifications.clear();

return Response(
Expand Down
38 changes: 27 additions & 11 deletions packages/neon/neon_talk/lib/src/blocs/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,14 @@ class _TalkRoomBloc extends InteractiveBloc implements TalkRoomBloc {

try {
final response = await account.client.spreed.chat.receiveMessages(
lookIntoFuture: spreed.ChatReceiveMessagesLookIntoFuture.$1,
token: token,
includeLastKnown: spreed.ChatReceiveMessagesIncludeLastKnown.$0,
lastKnownMessageId: lastKnownMessageId,
limit: 100,
$body: spreed.ChatReceiveMessagesRequestApplicationJson(
(b) => b
..lookIntoFuture = spreed.ChatReceiveMessagesRequestApplicationJson_LookIntoFuture.$1
..includeLastKnown = spreed.ChatReceiveMessagesRequestApplicationJson_IncludeLastKnown.$0
..lastKnownMessageId = lastKnownMessageId
..limit = 100,
),
);

updateLastCommonRead(response.headers.xChatLastCommonRead);
Expand Down Expand Up @@ -208,9 +211,12 @@ class _TalkRoomBloc extends InteractiveBloc implements TalkRoomBloc {
subject: messages,
getRequest: () => account.client.spreed.chat.$receiveMessages_Request(
token: token,
lookIntoFuture: spreed.ChatReceiveMessagesLookIntoFuture.$0,
includeLastKnown: spreed.ChatReceiveMessagesIncludeLastKnown.$0,
limit: 100,
$body: spreed.ChatReceiveMessagesRequestApplicationJson(
(b) => b
..lookIntoFuture = spreed.ChatReceiveMessagesRequestApplicationJson_LookIntoFuture.$0
..includeLastKnown = spreed.ChatReceiveMessagesRequestApplicationJson_IncludeLastKnown.$0
..limit = 100,
),
),
serializer: account.client.spreed.chat.$receiveMessages_Serializer(),
unwrap: (response) {
Expand All @@ -233,9 +239,15 @@ class _TalkRoomBloc extends InteractiveBloc implements TalkRoomBloc {
await wrapAction(
() async {
final response = await account.client.spreed.chat.sendMessage(
message: message,
replyTo: replyToId,
token: token,
$body: spreed.ChatSendMessageRequestApplicationJson(
(b) {
b.message = message;
if (replyToId != null) {
b.replyTo = replyToId;
}
},
),
);

updateLastCommonRead(response.headers.xChatLastCommonRead);
Expand All @@ -256,9 +268,11 @@ class _TalkRoomBloc extends InteractiveBloc implements TalkRoomBloc {
await wrapAction(
() async {
final response = await account.client.spreed.reaction.react(
reaction: reaction,
token: token,
messageId: message.id,
$body: spreed.ReactionReactRequestApplicationJson(
(b) => b..reaction = reaction,
),
);

updateReactions(
Expand All @@ -275,9 +289,11 @@ class _TalkRoomBloc extends InteractiveBloc implements TalkRoomBloc {
await wrapAction(
() async {
final response = await account.client.spreed.reaction.delete(
reaction: reaction,
token: token,
messageId: message.id,
$body: spreed.ReactionDeleteRequestApplicationJson(
(b) => b..reaction = reaction,
),
);

updateReactions(
Expand Down
15 changes: 11 additions & 4 deletions packages/neon/neon_talk/lib/src/blocs/talk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,17 @@ class _TalkBloc extends InteractiveBloc implements TalkBloc {
) async {
await wrapAction(() async {
await account.client.spreed.room.createRoom(
roomType: type.value,
roomName: roomName,
invite: invite?.id,
source: invite?.source,
$body: spreed.RoomCreateRoomRequestApplicationJson(
(b) {
b
..roomType = type.value
..invite = invite?.id
..source = invite?.source;
if (roomName != null) {
b.roomName = roomName;
}
},
),
);
});
}
Expand Down
11 changes: 7 additions & 4 deletions packages/neon/neon_talk/lib/src/widgets/message_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class _TalkMessageInputState extends State<TalkMessageInput> {
return [];
}

String? matchingPart = controller.text.substring(0, cursor);
var matchingPart = controller.text.substring(0, cursor);
final index = matchingPart.lastIndexOf(' ') + 1;
matchingPart = matchingPart.substring(index);
if (!matchingPart.startsWith('@') || matchingPart.isEmpty) {
Expand All @@ -159,15 +159,18 @@ class _TalkMessageInputState extends State<TalkMessageInput> {

final account = NeonProvider.of<Account>(context);
final response = await account.client.spreed.chat.mentions(
search: matchingPart.substring(1),
token: bloc.room.value.requireData.token,
limit: 5,
$body: spreed.ChatMentionsRequestApplicationJson(
(b) => b
..search = matchingPart.substring(1)
..limit = 5,
),
);

return response.body.ocs.data
.map(
(mention) => _Suggestion(
start: cursor - matchingPart!.length,
start: cursor - matchingPart.length,
end: cursor,
mention: mention,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ class TalkRichObjectFilePreview extends StatelessWidget {
etag: parameter.etag,
expires: null,
getRequest: (client) => client.core.preview.$getPreviewByFileId_Request(
fileId: int.parse(parameter.id),
x: deviceSize.width.toInt(),
y: deviceSize.height.toInt(),
$body: PreviewGetPreviewByFileIdRequestApplicationJson(
(b) => b
..fileId = int.parse(parameter.id)
..x = deviceSize.width.toInt()
..y = deviceSize.height.toInt(),
),
),
);
}
Expand Down
Loading

0 comments on commit d2787bf

Please sign in to comment.