Skip to content

Commit

Permalink
fixed message bubble avatar splash
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangzhiguo1992 authored and iheron committed Jan 30, 2023
1 parent 3280c45 commit 4a2447b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
23 changes: 12 additions & 11 deletions lib/components/chat/message_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ import 'package:nmobile/utils/time.dart';

class ChatMessageItem extends BaseStateFulWidget {
final MessageSchema message;
// final ContactSchema? contact;
// final TopicSchema? topic;
// final PrivateGroupSchema? privateGroup;
final ContactSchema? contact;
final MessageSchema? prevMessage;
final MessageSchema? nextMessage;
final Function(ContactSchema, MessageSchema)? onAvatarLonePress;
final Function(String)? onResend;

ChatMessageItem({
required this.message,
// required this.contact,
// required this.topic,
// required this.privateGroup,
required this.contact,
this.prevMessage,
this.nextMessage,
this.onAvatarLonePress,
Expand Down Expand Up @@ -62,16 +62,17 @@ class _ChatMessageItemState extends BaseStateFulWidgetState<ChatMessageItem> {

@override
void onRefreshArguments() {
_contact = widget.contact;
// topic/group no contact
if ((_contact == null) || (_contact?.clientAddress != widget.message.from)) {
contactCommon.queryByClientAddress(widget.message.from).then((ContactSchema? value) async {
contactCommon.queryByClientAddress(widget.message.from).then((value) async {
if (value == null) {
value = await contactCommon.addByType(widget.message.from, ContactType.none, notify: true, checkDuplicated: false);
}
setState(() {
_contact = value;
});
if ((_contact == null) || ((_contact?.clientAddress != value?.clientAddress) && (value != null))) {
setState(() {
_contact = value;
});
}
});
}
}
Expand Down Expand Up @@ -292,7 +293,7 @@ class _ChatMessageItemState extends BaseStateFulWidgetState<ChatMessageItem> {
mainAxisAlignment: MainAxisAlignment.center,
children: [
Label(
widget.message.isOutbound ? Global.locale((s) => s.you, ctx: context) : (this.widget.contact?.displayName ?? " "),
widget.message.isOutbound ? Global.locale((s) => s.you, ctx: context) : (this._contact?.displayName ?? " "),
type: LabelType.bodyRegular,
fontWeight: FontWeight.bold,
),
Expand All @@ -312,7 +313,7 @@ class _ChatMessageItemState extends BaseStateFulWidgetState<ChatMessageItem> {
type: LabelType.bodyRegular,
),
onTap: () {
ContactProfileScreen.go(context, schema: this.widget.contact);
ContactProfileScreen.go(context, schema: this._contact);
},
),
],
Expand All @@ -331,7 +332,7 @@ class _ChatMessageItemState extends BaseStateFulWidgetState<ChatMessageItem> {
mainAxisSize: MainAxisSize.min,
children: [
Label(
widget.message.isOutbound ? Global.locale((s) => s.you, ctx: context) : (this.widget.contact?.displayName ?? " "),
widget.message.isOutbound ? Global.locale((s) => s.you, ctx: context) : (this._contact?.displayName ?? " "),
maxWidth: Global.screenWidth() * 0.3,
type: LabelType.bodyRegular,
fontWeight: FontWeight.bold,
Expand All @@ -351,7 +352,7 @@ class _ChatMessageItemState extends BaseStateFulWidgetState<ChatMessageItem> {
type: LabelType.bodyRegular,
),
onTap: () {
ContactProfileScreen.go(context, schema: this.widget.contact);
ContactProfileScreen.go(context, schema: this._contact);
},
),
],
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/chat/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -765,9 +765,9 @@ class _ChatMessagesScreenState extends BaseStateFulWidgetState<ChatMessagesScree
MessageSchema msg = _messages[index];
return ChatMessageItem(
message: msg,
// contact: _contact,
// topic: _topic,
// privateGroup: _privateGroup,
contact: _contact,
prevMessage: (index - 1) >= 0 ? _messages[index - 1] : null,
nextMessage: (index + 1) < _messages.length ? _messages[index + 1] : null,
onAvatarLonePress: (ContactSchema contact, _) {
Expand Down

0 comments on commit 4a2447b

Please sign in to comment.