Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean and improve chat messages widgets #926

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Clean and improve chat messages widgets #926

wants to merge 1 commit into from

Conversation

mdmohsin7
Copy link
Collaborator

@mdmohsin7 mdmohsin7 commented Sep 26, 2024

Summary by Entelligence.AI

I'm sorry, but I can't generate the release notes as you requested because the variable $raw_summary you provided doesn't contain any actual data. It seems like a placeholder. Could you please provide the actual summary of changes? This will help me understand what modifications were made in the codebase and accordingly, I can craft appropriate release notes.

Copy link

github-actions bot commented Sep 26, 2024

Image description Entelligence.AI

I'm sorry, but I can't provide a review or generate a summary as the variable $raw_summary you've mentioned doesn't contain any actual code or changes. Please provide the specific code or changes that you want me to review.


Uplevel your code reviews with Entelligence.AI Pro

Entelligence.AI Pro

If you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, Entelligence.AI Pro is free for open source projects.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description Entelligence.AI

Commits Files that changed from the base of the PR and between 1b4fd1e and 42c6d41 commits.
Files selected (1)
  • app/lib/pages/chat/widgets/ai_message.dart (6)
Files not summarized due to errors (1)
  • app/lib/pages/chat/widgets/ai_message.dart (diff tokens exceeds limit)
Review comments generated (10)
  • Review: 3
  • LGTM: 7

Tips

Chat with Image description Entelligence.AI Bot (@Entelligence.AI)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @Entelligence.AI in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @Entelligence.AI: ignore anywhere in the PR description to pause further reviews from the bot.

Comment on lines +114 to +131
Widget buildMessageWidget(ServerMessage message, Function(String) sendMessage, bool showTypingIndicator,
bool displayOptions, Plugin? pluginSender, Function(ServerMemory) updateMemory) {
if (message.memories.isNotEmpty) {
return MemoriesMessageWidget(
showTypingIndicator: showTypingIndicator,
messageMemories: message.memories.length > 3 ? message.memories.sublist(0, 3) : message.memories,
messageText: message.isEmpty ? '...' : message.text.decodeSting,
updateMemory: updateMemory,
);
} else if (message.type == MessageType.daySummary) {
return DaySummaryWidget(showTypingIndicator: showTypingIndicator, messageText: message.text);
} else if (displayOptions) {
return InitialMessageWidget(
showTypingIndicator: showTypingIndicator, messageText: message.text, sendMessage: sendMessage);
} else {
return NormalMessageWidget(showTypingIndicator: showTypingIndicator, messageText: message.text);
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description Entelligence.AI

There's a potential issue with the message.isEmpty check. It seems like you're checking if the entire message object is empty, but I believe you want to check if the text of the message is empty. You should use message.text.isEmpty instead.

-       messageText: message.isEmpty ? '...' : message.text.decodeSting,
+       messageText: message.text.isEmpty ? '...' : message.text.decodeSting,

Comment on lines +172 to +231
if (m == null) return;
idx = memProvider.addMemoryWithDate(m);
MixpanelManager().chatMessageMemoryClicked(m);
setState(() => memoryDetailLoading[data.$1] = false);
context.read<MemoryDetailProvider>().updateMemory(idx);
await Navigator.of(context).push(
MaterialPageRoute(
builder: (c) => MemoryDetailPage(
memory: m,
),
),
);
//TODO: Not needed anymore I guess because memories are stored in provider and read from there only
if (SharedPreferencesUtil().modifiedMemoryDetails?.id == m.id) {
ServerMemory modifiedDetails = SharedPreferencesUtil().modifiedMemoryDetails!;
widget.updateMemory(SharedPreferencesUtil().modifiedMemoryDetails!);
var copy = List<MessageMemory>.from(widget.message.memories);
copy[data.$1] = MessageMemory(
modifiedDetails.id,
modifiedDetails.createdAt,
MessageMemoryStructured(
modifiedDetails.structured.title,
modifiedDetails.structured.emoji,
));
widget.message.memories.clear();
widget.message.memories.addAll(copy);
SharedPreferencesUtil().modifiedMemoryDetails = null;
setState(() {});
}
}
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Please check your internet connection and try again'),
duration: Duration(seconds: 2),
),
);
}
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8),
width: double.maxFinite,
decoration: BoxDecoration(
color: Colors.grey.shade900,
borderRadius: BorderRadius.circular(12.0),
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'📅 Day Summary ~ ${dateTimeFormat('MMM, dd', DateTime.now())}',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500,
color: Colors.grey.shade300,
decoration: TextDecoration.underline,
),
),
const SizedBox(height: 16),
SelectionArea(
child: showTypingIndicator
? const Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
TypingIndicator(),
],
)
: daySummaryMessagesList(messageText),
),
],
);
}

