Skip to content

Commit

Permalink
Merge pull request #4 from ecency/feature/report
Browse files Browse the repository at this point in the history
Report & Mute
  • Loading branch information
feruzm authored Jul 18, 2024
2 parents 75dca66 + b76cf20 commit 154bae0
Show file tree
Hide file tree
Showing 32 changed files with 1,044 additions and 434 deletions.
674 changes: 352 additions & 322 deletions android/app/src/main/assets/index.html

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions android/app/src/main/kotlin/com/ecency/waves/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ class MainActivity: FlutterActivity() {
"getImageUploadProofWithPostingKey('$id', '$username', '$postingKey');",
null
)
} else if (call.method == "muteUser" && username != null && author != null
&& postingKey != null && token != null && authKey != null ) {
webView?.evaluateJavascript(
"muteUser('$id','$username', '$author', '$postingKey', '$token', '$authKey');",
null
)
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions ios/Runner/AppBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@ class AppBridge: NSObject {
id: id,
jsCode: "voteContent('\(id)','\(username)', '\(author)', '\(permlink)', '\(weight)', '\(postingKey)', '\(token)', '\(authKey)');"
) { text in result(text) }
case "muteUser":
guard
let username = arguments ["username"] as? String,
let author = arguments ["author"] as? String,
let postingKey = arguments ["postingKey"] as? String,
let token = arguments ["token"] as? String,
let authKey = arguments ["authKey"] as? String
else {
debugPrint("username, author, postingKey, token, authKey - are note set")
return result(FlutterMethodNotImplemented)
}
webVC.runThisJS(
id: id,
jsCode: "muteUser('\(id)','\(username)', '\(author)', '\(postingKey)', '\(token)', '\(authKey)');"
) { text in result(text) }
case "getImageUploadProofWithPostingKey":
guard
let username = arguments ["username"] as? String,
Expand Down
31 changes: 31 additions & 0 deletions ios/Runner/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,37 @@
);
}

function muteUser(
id,
username,
author,
postingKey,
token,
authKey
) {
let op = [
"custom_json",
{
"id": "follow",
"required_auths": [],
"required_posting_auths": [
username
],
"json": JSON.stringify(["follow", { "follower": username, "following": author, "what": ["ignore"] }])
}

];
performOperations(
id,
[op],
"mute",
username,
postingKey,
token,
authKey
);
}

