parent message gets shown in chat bubble

This commit is contained in:
Lars Neuhaus 2024-04-19 18:55:07 +02:00
parent 232a767312
commit ae6b6511d7
3 changed files with 95 additions and 50 deletions

View File

@ -38,6 +38,7 @@ class GetChatResponseObject {
Map<String, int>? reactions; Map<String, int>? reactions;
List<String>? reactionsSelf; List<String>? reactionsSelf;
@JsonKey(fromJson: _fromJson) Map<String, RichObjectString>? messageParameters; @JsonKey(fromJson: _fromJson) Map<String, RichObjectString>? messageParameters;
GetChatResponseObject? parent;
GetChatResponseObject( GetChatResponseObject(
this.id, this.id,
@ -53,7 +54,8 @@ class GetChatResponseObject {
this.message, this.message,
this.messageParameters, this.messageParameters,
this.reactions, this.reactions,
this.reactionsSelf this.reactionsSelf,
this.parent,
); );
factory GetChatResponseObject.fromJson(Map<String, dynamic> json) => _$GetChatResponseObjectFromJson(json); factory GetChatResponseObject.fromJson(Map<String, dynamic> json) => _$GetChatResponseObjectFromJson(json);
@ -78,7 +80,8 @@ class GetChatResponseObject {
text, text,
null, null,
null, null,
null null,
null,
); );
} }

View File

@ -52,6 +52,10 @@ GetChatResponseObject _$GetChatResponseObjectFromJson(
(json['reactionsSelf'] as List<dynamic>?) (json['reactionsSelf'] as List<dynamic>?)
?.map((e) => e as String) ?.map((e) => e as String)
.toList(), .toList(),
json['parent'] == null
? null
: GetChatResponseObject.fromJson(
json['parent'] as Map<String, dynamic>),
); );
Map<String, dynamic> _$GetChatResponseObjectToJson( Map<String, dynamic> _$GetChatResponseObjectToJson(
@ -74,6 +78,7 @@ Map<String, dynamic> _$GetChatResponseObjectToJson(
'reactionsSelf': instance.reactionsSelf, 'reactionsSelf': instance.reactionsSelf,
'messageParameters': 'messageParameters':
instance.messageParameters?.map((k, e) => MapEntry(k, e.toJson())), instance.messageParameters?.map((k, e) => MapEntry(k, e.toJson())),
'parent': instance.parent?.toJson(),
}; };
const _$GetRoomResponseObjectMessageActorTypeEnumMap = { const _$GetRoomResponseObjectMessageActorTypeEnumMap = {

View File

@ -2,6 +2,7 @@ import 'package:better_open_file/better_open_file.dart';
import 'package:bubble/bubble.dart'; import 'package:bubble/bubble.dart';
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart' as emojis; import 'package:emoji_picker_flutter/emoji_picker_flutter.dart' as emojis;
import 'package:flowder/flowder.dart'; import 'package:flowder/flowder.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
@ -266,6 +267,7 @@ class _ChatBubbleState extends State<ChatBubble> {
message = ChatMessage(originalMessage: widget.bubbleData.message, originalData: widget.bubbleData.messageParameters); message = ChatMessage(originalMessage: widget.bubbleData.message, originalData: widget.bubbleData.messageParameters);
var showActorDisplayName = widget.bubbleData.messageType == GetRoomResponseObjectMessageType.comment && widget.chatData.type != GetRoomResponseObjectConversationType.oneToOne; var showActorDisplayName = widget.bubbleData.messageType == GetRoomResponseObjectMessageType.comment && widget.chatData.type != GetRoomResponseObjectConversationType.oneToOne;
var showBubbleTime = widget.bubbleData.messageType != GetRoomResponseObjectMessageType.system; var showBubbleTime = widget.bubbleData.messageType != GetRoomResponseObjectMessageType.system;
var parent = widget.bubbleData.parent;
var actorText = Text( var actorText = Text(
widget.bubbleData.actorDisplayName, widget.bubbleData.actorDisplayName,
@ -343,57 +345,92 @@ class _ChatBubbleState extends State<ChatBubble> {
}, },
child: Bubble( child: Bubble(
style: getStyle(), style: getStyle(),
child: Container( child: Column(
constraints: BoxConstraints( children: [
maxWidth: MediaQuery.of(context).size.width * 0.9, Visibility(
minWidth: showActorDisplayName visible: parent != null && parent.message.isNotEmpty,
? actorText.size.width child: Wrap(
: timeText.size.width + (widget.isSender ? widget.spacing + widget.timeIconSize : 0) + 3, alignment: WrapAlignment.start,
), clipBehavior: Clip.hardEdge,
child: Stack( children: [
children: [ DecoratedBox(
Padding( decoration: BoxDecoration(
padding: EdgeInsets.only(bottom: showBubbleTime ? 18 : 0, top: showActorDisplayName ? 18 : 0), color: Theme.of(context).secondaryHeaderColor,
child: message.getWidget() ),
child: Text(
parent?.message ?? '',
maxLines: 2,
style: const TextStyle(
overflow: TextOverflow.ellipsis,
),
),
),
],
), ),
Visibility( // SizedBox(
visible: showActorDisplayName, // width: parentMessageWidth < MediaQuery.of(context).size.width * 0.9
child: Positioned( // ? parentMessageWidth.toDouble()
top: 0, // : MediaQuery.of(context).size.width * 0.9,
left: 0, // height: 20,
child: actorText // child: Text(
), // parentMessage?.message ?? 'Ranz',
// overflow: TextOverflow.clip,
// ),
// ),
),
Container(
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width * 0.9,
minWidth: showActorDisplayName
? actorText.size.width
: timeText.size.width + (widget.isSender ? widget.spacing + widget.timeIconSize : 0) + 3,
), ),
Visibility( child: Stack(
visible: showBubbleTime, children: [
child: Positioned( Padding(
bottom: 0, padding: EdgeInsets.only(bottom: showBubbleTime ? 18 : 0, top: showActorDisplayName ? 18 : 0),
right: 0, child: message.getWidget()
child: Row( ),
children: [ Visibility(
timeText, visible: showActorDisplayName,
if(widget.isSender) ...[ child: Positioned(
SizedBox(width: widget.spacing), top: 0,
if(widget.isRead) left: 0,
Icon(Icons.done_all_outlined, size: widget.timeIconSize, color: widget.timeIconColor) child: actorText
else ),
Icon(Icons.done_outlined, size: widget.timeIconSize, color: widget.timeIconColor) ),
] Visibility(
], visible: showBubbleTime,
) child: Positioned(
), bottom: 0,
right: 0,
child: Row(
children: [
timeText,
if(widget.isSender) ...[
SizedBox(width: widget.spacing),
if(widget.isRead)
Icon(Icons.done_all_outlined, size: widget.timeIconSize, color: widget.timeIconColor)
else
Icon(Icons.done_outlined, size: widget.timeIconSize, color: widget.timeIconColor)
]
],
)
),
),
Visibility(
visible: downloadProgress > 0,
child: Positioned(
bottom: 0,
right: 0,
left: 0,
child: LinearProgressIndicator(value: downloadProgress/100),
),
),
],
), ),
Visibility( ),
visible: downloadProgress > 0, ],
child: Positioned(
bottom: 0,
right: 0,
left: 0,
child: LinearProgressIndicator(value: downloadProgress/100),
),
),
],
),
), ),
), ),
), ),