Widget daySummaryMessagesList(String text) {
var sentences = text.split('. ');
return ListView.builder(
shrinkWrap: true,
itemCount: sentences.length,
itemBuilder: (context, index) {
return ListTile(
visualDensity: const VisualDensity(horizontal: 0, vertical: -1),
contentPadding: EdgeInsets.zero,
horizontalTitleGap: 10,
minLeadingWidth: 2,
leading: Icon(Icons.circle, size: 8, color: Colors.grey.shade300),
title: AutoSizeText(
sentences[index],
// : utf8.decode(widget.message.text.codeUnits),
style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.w500, color: Colors.grey.shade300),
softWrap: true,
),
);
},
);
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description Entelligence.AI

In line 184, you are using DateTime.now() which will always give you the current date when the widget is built. If the widget is kept in the widget tree and not rebuilt for a while (which can happen), the displayed date might be outdated. Consider passing the date as a parameter to the widget or use a state management solution to keep it updated.

Comment on lines +264 to +410
Expanded(
child: Text(
'${tryDecodeText(data.$2.structured.emoji)} ${data.$2.structured.title}',
style: Theme.of(context).textTheme.bodyMedium,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 8),
memoryDetailLoading[data.$1]
? const SizedBox(
height: 24,
width: 24,
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
))
: const Icon(Icons.arrow_right_alt)
],
),
);
} else {
if (memoryDetailLoading[data.$1]) return;
setState(() => memoryDetailLoading[data.$1] = true);
ServerMemory? m = await getMemoryById(data.$2.id);
if (m == null) return;
idx = memProvider.addMemoryWithDate(m);
MixpanelManager().chatMessageMemoryClicked(m);
setState(() => memoryDetailLoading[data.$1] = false);
context.read<MemoryDetailProvider>().updateMemory(idx);
await Navigator.of(context).push(
MaterialPageRoute(
builder: (c) => MemoryDetailPage(
memory: m,
),
),
);
//TODO: Not needed anymore I guess because memories are stored in provider and read from there only
if (SharedPreferencesUtil().modifiedMemoryDetails?.id == m.id) {
ServerMemory modifiedDetails = SharedPreferencesUtil().modifiedMemoryDetails!;
widget.updateMemory(SharedPreferencesUtil().modifiedMemoryDetails!);
var copy = List<MessageMemory>.from(widget.messageMemories);
copy[data.$1] = MessageMemory(
modifiedDetails.id,
modifiedDetails.createdAt,
MessageMemoryStructured(
modifiedDetails.structured.title,
modifiedDetails.structured.emoji,
));
widget.messageMemories.clear();
widget.messageMemories.addAll(copy);
SharedPreferencesUtil().modifiedMemoryDetails = null;
setState(() {});
}
}
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Please check your internet connection and try again'),
duration: Duration(seconds: 2),
),
),
],
],
],
);
}
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8),
width: double.maxFinite,
decoration: BoxDecoration(
color: Colors.grey.shade900,
borderRadius: BorderRadius.circular(12.0),
),
child: Row(
children: [
Expanded(
child: Text(
'${tryDecodeText(data.$2.structured.emoji)} ${data.$2.structured.title}',
style: Theme.of(context).textTheme.bodyMedium,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 8),
memoryDetailLoading[data.$1]
? const SizedBox(
height: 24,
width: 24,
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
))
: const Icon(Icons.arrow_right_alt)
],
),
),
),
),
),
],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description Entelligence.AI

In lines 315-377, there's a lot of nested logic that makes this code hard to read and maintain. Consider breaking this down into smaller functions or methods. This would improve readability and make the code easier to test and debug.

@mdmohsin7 mdmohsin7 marked this pull request as ready for review September 26, 2024 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant