Implemented RichObjectString in text messages
This commit is contained in:
parent
cee122602f
commit
5f140821a8
@ -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;
|
||||
}
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:marianum_mobile/api/apiResponse.dart';
|
||||
|
||||
import '../chat/getChatResponse.dart';
|
||||
|
||||
part 'getRoomResponse.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
@ -48,7 +50,7 @@ class GetRoomResponseObject {
|
||||
bool unreadMentionDirect;
|
||||
int lastReadMessage;
|
||||
int lastCommonReadMessage;
|
||||
GetRoomResponseObjectMessage lastMessage;
|
||||
GetChatResponseObject lastMessage;
|
||||
String? status;
|
||||
String? statusIcon;
|
||||
String? statusMessage;
|
||||
@ -104,37 +106,37 @@ enum GetRoomResponseObjectParticipantNotificationLevel {
|
||||
@JsonValue(3) neverNotify,
|
||||
}
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class GetRoomResponseObjectMessage {
|
||||
int id;
|
||||
String token;
|
||||
GetRoomResponseObjectMessageActorType actorType;
|
||||
String actorId;
|
||||
String actorDisplayName;
|
||||
int timestamp;
|
||||
String message;
|
||||
String systemMessage;
|
||||
GetRoomResponseObjectMessageType messageType;
|
||||
bool isReplyable;
|
||||
String referenceId;
|
||||
|
||||
|
||||
GetRoomResponseObjectMessage(
|
||||
this.id,
|
||||
this.token,
|
||||
this.actorType,
|
||||
this.actorId,
|
||||
this.actorDisplayName,
|
||||
this.timestamp,
|
||||
this.message,
|
||||
this.systemMessage,
|
||||
this.messageType,
|
||||
this.isReplyable,
|
||||
this.referenceId);
|
||||
|
||||
factory GetRoomResponseObjectMessage.fromJson(Map<String, dynamic> json) => _$GetRoomResponseObjectMessageFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetRoomResponseObjectMessageToJson(this);
|
||||
}
|
||||
// @JsonSerializable(explicitToJson: true)
|
||||
// class GetRoomResponseObjectMessage {
|
||||
// int id;
|
||||
// String token;
|
||||
// GetRoomResponseObjectMessageActorType actorType;
|
||||
// String actorId;
|
||||
// String actorDisplayName;
|
||||
// int timestamp;
|
||||
// String message;
|
||||
// String systemMessage;
|
||||
// GetRoomResponseObjectMessageType messageType;
|
||||
// bool isReplyable;
|
||||
// String referenceId;
|
||||
//
|
||||
//
|
||||
// GetRoomResponseObjectMessage(
|
||||
// this.id,
|
||||
// this.token,
|
||||
// this.actorType,
|
||||
// this.actorId,
|
||||
// this.actorDisplayName,
|
||||
// this.timestamp,
|
||||
// this.message,
|
||||
// this.systemMessage,
|
||||
// this.messageType,
|
||||
// this.isReplyable,
|
||||
// this.referenceId);
|
||||
//
|
||||
// factory GetRoomResponseObjectMessage.fromJson(Map<String, dynamic> json) => _$GetRoomResponseObjectMessageFromJson(json);
|
||||
// Map<String, dynamic> toJson() => _$GetRoomResponseObjectMessageToJson(this);
|
||||
// }
|
||||
|
||||
enum GetRoomResponseObjectMessageActorType {
|
||||
@JsonValue("users") user,
|
||||
|
@ -48,7 +48,7 @@ GetRoomResponseObject _$GetRoomResponseObjectFromJson(
|
||||
json['unreadMentionDirect'] as bool,
|
||||
json['lastReadMessage'] as int,
|
||||
json['lastCommonReadMessage'] as int,
|
||||
GetRoomResponseObjectMessage.fromJson(
|
||||
GetChatResponseObject.fromJson(
|
||||
json['lastMessage'] as Map<String, dynamic>),
|
||||
json['status'] as String?,
|
||||
json['statusIcon'] as String?,
|
||||
@ -106,53 +106,3 @@ const _$GetRoomResponseObjectParticipantNotificationLevelEnumMap = {
|
||||
GetRoomResponseObjectParticipantNotificationLevel.notifyOnMention: 2,
|
||||
GetRoomResponseObjectParticipantNotificationLevel.neverNotify: 3,
|
||||
};
|
||||
|
||||
GetRoomResponseObjectMessage _$GetRoomResponseObjectMessageFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
GetRoomResponseObjectMessage(
|
||||
json['id'] as int,
|
||||
json['token'] as String,
|
||||
$enumDecode(
|
||||
_$GetRoomResponseObjectMessageActorTypeEnumMap, json['actorType']),
|
||||
json['actorId'] as String,
|
||||
json['actorDisplayName'] as String,
|
||||
json['timestamp'] as int,
|
||||
json['message'] as String,
|
||||
json['systemMessage'] as String,
|
||||
$enumDecode(
|
||||
_$GetRoomResponseObjectMessageTypeEnumMap, json['messageType']),
|
||||
json['isReplyable'] as bool,
|
||||
json['referenceId'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GetRoomResponseObjectMessageToJson(
|
||||
GetRoomResponseObjectMessage instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'token': instance.token,
|
||||
'actorType':
|
||||
_$GetRoomResponseObjectMessageActorTypeEnumMap[instance.actorType]!,
|
||||
'actorId': instance.actorId,
|
||||
'actorDisplayName': instance.actorDisplayName,
|
||||
'timestamp': instance.timestamp,
|
||||
'message': instance.message,
|
||||
'systemMessage': instance.systemMessage,
|
||||
'messageType':
|
||||
_$GetRoomResponseObjectMessageTypeEnumMap[instance.messageType]!,
|
||||
'isReplyable': instance.isReplyable,
|
||||
'referenceId': instance.referenceId,
|
||||
};
|
||||
|
||||
const _$GetRoomResponseObjectMessageActorTypeEnumMap = {
|
||||
GetRoomResponseObjectMessageActorType.user: 'users',
|
||||
GetRoomResponseObjectMessageActorType.guest: 'guests',
|
||||
GetRoomResponseObjectMessageActorType.bot: 'bots',
|
||||
GetRoomResponseObjectMessageActorType.bridge: 'bridged',
|
||||
};
|
||||
|
||||
const _$GetRoomResponseObjectMessageTypeEnumMap = {
|
||||
GetRoomResponseObjectMessageType.comment: 'comment',
|
||||
GetRoomResponseObjectMessageType.deletedComment: 'comment_deleted',
|
||||
GetRoomResponseObjectMessageType.system: 'system',
|
||||
GetRoomResponseObjectMessageType.command: 'command',
|
||||
};
|
||||
|
@ -2,6 +2,7 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:jiffy/jiffy.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/chat/richObjectStringProcessor.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomResponse.dart';
|
||||
import 'package:marianum_mobile/data/chatList/chatListProps.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@ -62,7 +63,7 @@ class _ChatListState extends State<ChatList> {
|
||||
|
||||
chats.add(ListTile(
|
||||
title: Text(chatRoom.displayName),
|
||||
subtitle: Text("${Jiffy.unixFromSecondsSinceEpoch(chatRoom.lastMessage.timestamp).fromNow()}: ${chatRoom.lastMessage.message.replaceAll("\n", " ")}", overflow: TextOverflow.ellipsis),
|
||||
subtitle: Text("${Jiffy.unixFromSecondsSinceEpoch(chatRoom.lastMessage.timestamp).fromNow()}: ${RichObjectStringProcessor.parse(chatRoom.lastMessage.message.replaceAll("\n", " "), chatRoom.lastMessage.messageParameters)}", overflow: TextOverflow.ellipsis),
|
||||
trailing: Visibility(
|
||||
visible: chatRoom.unreadMessages > 0,
|
||||
child: Container(
|
||||
|
@ -2,6 +2,7 @@
|
||||
import 'package:bubble/bubble.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:jiffy/jiffy.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/chat/richObjectStringProcessor.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomResponse.dart';
|
||||
import 'package:marianum_mobile/data/chatList/chatProps.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@ -96,7 +97,7 @@ class _ChatViewState extends State<ChatView> {
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: showMetadata ? 18 : 0),
|
||||
child: Text(element.message),
|
||||
child: Text(RichObjectStringProcessor.parse(element.message, element.messageParameters)),
|
||||
),
|
||||
Visibility(
|
||||
visible: showMetadata,
|
||||
|
Loading…
x
Reference in New Issue
Block a user