Implemented RichObjectString in text messages
This commit is contained in:
@ -33,6 +33,7 @@ class GetChatResponseObject {
|
||||
bool isReplyable;
|
||||
String referenceId;
|
||||
String message;
|
||||
@JsonKey(fromJson: _fromJson) Map<String, RichObjectString>? messageParameters;
|
||||
|
||||
GetChatResponseObject(
|
||||
this.id,
|
||||
@ -45,9 +46,45 @@ class GetChatResponseObject {
|
||||
this.messageType,
|
||||
this.isReplyable,
|
||||
this.referenceId,
|
||||
this.message);
|
||||
this.message,
|
||||
this.messageParameters);
|
||||
|
||||
factory GetChatResponseObject.fromJson(Map<String, dynamic> json) => _$GetChatResponseObjectFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetChatResponseObjectToJson(this);
|
||||
|
||||
}
|
||||
|
||||
Map<String, RichObjectString>? _fromJson(json) {
|
||||
if(json is Map<String, dynamic>) {
|
||||
Map<String, RichObjectString> data = {};
|
||||
for (var element in json.keys) {
|
||||
data.putIfAbsent(element, () => RichObjectString.fromJson(json[element]));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class RichObjectString {
|
||||
RichObjectStringObjectType type;
|
||||
String id;
|
||||
String name;
|
||||
|
||||
String? path;
|
||||
String? link;
|
||||
|
||||
RichObjectString(this.type, this.id, this.name, this.path, this.link);
|
||||
|
||||
factory RichObjectString.fromJson(Map<String, dynamic> json) => _$RichObjectStringFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$RichObjectStringToJson(this);
|
||||
}
|
||||
|
||||
enum RichObjectStringObjectType {
|
||||
@JsonValue("user") user,
|
||||
@JsonValue("group") group,
|
||||
@JsonValue("file") file,
|
||||
@JsonValue("guest") guest,
|
||||
@JsonValue("highlight") highlight,
|
||||
}
|
@ -34,6 +34,7 @@ GetChatResponseObject _$GetChatResponseObjectFromJson(
|
||||
json['isReplyable'] as bool,
|
||||
json['referenceId'] as String,
|
||||
json['message'] as String,
|
||||
_fromJson(json['messageParameters']),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GetChatResponseObjectToJson(
|
||||
@ -52,6 +53,8 @@ Map<String, dynamic> _$GetChatResponseObjectToJson(
|
||||
'isReplyable': instance.isReplyable,
|
||||
'referenceId': instance.referenceId,
|
||||
'message': instance.message,
|
||||
'messageParameters':
|
||||
instance.messageParameters?.map((k, e) => MapEntry(k, e.toJson())),
|
||||
};
|
||||
|
||||
const _$GetRoomResponseObjectMessageActorTypeEnumMap = {
|
||||
@ -67,3 +70,29 @@ const _$GetRoomResponseObjectMessageTypeEnumMap = {
|
||||
GetRoomResponseObjectMessageType.system: 'system',
|
||||
GetRoomResponseObjectMessageType.command: 'command',
|
||||
};
|
||||
|
||||
RichObjectString _$RichObjectStringFromJson(Map<String, dynamic> json) =>
|
||||
RichObjectString(
|
||||
$enumDecode(_$RichObjectStringObjectTypeEnumMap, json['type']),
|
||||
json['id'] as String,
|
||||
json['name'] as String,
|
||||
json['path'] as String?,
|
||||
json['link'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$RichObjectStringToJson(RichObjectString instance) =>
|
||||
<String, dynamic>{
|
||||
'type': _$RichObjectStringObjectTypeEnumMap[instance.type]!,
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
'path': instance.path,
|
||||
'link': instance.link,
|
||||
};
|
||||
|
||||
const _$RichObjectStringObjectTypeEnumMap = {
|
||||
RichObjectStringObjectType.user: 'user',
|
||||
RichObjectStringObjectType.group: 'group',
|
||||
RichObjectStringObjectType.file: 'file',
|
||||
RichObjectStringObjectType.guest: 'guest',
|
||||
RichObjectStringObjectType.highlight: 'highlight',
|
||||
};
|
||||
|
@ -0,0 +1,13 @@
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/chat/getChatResponse.dart';
|
||||
|
||||
class RichObjectStringProcessor {
|
||||
static String parse(String message, Map<String, RichObjectString>? data) {
|
||||
if(data == null) return message;
|
||||
|
||||
data.forEach((key, value) {
|
||||
message = message.replaceAll(RegExp("{$key}"), value.name);
|
||||
});
|
||||
|
||||
return message;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user