Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@
}
},
"edit": "Edit",
"restore": "Restore",
"delete": "Delete",
"deleteX": "Delete {name}",
"@deleteX": {
Expand Down Expand Up @@ -494,6 +495,8 @@
"reason": "Reason",
"moderate": "Moderate",
"submit": "Submit",
"resolve": "Resolve",
"unresolve": "Unresolve",
"alternativeSources": "Alternative Sources",
"markdownEditor_heading": "Heading",
"markdownEditor_bold": "Bold",
Expand Down
8 changes: 2 additions & 6 deletions lib/src/api/community.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,7 @@ class APICommunity {

final response = await client.get(path, queryParams: query);

return DetailedCommunityModel.fromLemmy(
response.bodyJson['community_view']! as JsonMap,
);
return DetailedCommunityModel.fromLemmy(response.bodyJson);

case ServerSoftware.piefed:
const path = '/community';
Expand All @@ -262,9 +260,7 @@ class APICommunity {

final response = await client.get(path, queryParams: query);

return DetailedCommunityModel.fromLemmy(
response.bodyJson['community_view']! as JsonMap,
);
return DetailedCommunityModel.fromLemmy(response.bodyJson);

case ServerSoftware.piefed:
const path = '/community';
Expand Down
118 changes: 110 additions & 8 deletions lib/src/api/community_moderation.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'package:interstellar/src/api/client.dart';
import 'package:interstellar/src/controller/server.dart';
import 'package:interstellar/src/models/community.dart';
import 'package:interstellar/src/models/user.dart';
import 'package:interstellar/src/utils/models.dart';
import 'package:interstellar/src/utils/utils.dart';

enum ReportStatus { any, approved, pending, rejected }
enum ReportStatus { any, approved, pending, rejected, resolved }

class APICommunityModeration {
APICommunityModeration(this.client);
Expand All @@ -24,6 +26,56 @@ class APICommunityModeration {

return CommunityReportListModel.fromMbin(response.bodyJson);
case ServerSoftware.lemmy:
const path = '/post/report/list';
final query = {
'page': page,
'community_id': communityId.toString(),
'unresolved_only': (status == ReportStatus.pending).toString(),
};

final response = await client.get(path, queryParams: query);

final json = response.bodyJson;
json['next_page'] = lemmyCalcNextIntPage(
json['post_reports']! as List<dynamic>,
page,
);

return CommunityReportListModel.fromLemmy(
json,
langCodeIdPairs: await client.languageCodeIdPairs(),
);
case ServerSoftware.piefed:
throw UnimplementedError('Not yet implemented');
}
}

Future<CommunityReportModel> resolve(
int communityId,
int reportId,
bool state,
) async {
switch (client.software) {
case ServerSoftware.mbin:
final path =
'/moderate/magazine/$communityId/reports/$reportId/${state ? 'reject' : 'accept'}';

final response = await client.post(path);

return CommunityReportModel.fromMbin(response.bodyJson);
case ServerSoftware.lemmy:
const path = '/post/report/resolve';

final response = await client.put(
path,
body: {'report_id': reportId, 'resolved': state},
);

return CommunityReportModel.fromLemmy(
response.bodyJson['post_report_view']! as JsonMap,
langCodeIdPairs: await client.languageCodeIdPairs(),
);

case ServerSoftware.piefed:
throw UnimplementedError('Not yet implemented');
}
Expand Down Expand Up @@ -108,15 +160,28 @@ class APICommunityModeration {
return CommunityBanModel.fromMbin(response.bodyJson);

case ServerSoftware.lemmy:
throw Exception('Ban update not implemented on Lemmy yet');
const path = '/community/ban_user';

final response = await client.post(
path,
body: {
'community_id': communityId,
'person_id': userId,
'ban': true,
'reason': reason,
'expires_at': ?expiredAt?.microsecondsSinceEpoch,
},
);

return CommunityBanModel.fromLemmy(response.bodyJson);

case ServerSoftware.piefed:
const path = '/community/moderate/ban';
final body = {
'community_id': communityId,
'user_id': userId,
'reason': reason,
if (expiredAt != null) 'expires_at': expiredAt.toIso8601String(),
'expires_at': ?expiredAt?.toIso8601String(),
};

final response = await client.post(path, body: body);
Expand All @@ -135,7 +200,18 @@ class APICommunityModeration {
return CommunityBanModel.fromMbin(response.bodyJson);

case ServerSoftware.lemmy:
throw Exception('Ban update not implemented on Lemmy yet');
const path = '/community/ban_user';

final response = await client.post(
path,
body: {
'community_id': communityId,
'person_id': userId,
'ban': false,
},
);

return CommunityBanModel.fromLemmy(response.bodyJson);

case ServerSoftware.piefed:
const path = '/community/moderate/unban';
Expand Down Expand Up @@ -232,7 +308,20 @@ class APICommunityModeration {
return DetailedCommunityModel.fromMbin(response.bodyJson);

case ServerSoftware.lemmy:
throw Exception('Community edit not implemented on Lemmy yet');
const path = '/community';

final response = await client.put(
path,
body: {
'community_id': communityId,
'title': title,
'description': description,
'nsfw': isAdult,
'posting_restricted_to_mods': isPostingRestrictedToMods,
},
);

return DetailedCommunityModel.fromLemmy(response.bodyJson);

case ServerSoftware.piefed:
const path = '/community';
Expand All @@ -252,7 +341,7 @@ class APICommunityModeration {
}
}

Future<DetailedCommunityModel> updateModerator(
Future<List<UserModel>> updateModerator(
int communityId,
int userId,
bool state,
Expand All @@ -265,10 +354,23 @@ class APICommunityModeration {
? await client.post(path)
: await client.delete(path);

return DetailedCommunityModel.fromMbin(response.bodyJson);
return DetailedCommunityModel.fromMbin(response.bodyJson).moderators;

case ServerSoftware.lemmy:
throw Exception('Moderator update not implemented on Lemmy yet');
const path = '/community/mod';

final response = await client.post(
path,
body: {
'community_id': communityId,
'person_id': userId,
'added': state,
},
);

return (response.bodyJson['moderators']! as List<dynamic>)
.map((moderator) => UserModel.fromLemmy(moderator['moderator']))
.toList();

case ServerSoftware.piefed:
throw UnimplementedError();
Expand Down
44 changes: 41 additions & 3 deletions lib/src/api/moderation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,21 @@ class APIModeration {
};

case ServerSoftware.lemmy:
throw Exception('Moderation not implemented on Lemmy yet');
const path = '/post/feature';

final response = await client.post(
path,
body: {
'post_id': postId,
'featured': pinned,
'feature_type': 'Community',
},
);

return PostModel.fromLemmy(
response.bodyJson,
langCodeIdPairs: await client.languageCodeIdPairs(),
);

case ServerSoftware.piefed:
const path = '/post/feature';
Expand Down Expand Up @@ -188,7 +202,17 @@ class APIModeration {
};

case ServerSoftware.lemmy:
throw Exception('Moderation not implemented on Lemmy yet');
const path = '/post/remove';

final response = await client.post(
path,
body: {'post_id': postId, 'removed': status, 'reason': 'Moderated'},
);

return PostModel.fromLemmy(
response.bodyJson,
langCodeIdPairs: await client.languageCodeIdPairs(),
);

case ServerSoftware.piefed:
const path = '/post/remove';
Expand Down Expand Up @@ -287,7 +311,21 @@ class APIModeration {
return CommentModel.fromMbin(response.bodyJson);

case ServerSoftware.lemmy:
throw Exception('Moderation not implemented on Lemmy yet');
const path = '/comment/remove';

final response = await client.post(
path,
body: {
'comment_id': commentId,
'removed': status,
'reason': 'Moderated',
},
);

return CommentModel.fromLemmy(
response.bodyJson['comment_view']! as JsonMap,
langCodeIdPairs: await client.languageCodeIdPairs(),
);

case ServerSoftware.piefed:
const path = '/comment/remove';
Expand Down
Loading
Loading