Skip to content

Commit

Permalink
fix(problem_report_message): fix problem report message entity
Browse files Browse the repository at this point in the history
implemented missing fields of the problem report message entity
https://iden3-communication.io/report-problem/2.0/report-problem-message/
  • Loading branch information
emuroni committed Jan 20, 2025
1 parent 7108bdf commit bf74369
Showing 1 changed file with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import 'package:polygonid_flutter_sdk/iden3comm/domain/entities/common/iden3_message_entity.dart';

class ProblemReportMessageEntity extends Iden3MessageEntity<ProblemReportBody> {
// Parent thread
final String pthid;

// List of IDs of previous messages that triggered this one
final List<String>? ack;

ProblemReportMessageEntity({
required super.id,
required super.typ,
required super.type,
required super.thid,
required this.pthid,
required this.ack,
required super.from,
required super.body,
}) : super(messageType: Iden3MessageType.problemReport);
Expand All @@ -18,6 +26,8 @@ class ProblemReportMessageEntity extends Iden3MessageEntity<ProblemReportBody> {
typ: json['typ'],
type: json['type'],
thid: json['thid'],
pthid: json['pthid'],
ack: json['ack'].map<String>((e) => e.toString()).toList(),
from: "",
body: body,
);
Expand All @@ -27,6 +37,8 @@ class ProblemReportMessageEntity extends Iden3MessageEntity<ProblemReportBody> {
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = super.toJson();
data['body'] = body.toJson();
data['pthid'] = pthid;
data['ack'] = ack;
return data;
}

Expand All @@ -42,37 +54,55 @@ class ProblemReportMessageEntity extends Iden3MessageEntity<ProblemReportBody> {
}

class ProblemReportBody {
// (optional) List of arguments matching the placeholders in comment field
final List<String>? args;

// (required) Problem code (See Problem Codes section)
final String code;

// (optional) Human-friendly text describing the problem. Can include {1} placeholders {2}
final String? comment;

// (optional) URI where more help about the problem could be received
final String? escalateTo;

ProblemReportBody({
this.args,
required this.code,
this.comment,
this.escalateTo,
});

factory ProblemReportBody.fromJson(Map<String, dynamic> json) {
return ProblemReportBody(
args: json['args'].map<String>((e) => e.toString()).toList(),
code: json['code'],
comment: json['comment'],
escalateTo: json['escalate_to'],
);
}

Map<String, dynamic> toJson() {
return {
'code': code,
if (args != null) 'args': args,
if (escalateTo != null) 'escalate_to': escalateTo,
if (comment != null) 'comment': comment,
};
}

@override
String toString() => "[ProblemReportBody] {code: $code, comment: $comment}";
String toString() =>
"[ProblemReportBody] {code: $code, comment: $comment, args: $args, escalateTo: $escalateTo}";

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is ProblemReportBody &&
runtimeType == other.runtimeType &&
code == other.code &&
escalateTo == other.escalateTo &&
args == other.args &&
comment == other.comment;

@override
Expand Down

0 comments on commit bf74369

Please sign in to comment.