Skip to content
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
11 changes: 7 additions & 4 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,14 @@
"ownerPanel": "Owner Panel",
"reportStatus_any": "All",
"reportStatus_appeal": "Appeal",
"reportStatus_approved": "Approved",
"reportStatus_closed": "Closed",
"reportStatus_pending": "Pending",
"reportStatus_rejected": "Rejected",
"report_accept": "Accept",
"report_reject": "Reject",
"reportStatus_deleted": "Deleted",
"reportStatus_restored": "Restored",
"reportedUser": "Reported user: ",
"reportedBy": "Reported by: ",
"reportDeleteMessage": "Delete the reported post.",
"reportRestoreMessage": "Resolve or restore the reported post.",
"copy": "Copy",
"copied": "Copied",
"share": "Share",
Expand Down 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
129 changes: 122 additions & 7 deletions lib/src/api/community_moderation.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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 }
Expand All @@ -24,6 +26,25 @@ 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');
}
Expand All @@ -32,6 +53,7 @@ class APICommunityModeration {
Future<CommunityReportModel> acceptReport(
int communityId,
int reportId,
int postId,
) async {
switch (client.software) {
case ServerSoftware.mbin:
Expand All @@ -41,6 +63,27 @@ class APICommunityModeration {

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

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

const path = '/post/report/resolve';

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

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

case ServerSoftware.piefed:
throw UnimplementedError('Not yet implemented');
}
Expand All @@ -49,6 +92,7 @@ class APICommunityModeration {
Future<CommunityReportModel> rejectReport(
int communityId,
int reportId,
int postId,
) async {
switch (client.software) {
case ServerSoftware.mbin:
Expand All @@ -58,6 +102,27 @@ class APICommunityModeration {

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

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

const path = '/post/report/resolve';

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

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 +173,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 +213,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 +321,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 +354,7 @@ class APICommunityModeration {
}
}

Future<DetailedCommunityModel> updateModerator(
Future<List<UserModel>> updateModerator(
int communityId,
int userId,
bool state,
Expand All @@ -265,10 +367,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
16 changes: 12 additions & 4 deletions lib/src/models/comment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ abstract class CommentModel with _$CommentModel {
required DateTime? editedAt,
required List<CommentModel>? children,
required int childCount,
required String visibility,
required PostVisibility visibility,
required bool? canAuthUserModerate,
required NotificationControlStatus? notificationControlStatus,
required List<String>? bookmarks,
Expand Down Expand Up @@ -164,7 +164,7 @@ abstract class CommentModel with _$CommentModel {
.map((c) => CommentModel.fromMbin(c as JsonMap))
.toList(),
childCount: json['childCount']! as int,
visibility: json['visibility']! as String,
visibility: PostVisibility.values.byName(json['visibility']! as String),
canAuthUserModerate: json['canAuthUserModerate'] as bool?,
notificationControlStatus: null,
bookmarks: optionalStringList(json['bookmarks']),
Expand Down Expand Up @@ -229,7 +229,11 @@ abstract class CommentModel with _$CommentModel {
editedAt: optionalDateTime(json['updated'] as String?),
children: children,
childCount: lemmyCounts?['child_count'] as int? ?? 0,
visibility: 'visible',
visibility: (lemmyComment['deleted']! as bool)
? PostVisibility.soft_deleted
: (lemmyComment['removed']! as bool)
? PostVisibility.trashed
: PostVisibility.visible,
canAuthUserModerate: null,
notificationControlStatus: null,
bookmarks: [
Expand Down Expand Up @@ -319,7 +323,11 @@ abstract class CommentModel with _$CommentModel {
editedAt: optionalDateTime(json['updated'] as String?),
children: children,
childCount: piefedCounts?['child_count'] as int? ?? 0,
visibility: 'visible',
visibility: (piefedComment['deleted']! as bool)
? PostVisibility.soft_deleted
: (piefedComment['removed']! as bool)
? PostVisibility.trashed
: PostVisibility.visible,
canAuthUserModerate: json['can_auth_user_moderate'] as bool?,
notificationControlStatus: json['activity_alert'] == null
? null
Expand Down
Loading
Loading