diff --git a/packages/simplex_app/lib/model/contact.dart b/packages/simplex_app/lib/model/contact.dart new file mode 100644 index 0000000000..04f1feb05b --- /dev/null +++ b/packages/simplex_app/lib/model/contact.dart @@ -0,0 +1,33 @@ +import 'dart:convert'; + +class Contact { + final String? name; + final String? msg; + final String? msgTime; + + Contact({this.name, this.msg, this.msgTime}); + + factory Contact.fromJson(Map json) { + return Contact( + name: json['name'], msg: json['msg'], msgTime: json['msgTime']); + } + + static Map toJson(Contact contact) { + return { + 'name': contact.name, + 'msg': contact.msg, + 'msgTime': contact.msgTime, + }; + } + + static String encode(List contacts) => json.encode( + contacts + .map>((contact) => Contact.toJson(contact)) + .toList(), + ); + + static List decode(String? contacts) => + (json.decode(contacts!) as List) + .map((item) => Contact.fromJson(item)) + .toList(); +}