mirror of
https://github.com/haorendashu/nowser.git
synced 2025-12-18 18:14:21 +01:00
android content query add reject colum
This commit is contained in:
@@ -10,6 +10,7 @@ import 'package:nostr_sdk/signer/nostr_signer.dart';
|
||||
import 'package:nostr_sdk/utils/string_util.dart';
|
||||
import 'package:nostr_sdk/zap/private_zap.dart';
|
||||
import 'package:nowser/const/app_type.dart';
|
||||
import 'package:nowser/const/reject_type.dart';
|
||||
import 'package:nowser/provider/permission_check_mixin.dart';
|
||||
|
||||
import '../const/auth_result.dart';
|
||||
@@ -148,13 +149,14 @@ class AndroidSignerContentResolverProvider extends AndroidContentProvider
|
||||
|
||||
App? app;
|
||||
NostrSigner? signer;
|
||||
var complete = Completer();
|
||||
var complete = Completer<int?>();
|
||||
|
||||
rejectFunc(_app) {
|
||||
rejectFunc(_app, rejectType) {
|
||||
if (_app != null) {
|
||||
saveAuthLog(_app, authType, eventKind, authDetail, AuthResult.REJECT);
|
||||
}
|
||||
complete.complete();
|
||||
|
||||
complete.complete(rejectType);
|
||||
}
|
||||
|
||||
confirmFunc(_app, _signer) {
|
||||
@@ -166,8 +168,17 @@ class AndroidSignerContentResolverProvider extends AndroidContentProvider
|
||||
checkPermission(null, appType, code!, authType, rejectFunc, confirmFunc,
|
||||
eventKind: eventKind, authDetail: authDetail);
|
||||
|
||||
await complete.future;
|
||||
var rejectType = await complete.future;
|
||||
if (signer == null || app == null) {
|
||||
if (rejectType == AuthResult.REJECT) {
|
||||
// if there is a rejected colum, the app will not open the signer app.
|
||||
data = MatrixCursorData(
|
||||
columnNames: ["rejected"], notificationUris: [uri]);
|
||||
data.addRow(["Could not decrypt the message"]);
|
||||
return data;
|
||||
}
|
||||
|
||||
/// The app will open the signer with to ask sign request again.
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ mixin AndroidSignerMixin on PermissionCheckMixin {
|
||||
}
|
||||
|
||||
checkPermission(context, AppType.ANDROID_APP, code!, authType,
|
||||
eventKind: eventKind, authDetail: playload, (app) {
|
||||
eventKind: eventKind, authDetail: playload, (app, rejectType) {
|
||||
// this place should do some about reject
|
||||
if (app != null) {
|
||||
saveAuthLog(
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:nowser/component/auth_dialog/auth_app_connect_dialog.dart';
|
||||
import 'package:nowser/component/auth_dialog/auth_dialog.dart';
|
||||
import 'package:nowser/component/user/user_login_dialog.dart';
|
||||
import 'package:nowser/const/auth_result.dart';
|
||||
import 'package:nowser/const/reject_type.dart';
|
||||
import 'package:nowser/data/auth_log.dart';
|
||||
import 'package:nowser/data/auth_log_db.dart';
|
||||
import 'package:nowser/main.dart';
|
||||
@@ -12,9 +13,15 @@ import '../const/connect_type.dart';
|
||||
import '../data/app.dart';
|
||||
|
||||
mixin PermissionCheckMixin {
|
||||
Future<void> checkPermission(BuildContext? context, int appType, String code,
|
||||
int authType, Function(App?) reject, Function(App, NostrSigner) confirm,
|
||||
{int? eventKind, String? authDetail}) async {
|
||||
Future<void> checkPermission(
|
||||
BuildContext? context,
|
||||
int appType,
|
||||
String code,
|
||||
int authType,
|
||||
Function(App?, int rejectType) reject,
|
||||
Function(App, NostrSigner) confirm,
|
||||
{int? eventKind,
|
||||
String? authDetail}) async {
|
||||
if (keyProvider.keys.isEmpty) {
|
||||
// should add a key first
|
||||
if (context != null) {
|
||||
@@ -38,14 +45,14 @@ mixin PermissionCheckMixin {
|
||||
|
||||
if (app == null) {
|
||||
// not allow connect
|
||||
reject(null);
|
||||
reject(null, RejectType.OTHERS);
|
||||
return;
|
||||
}
|
||||
|
||||
var signer = await getSigner(app.pubkey!);
|
||||
if (signer == null) {
|
||||
saveAuthLog(app, authType, eventKind, authDetail, AuthResult.REJECT);
|
||||
reject(app);
|
||||
reject(app, RejectType.OTHERS);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -55,7 +62,7 @@ mixin PermissionCheckMixin {
|
||||
saveAuthLog(app, authType, eventKind, authDetail, AuthResult.OK);
|
||||
} catch (e) {
|
||||
print("confirm error $e");
|
||||
reject(app);
|
||||
reject(app, RejectType.OTHERS);
|
||||
saveAuthLog(app, authType, eventKind, authDetail, AuthResult.REJECT);
|
||||
}
|
||||
return;
|
||||
@@ -69,13 +76,13 @@ mixin PermissionCheckMixin {
|
||||
saveAuthLog(app, authType, eventKind, authDetail, AuthResult.OK);
|
||||
} catch (e) {
|
||||
print("confirm error $e");
|
||||
reject(app);
|
||||
reject(app, RejectType.OTHERS);
|
||||
saveAuthLog(app, authType, eventKind, authDetail, AuthResult.REJECT);
|
||||
}
|
||||
return;
|
||||
} else if (permissionCheckResult == AuthResult.REJECT) {
|
||||
saveAuthLog(app, authType, eventKind, authDetail, AuthResult.REJECT);
|
||||
reject(app);
|
||||
reject(app, RejectType.REJECT);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -88,17 +95,19 @@ mixin PermissionCheckMixin {
|
||||
saveAuthLog(app, authType, eventKind, authDetail, AuthResult.OK);
|
||||
} catch (e) {
|
||||
print("confirm error $e");
|
||||
reject(app);
|
||||
reject(app, RejectType.OTHERS);
|
||||
saveAuthLog(
|
||||
app, authType, eventKind, authDetail, AuthResult.REJECT);
|
||||
}
|
||||
return;
|
||||
} else if (authResult == AuthResult.REJECT) {
|
||||
// return reject here ?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
saveAuthLog(app, authType, eventKind, authDetail, AuthResult.REJECT);
|
||||
reject(app);
|
||||
reject(app, RejectType.OTHERS);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -231,7 +231,7 @@ class RemoteSigningProvider extends ChangeNotifier with PermissionCheckMixin {
|
||||
}
|
||||
|
||||
checkPermission(context!, appType, code, authType,
|
||||
eventKind: eventKind, authDetail: authDetail, (app) {
|
||||
eventKind: eventKind, authDetail: authDetail, (app, rejectType) {
|
||||
response = NostrRemoteResponse(request.id, "", error: "forbid");
|
||||
sendResponse(
|
||||
relays, response, signerSigner, localPubkey, remoteSignerPubkey);
|
||||
|
||||
Reference in New Issue
Block a user