function performOperations(
id,
operations,
Expand Down
7 changes: 5 additions & 2 deletions lib/core/common/widgets/dialog/dialog_template.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DialogTemplate extends StatelessWidget {
final theme = Theme.of(context);
return AlertDialog(
contentPadding: EdgeInsets.zero,
backgroundColor: theme.primaryColorLight,
backgroundColor: theme.colorScheme.tertiary,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(12))),
title: Row(
Expand All @@ -45,7 +45,10 @@ class DialogTemplate extends StatelessWidget {
icon: const Icon(Icons.cancel))
],
),
content: content,
content: Padding(
padding: const EdgeInsets.only(left: 24, right: 15, bottom: 20),
child: content,
),
actions: [
if (declineButtonText != null)
DialogButton(
Expand Down
7 changes: 1 addition & 6 deletions lib/core/common/widgets/dialog/log_in_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ class LogInDialog extends StatelessWidget {
Widget build(BuildContext context) {
return DialogTemplate(
title: LocaleText.notLoggedIn,
content: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20,
).copyWith(bottom: 20),
child: Text(LocaleText.pleaseLoginFirst),
),
content: Text(LocaleText.pleaseLoginFirst),
declineButtonText: LocaleText.cancel,
proceedButtonText: LocaleText.login,
onProceedTap: () {
Expand Down
49 changes: 42 additions & 7 deletions lib/core/models/broadcast_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ class BroadcastModel<T> {
final T data;

const BroadcastModel({required this.type, required this.data});

Map<String, dynamic> toJson() {
return _toJson(data);
}

Map<String, dynamic> _toJson(T model) {
if (model is VoteBroadCastModel) {
return model.toJson();
} else if (model is CommentBroadCastModel) {
return model.toJson();
} else if (model is MuteBroadcastModel) {
return model.toJson();
} else {
throw Exception('Unknown type');
}
}
}

class VoteBroadCastModel {
Expand Down Expand Up @@ -53,16 +69,35 @@ class CommentBroadCastModel {
'title': "",
'body': comment,
'json_metadata': json.encode({
'tags': [
"hive-125125",
"waves",
"ecency",
"mobile",
"thread"
],
'tags': ["hive-125125", "waves", "ecency", "mobile", "thread"],
'app': "ecency-waves",
'format': "markdown+html",
}),
};
}
}

class MuteBroadcastModel {
final String username;
final String author;

const MuteBroadcastModel({
required this.username,
required this.author,
});

Map<String, dynamic> toJson() {
return {
"id": "follow",
"required_posting_auths": [username],
"json": json.encode([
"follow",
{
"follower": username,
"following": author,
"what": ["ignore"]
}
])
};
}
}
14 changes: 11 additions & 3 deletions lib/core/providers/global_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ class GlobalProviders {
ChangeNotifierProvider(
create: (context) => ThemeController(),
),
ChangeNotifierProvider(
ChangeNotifierProvider(
lazy: false,
create: (context) => UserController(),
),
ChangeNotifierProvider(
create: (context) => ThreadFeedController(),
ChangeNotifierProxyProvider<UserController, ThreadFeedController>(
create: (context) => ThreadFeedController(observer: null),
update: (context, userController, previousThreadFeedController) {
if (previousThreadFeedController == null) {
return ThreadFeedController(observer: userController.userName);
} else {
previousThreadFeedController.updateObserver(userController.userName);
return previousThreadFeedController;
}
},
)
];
}
61 changes: 52 additions & 9 deletions lib/core/services/data_service/api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ import 'package:waves/core/utilities/enum.dart';
import 'package:waves/features/threads/models/comment/image_upload_error_response.dart';
import 'package:waves/features/threads/models/comment/image_upload_response.dart';
import 'package:waves/features/threads/models/post_detail/comment_model.dart';
import 'package:waves/features/threads/models/thread_feeds/reported/report_reponse.dart';
import 'package:waves/features/threads/models/thread_feeds/thread_feed_model.dart';
import 'package:waves/features/user/models/follow_count_model.dart';
import 'package:waves/features/user/models/user_model.dart';

class ApiService {
Future<ActionListDataResponse<ThreadFeedModel>> getComments(
String accountName, String permlink) async {
String accountName, String permlink, String? observer) async {
try {
var url = Uri.parse(
'https://hivexplorer.com/api/get_discussion?author=$accountName&permlink=$permlink');
'https://hivexplorer.com/api/get_discussion?author=$accountName&permlink=$permlink&observer=$observer');

var response = await http.get(
url,
Expand Down Expand Up @@ -151,7 +152,8 @@ class ApiService {
String jsonString =
await validatePostingKeyFromPlatform(accountName, postingKey);
ActionSingleDataResponse<String> response =
ActionSingleDataResponse.fromJsonString(jsonString, null,ignoreFromJson: true);
ActionSingleDataResponse.fromJsonString(jsonString, null,
ignoreFromJson: true);
return response;
} catch (e) {
return ActionSingleDataResponse(
Expand Down Expand Up @@ -214,12 +216,7 @@ class ApiService {
};
final body = json.encode({
'operations': [
[
enumToString(args.type),
(args.data is VoteBroadCastModel
? (args.data as VoteBroadCastModel).toJson()
: (args.data as CommentBroadCastModel).toJson())
]
[enumToString(args.type), args.toJson()]
]
});

Expand Down Expand Up @@ -374,4 +371,50 @@ class ApiService {
status: ResponseStatus.failed, errorMessage: e.toString());
}
}

Future<ActionSingleDataResponse<String>> muteUser(
String username,
String author,
String? postingKey,
String? authKey,
String? token,
) async {
try {
String jsonString = await muteUserFromPlatform(
username, author, postingKey, authKey, token);
ActionSingleDataResponse<String> response =
ActionSingleDataResponse.fromJsonString(jsonString, null,
ignoreFromJson: true);
return response;
} catch (e) {
return ActionSingleDataResponse(
status: ResponseStatus.failed, errorMessage: e.toString());
}
}

Future<ActionSingleDataResponse<ReportResponse>> reportThread(
String author, String permlink) async {
try {
var url = Uri.parse("https://ecency.com/private-api/report");

http.Response response = await http.post(url,
body: json.encode({
"type": "content",
"data": "https://ecency.com/@$author/$permlink"
}));
if (response.statusCode == 200) {
return ActionSingleDataResponse<ReportResponse>(
data: ReportResponse.fromRawJson(response.body),
status: ResponseStatus.success,
isSuccess: true,
errorMessage: "");
} else {
return ActionSingleDataResponse(
status: ResponseStatus.failed, errorMessage: "Server Error");
}
} catch (e) {
return ActionSingleDataResponse(
status: ResponseStatus.failed, errorMessage: e.toString());
}
}
}
19 changes: 19 additions & 0 deletions lib/core/services/data_service/mobile_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,23 @@ Future<String> getImageUploadProofWithPostingKeyFromPlatform(
return response;
}

Future<String> muteUserFromPlatform(
String username,
String author,
String? postingKey,
String? authKey,
String? token,
) async {
final String id = 'muteUser${DateTime.now().toIso8601String()}';
final String response = await platform.invokeMethod('muteUser', {
'id': id,
'username': username,
'author': author,
'postingKey': postingKey ?? '',
'token': token ?? '',
'authKey': authKey ?? '',
});
return response;
}


10 changes: 10 additions & 0 deletions lib/core/services/data_service/service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ Future<String> getImageUploadProofWithPostingKeyFromPlatform(
return _error();
}

Future<String> muteUserFromPlatform(
String username,
String author,
String? postingKey,
String? authKey,
String? token,
){
return _error();
}

Future<String> _error() {
return Future.value('error');
}
Expand Down
10 changes: 10 additions & 0 deletions lib/core/services/data_service/web_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,13 @@ Future<String> getImageUploadProofWithPostingKeyFromPlatform(
) {
throw UnimplementedError();
}

Future<String> muteUserFromPlatform(
String username,
String author,
String? postingKey,
String? authKey,
String? token,
) {
throw UnimplementedError();
}
15 changes: 15 additions & 0 deletions lib/core/services/local_service.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'package:get_storage/get_storage.dart';
import 'package:waves/core/utilities/enum.dart';
import 'package:waves/features/threads/models/thread_feeds/reported/thread_info_model.dart';
import 'package:waves/features/threads/models/thread_feeds/thread_feed_model.dart';

class LocalService {
final GetStorage _getStorage;
final _defaultThreadKey = 'defaultThread';
final _reportedThreadKey = 'reportedThreads';

LocalService({required GetStorage getStorage}) : _getStorage = getStorage;

Expand All @@ -30,4 +32,17 @@ class LocalService {
if (data == null) return null;
return enumFromString(data, ThreadFeedType.values);
}

List<ThreadInfoModel> readReportedThreads() {
String? data = _getStorage.read(_reportedThreadKey);
if (data == null) return [];
return ThreadInfoModel.fromRawJsonList(data);
}

Future<void> writeReportedThreads(ThreadInfoModel item) async {
List<ThreadInfoModel> threads = readReportedThreads();
threads.add(item);
await _getStorage.write(
_reportedThreadKey, ThreadInfoModel.toRawJsonList(threads));
}
}
4 changes: 2 additions & 2 deletions lib/core/utilities/enum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ enum AuthType {hiveKeyChain, hiveAuth, postingKey, hiveSign}

enum TransactionState {loading,qr,redirection}

enum SignTransactionType {comment,vote}
enum SignTransactionType {comment,vote,mute}

enum BroadCastType {vote,comment}
enum BroadCastType {vote,comment,custom_json}

enum FollowType { followers, following }

Expand Down
Loading

0 comments on commit 154bae0

Please sign in to comment.