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
18 changes: 18 additions & 0 deletions docs/plugin-sdk/API_REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ if (response.success) {
| `feedback.sendEmail` | 0.9.89 |
| `feedback.report` | 0.9.97 |
| `feedback.submitBookCorrection` | 0.9.98.1 |
| `feedback.getBookCorrectionStatus` | 0.9.99 |
| `feedback.hasReporterEmail` | 0.9.97 |
| `history.list` | 0.9.89 |
| `history.listSearches` | 0.9.89 |
Expand Down Expand Up @@ -4597,6 +4598,23 @@ const result = await Otzaria.call('feedback.submitBookCorrection', {
- **אישור כתובת השולח:** בקריאה הראשונה בכל מופע של התוסף אוצריא מציגה למשתמש חלון עם שם התוסף וכתובת החזרה השמורה, וניתן לערוך בו את הכתובת. האישור תקף כל עוד התוסף פתוח וכתובת החזרה נשארת אותה כתובת, כך שתיקון שמפוצל לחלקים אינו מקפיץ חלון לכל חלק. ביטול מחזיר `error.report_email_required` ושום דיווח אינו נשלח.
- `error.report_id_conflict` מציין התנגשות בתור המקומי או HTTP 409: יש ליצור `reportId` חדש לפני ניסיון נוסף. כשל זמני משתמש באותו מזהה ובאותו תוכן.

### `feedback.getBookCorrectionStatus`
**הרשאה:** `feedback.send_email` (כמו `feedback.submitBookCorrection`). קריאה בלבד.

דיווח שהוחזר עבורו `status: 'queued'` נשלח בהמשך על ידי התור של אוצריא, בלי שהתוסף מקבל על כך הודעה. כדי לעדכן את המצב שמציג התוסף:

```js
const response = await Otzaria.call('feedback.getBookCorrectionStatus', { reportId });
if (response.success && response.data) {
const { status } = response.data;
}
```

- פרמטר: `reportId` — אותו מזהה שהועבר ל־`feedback.submitBookCorrection` (אותם תווים ואותה מגבלת אורך). תוסף יכול לשאול רק על דיווחים שהוא עצמו שלח, ושום תוכן אינו נחשף.
- `response.data`: `{status: 'queued'|'sent'|'rejected'|'unknown', reportId, nativeReportId}`. `queued` — עדיין בתור המקומי; `sent` — רשום כנשלח, גם אם ניסיון חוזר עדיין בתור; `rejected` — נדחה סופית על ידי השרת.
- `unknown` אינו סופי: הדיווח לא נמצא (נמחק, נחתך מהיסטוריית הנשלחים — נשמרים 100 אחרונים — שוחזר מגיבוי, הוחלף מזהה אחרי התנגשות, או שנתפס ברגע ההעברה מהתור להיסטוריה). יש להשאיר את המצב הקודם ולנסות שוב מאוחר יותר.
- שגיאה `error.invalid_params` על `reportId` לא תקין.

### `feedback.hasReporterEmail`
**הרשאה:** אינה נדרשת — מוחזר ביט קיום בלבד, בלי הכתובת עצמה.

Expand Down
28 changes: 28 additions & 0 deletions docs/plugin-sdk/otzaria_plugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2582,6 +2582,23 @@ export interface SubmitBookCorrectionParams {
requireTextCorrection?: boolean;
}

export interface GetBookCorrectionStatusParams {
/** The `reportId` that was passed to `feedback.submitBookCorrection`. */
reportId: string;
}

export interface GetBookCorrectionStatusResult {
/**
* `queued`: still in Otzaria's local queue. `sent`: recorded as sent. `rejected`:
* permanently rejected by the server. `unknown`: not found (deleted, trimmed
* from the sent history, restored from a backup, or caught between the queue
* and the history). `unknown` is not final: keep the previous state.
*/
status: 'queued' | 'sent' | 'rejected' | 'unknown';
reportId: string;
nativeReportId: string;
}

export interface SubmitBookCorrectionResult {
/** `sent`: delivered now. `queued`: stored in Otzaria's local queue. */
status: 'sent' | 'queued';
Expand Down Expand Up @@ -2729,6 +2746,7 @@ export type OtzariaMethod =
| 'publishedData.listOwn'
| 'feedback.sendEmail'
| 'feedback.submitBookCorrection'
| 'feedback.getBookCorrectionStatus'
| 'feedback.report'
| 'feedback.hasReporterEmail'
| 'history.list'
Expand Down Expand Up @@ -2983,6 +3001,16 @@ export interface OtzariaGlobal {
payload: Record<string, unknown> & { direction: Direction }
): Promise<OtzariaResponse<GetLinksResult<Direction>>>;

/**
* State of a correction report this plugin submitted (`queued` reports are
* sent later by Otzaria's own queue). Read-only, own reports only.
* Since 0.9.99.
*/
call(
method: 'feedback.getBookCorrectionStatus',
payload: GetBookCorrectionStatusParams
): Promise<OtzariaResponse<GetBookCorrectionStatusResult>>;

/**
* Call a Host API method.
*
Expand Down
3 changes: 3 additions & 0 deletions docs/plugin-sdk/spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"database.listSources",
"database.query",
"events.setOptions",
"feedback.getBookCorrectionStatus",
"feedback.hasReporterEmail",
"feedback.report",
"feedback.sendEmail",
Expand Down Expand Up @@ -288,6 +289,7 @@
"database.describeSource": "database.read",
"database.listSources": "database.read",
"database.query": "database.read",
"feedback.getBookCorrectionStatus": "feedback.send_email",
"feedback.sendEmail": "feedback.send_email",
"feedback.submitBookCorrection": "feedback.send_email",
"fonts.listInstalled": "app.info.read",
Expand Down Expand Up @@ -453,6 +455,7 @@
"database.listSources": "0.9.89",
"database.query": "0.9.89",
"events.setOptions": "0.9.98.1",
"feedback.getBookCorrectionStatus": "0.9.99",
"feedback.hasReporterEmail": "0.9.97",
"feedback.report": "0.9.97",
"feedback.sendEmail": "0.9.89",
Expand Down
25 changes: 25 additions & 0 deletions lib/plugins/bridge/plugin_bridge_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -712,10 +712,12 @@ class PluginBridgeAdapter {
PluginHighlightRegistry? highlightRegistry,
PluginReportService? reportService,
PluginBookCorrectionService? bookCorrectionService,
DirectErrorReportService? directReportService,
PluginSearchFieldSessionService? searchFieldSessions,
}) : _pluginRepo = pluginRepository ?? PluginRegistryRepository(),
_pluginReportService = reportService,
_pluginBookCorrectionService = bookCorrectionService,
_directBookReportService = directReportService,
// שירות שהוזרק (בדיקות) מקבל בעלים פרטי; אחרת הבעלים של החלון.
_alerts =
alertsClient ??
Expand Down Expand Up @@ -7245,6 +7247,8 @@ class PluginBridgeAdapter {
switch (action) {
case 'submitBookCorrection':
return _submitBookCorrection(args);
case 'getBookCorrectionStatus':
return _getBookCorrectionStatus(args);
case 'sendEmail':
final to = args['to'] as String?;
final subject = args['subject'] as String?;
Expand Down Expand Up @@ -7353,6 +7357,27 @@ class PluginBridgeAdapter {
}
}

/// מצב דיווח תיקון שהתוסף עצמו שלח. המזהה המקומי נבנה כאן מהמזהה של התוסף,
/// ולכן תוסף יכול לשאול רק על דיווחים שלו, ושום תוכן אינו נחשף.
Future<Map<String, dynamic>> _getBookCorrectionStatus(
Map<String, dynamic> args,
) async {
final id = args['reportId'];
if (id is! String || !PluginBookCorrectionService.isValidReportId(id)) {
throw Exception('error.invalid_params: מזהה הדיווח אינו תקין.');
}
final nativeId = PluginBookCorrectionService.nativeReportId(
plugin.pluginId,
id,
);
final direct = _directBookReportService ??= DirectErrorReportService();
return {
'status': await direct.lookupReportStatus(nativeId),
'reportId': id,
'nativeReportId': nativeId,
};
}

Future<Map<String, dynamic>> _submitBookCorrection(
Map<String, dynamic> args,
) async {
Expand Down
5 changes: 5 additions & 0 deletions lib/plugins/models/plugin_api_catalog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,11 @@ const Map<String, PluginApiMethod> pluginApiMethods = {
'0.9.98.1',
hasPermissionHint: true,
),
'feedback.getBookCorrectionStatus': PluginApiMethod(
'feedback.send_email',
'0.9.99',
hasPermissionHint: true,
),
'feedback.report': PluginApiMethod(null, '0.9.97'),
'feedback.hasReporterEmail': PluginApiMethod(null, '0.9.97'),
'history.list': PluginApiMethod(
Expand Down
14 changes: 12 additions & 2 deletions lib/plugins/services/plugin_book_correction_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ class PluginBookCorrectionService {
DateTime Function()? now,
}) : now = now ?? DateTime.now;

static final RegExp _reportIdPattern = RegExp(r'^[a-zA-Z0-9_.:-]{1,160}$');

/// מזהה דיווח שהתוסף בוחר.
static bool isValidReportId(String id) => _reportIdPattern.hasMatch(id);

/// המזהה המקומי של אוצריא לדיווח של תוסף: מרחב שמות לכל תוסף, כך שתוסף
/// פוגש רק דיווחים שלו.
static String nativeReportId(String pluginId, String reportId) =>
'$pluginId:$reportId';

Future<Map<String, dynamic>> submit({
required String pluginId,
required Map<String, dynamic> args,
Expand All @@ -68,7 +78,7 @@ class PluginBookCorrectionService {
final start = args['sourceStart'];
final end = args['sourceEnd'];
if (id is! String ||
!RegExp(r'^[a-zA-Z0-9_.:-]{1,160}$').hasMatch(id) ||
!isValidReportId(id) ||
first is! int ||
first < 0 ||
last is! int ||
Expand Down Expand Up @@ -197,7 +207,7 @@ class PluginBookCorrectionService {
].join('\n');
const fit = DirectErrorReport.fitDisplayField;
final report = DirectErrorReport(
id: '$pluginId:$id',
id: nativeReportId(pluginId, id),
senderEmail: email,
schemaVersion: DirectErrorReport.currentSchemaVersion,
reportKind: correction == null
Expand Down
10 changes: 10 additions & 0 deletions lib/services/direct_error_report_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ class DirectErrorReportService {
);
}

/// מצב הדיווח: `queued`, `sent`, `rejected` או `unknown`, שאינו סופי:
/// במעבר מהתור להיסטוריה הדיווח עשוי להיעדר רגע משתי הרשימות.
Future<String> lookupReportStatus(String reportId) async {
final sent = await _rowOf(sentKind, reportId);
// ניסיון נוסף עשוי להישאר בתור אחרי שכבר נרשמה מסירה.
if (sent != null && sent.payload['rejectionReason'] == null) return 'sent';
if (await _rowOf(pendingKind, reportId) != null) return 'queued';
return sent == null ? 'unknown' : 'rejected';
}

Future<int> getPendingReportsCount() => _reports.countByKind(pendingKind);

Future<List<DirectErrorReport>> getPendingReports() async {
Expand Down
133 changes: 129 additions & 4 deletions test/plugins/bridge/plugin_bridge_book_correction_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'package:otzaria/settings/engine/app_settings_store.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:otzaria/core/app_paths.dart';
import 'package:otzaria/core/user_state/pending_report_store.dart';
import 'package:otzaria/core/user_state/user_state_database.dart';
import 'package:otzaria/data/data_providers/sqlite_data_provider.dart';
import 'package:otzaria/data/data_providers/user_books_database_holder.dart';
import 'package:otzaria/data/repository/data_repository.dart';
Expand Down Expand Up @@ -61,8 +63,8 @@ class _StubPluginRegistryRepository extends PluginRegistryRepository {
Future<bool?> getPermission(String pluginId, String permission) async => true;
}

InstalledPlugin _plugin() => InstalledPlugin(
pluginId: 'test.plugin',
InstalledPlugin _plugin([String id = 'test.plugin']) => InstalledPlugin(
pluginId: id,
name: 'Test Plugin',
version: '1.0.0',
installPath: '/',
Expand All @@ -71,7 +73,7 @@ InstalledPlugin _plugin() => InstalledPlugin(
pinned: true,
manifest: PluginManifest(
schemaVersion: 1,
id: 'test.plugin',
id: id,
name: 'Test Plugin',
version: '1.0.0',
description: '',
Expand Down Expand Up @@ -121,8 +123,10 @@ void main() {

PluginBridgeAdapter buildAdapter({
PluginBookCorrectionService? bookCorrectionService,
DirectErrorReportService? directReportService,
String pluginId = 'test.plugin',
}) => PluginBridgeAdapter(
_plugin(),
_plugin(pluginId),
dependencies: PluginBridgeDependencies(
historyBloc: _MockHistoryBloc(),
tabsBloc: _StubTabsBloc(),
Expand All @@ -139,6 +143,7 @@ void main() {
),
pluginRepository: _StubPluginRegistryRepository(),
bookCorrectionService: bookCorrectionService,
directReportService: directReportService,
);

setUp(() {
Expand All @@ -151,6 +156,126 @@ void main() {
_codedError(code),
);

group('feedback.getBookCorrectionStatus', () {
for (final args in <Map<String, dynamic>>[
{},
{'reportId': 42},
{'reportId': ''},
{'reportId': 'יש רווח'},
{'reportId': 'x' * 161},
]) {
test('דוחה מזהה לא תקין: $args', () {
return expectLater(
adapter.execute('feedback', 'getBookCorrectionStatus', args),
_codedError('error.invalid_params'),
);
});
}

group('מרחב שמות לכל תוסף', () {
late Directory tmp;
late UserStateDatabase db;
late DirectErrorReportService direct;

setUp(() async {
tmp = Directory.systemTemp.createTempSync('otzaria_status_');
db = UserStateDatabase.openAt(path.join(tmp.path, 'user_state.db'));
final store = PendingReportStore(database: db);
direct = DirectErrorReportService(reportStore: store);
await store.add(
DirectErrorReportService.pendingKind,
DirectErrorReport(
id: 'plugin.a:r1',
senderEmail: 'user@example.com',
subject: 's',
bookTitle: 'ספר',
currentRef: '',
lineNumber: 1,
errorDetails: 'd',
queueType: DirectErrorReportQueueType.automaticRetry,
createdAt: DateTime(2026),
).toJson(),
);
});

tearDown(() async {
await direct.closeHttpClient();
db.close();
tmp.deleteSync(recursive: true);
});

Future<Map<String, dynamic>> status(String pluginId) async =>
Map<String, dynamic>.from(
await buildAdapter(
directReportService: direct,
pluginId: pluginId,
).execute('feedback', 'getBookCorrectionStatus', {
'reportId': 'r1',
})
as Map,
);

test('התוסף הבעלים רואה את הדיווח שלו', () async {
expect(await status('plugin.a'), {
'status': 'queued',
'reportId': 'r1',
'nativeReportId': 'plugin.a:r1',
});
});

test('תוסף אחר עם אותו reportId לא רואה את הדיווח', () async {
expect(await status('plugin.b'), {
'status': 'unknown',
'reportId': 'r1',
'nativeReportId': 'plugin.b:r1',
});
});
test('מזהה מפורש ושדות עודפים אינם עוקפים את מרחב השמות', () async {
final caller = buildAdapter(
directReportService: direct,
pluginId: 'plugin.b',
);
expect(
await caller.execute('feedback', 'getBookCorrectionStatus', {
'reportId': 'plugin.a:r1',
'nativeReportId': 'plugin.a:r1',
'pluginId': 'plugin.a',
'status': 'sent',
}),
{
'status': 'unknown',
'reportId': 'plugin.a:r1',
'nativeReportId': 'plugin.b:plugin.a:r1',
},
);
});

test('דיווח תיקון רגיל על ספר אינו גלוי לתוסף', () async {
const id = '1782315021188111-1234567';
await PendingReportStore(database: db).add(
DirectErrorReportService.pendingKind,
{'id': id},
);
expect(await direct.lookupReportStatus(id), 'queued');
final caller = buildAdapter(
directReportService: direct,
pluginId: 'plugin.a',
);
expect(
await caller.execute('feedback', 'getBookCorrectionStatus', {
'reportId': id,
'nativeReportId': id,
}),
{
'status': 'unknown',
'reportId': id,
'nativeReportId': 'plugin.a:$id',
},
);
});
});
});

group('feedback.submitBookCorrection identity', () {
for (final args in <Map<String, dynamic>>[
{},
Expand Down
Loading
Loading