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

[TASK] Messaging fixes and tweaks #4656

Merged
merged 4 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Fixed
- Messaging fixes and tweaks [#4621](https://github.com/rokwire/illinois-app/issues/4621)
## [6.1.44] - 2025-01-21
### Changed
- Connections renamed to Conversations [#4651](https://github.com/rokwire/illinois-app/issues/4651).
Expand Down
4 changes: 4 additions & 0 deletions assets/strings.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
"dialog.deselect_all.hint":"",
"dialog.success.title":"Success",
"dialog.success.hint":"",
"dialog.edit.title":"Edit",
"dialog.edit.hint":"",
"dialog.delete.title":"Delete",
"dialog.delete.hint":"",

"tabbar.home.title":"Home",
"tabbar.home.hint":"Home Page",
Expand Down
4 changes: 4 additions & 0 deletions assets/strings.es.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"dialog.deselect_all.hint":"",
"dialog.success.title":"Success",
"dialog.success.hint":"",
"dialog.edit.title":"Edit",
"dialog.edit.hint":"",
"dialog.delete.title":"Delete",
"dialog.delete.hint":"",

"tabbar.home.title":"Inicio",
"tabbar.home.hint":"Página de inicio",
Expand Down
6 changes: 5 additions & 1 deletion assets/strings.zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
"dialog.deselect_all.title":"Deselect All",
"dialog.deselect_all.hint":"",
"dialog.success.title":"Success",
"dialog.success.hint":"",
"dialog.success.hint":"",
"dialog.edit.title":"Edit",
"dialog.edit.hint":"",
"dialog.delete.title":"Delete",
"dialog.delete.hint":"",

"tabbar.home.title":"主页",
"tabbar.home.hint":"主页",
Expand Down
194 changes: 149 additions & 45 deletions lib/ui/messages/MessagesConversationPanel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ class _MessagesConversationPanelState extends State<MessagesConversationPanel>
bool _hasMoreMessages = false;
final int _messagesPageSize = 20;
Message? _editingMessage;
Message? _deletingMessage;

final Set<String> _globalIds = {};

static const double _photoSize = 20;

@override
void initState() {
NotificationService().subscribe(this, [
Expand Down Expand Up @@ -258,15 +261,16 @@ class _MessagesConversationPanelState extends State<MessagesConversationPanel>
Widget _buildMessageCard(Message message) {
String? senderId = message.sender?.accountId;
bool isCurrentUser = (senderId == _currentUserId);
bool hasProgress = (_deletingMessage != null) && (message.globalId == _deletingMessage?.globalId);
bool canLongPress = isCurrentUser && (_editingMessage == null) && (_deletingMessage == null);
Key? contentItemKey = widget.isTargetMessage(message) ? _targetMessageContentItemKey : null;
Decoration cardDecoration = widget.isTargetMessage(message) ? _highlightedMessageCardDecoration : _messageCardDecoration;

return GestureDetector(onLongPress: isCurrentUser ? () => _onMessageLongPress(message) : null, child:
Widget cardWidget = GestureDetector(onLongPress: canLongPress ? () => _onMessageLongPress(message) : null, child:
FutureBuilder<Widget>(
future: _buildAvatarWidget(isCurrentUser: isCurrentUser, senderId: senderId),
builder: (context, snapshot) {
Widget avatar = snapshot.data ??
(Styles().images.getImage('person-circle-white', size: 20.0, color: Styles().colors.fillColorSecondary) ?? Container());
Widget avatar = (snapshot.data ?? (Styles().images.getImage('person-circle-white', size: _photoSize, color: Styles().colors.fillColorSecondary) ?? Container()));

return Container(key: contentItemKey, margin: EdgeInsets.only(bottom: 16), decoration: cardDecoration, child:
Padding(padding: EdgeInsets.all(16), child:
Expand Down Expand Up @@ -309,16 +313,95 @@ class _MessagesConversationPanelState extends State<MessagesConversationPanel>
},
),
);

return hasProgress ? Stack(children: [
cardWidget,
Positioned.fill(child:
Center(child:
SizedBox(width: _photoSize, height: _photoSize, child:
CircularProgressIndicator(color: Styles().colors.fillColorSecondary, strokeWidth: 2,),
)
)
)
]) : cardWidget;
}

void _onMessageLongPress(Message message) {
showDialog(
context: context,
builder: (_) {
return AlertDialog(
title: Text(Localization().getStringEx('', 'Message Options'), style: TextStyle(color: Styles().colors.fillColorPrimary)),
content: Text(Localization().getStringEx('', 'Edit or delete this message?'), style: TextStyle(color: Styles().colors.fillColorPrimary)),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
_onEditMessage(message);
},
child: Text(Localization().getStringEx('dialog.edit.title', 'Edit'), style: TextStyle(color: Styles().colors.fillColorPrimary)),
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
_onDeleteMessage(message);
},
child: Text(Localization().getStringEx('dialog.delete.title', 'Delete'), style: TextStyle(color: Styles().colors.fillColorSecondary)),
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(Localization().getStringEx('dialog.cancel.title', 'Cancel'), style: TextStyle(color: Styles().colors.fillColorPrimary)),
),
],
);
}
);
}

void _onMessageLongPress(Message message) { // NEW CODE
void _onEditMessage(Message message) {
setState(() {
_editingMessage = message;
_inputController.text = message.message ?? '';
});
FocusScope.of(context).requestFocus(_inputFieldFocus); // optional: focus the input
FocusScope.of(context).requestFocus(_inputFieldFocus);
}

Future<void> _onDeleteMessage(Message message) async {
String? globalId = message.globalId;
if (globalId == null) {
debugPrint('Cannot delete this message: missing globalId.');
return;
}
if (_conversationId == null) {
debugPrint('Cannot delete message: missing conversationId.');
return;
}

setState(() {
_deletingMessage = message;
});

bool success = await Social().deleteConversationMessage(
conversationId: _conversationId!,
globalMessageId: globalId,
);

if (mounted) {
setState(() {
_deletingMessage = null;
});
if (success) {
setState(() {
_messages.removeWhere((m) => m.globalId == globalId);
});
AppToast.showMessage('Message deleted.');
} else {
AppToast.showMessage('Failed to delete message.');
}
}
}

void _onTapAccount(Message message) {
Analytics().logSelect(target: 'View Account');
Expand Down Expand Up @@ -348,8 +431,8 @@ class _MessagesConversationPanelState extends State<MessagesConversationPanel>
Uint8List? profilePicture = Auth2().profilePicture;
if (profilePicture != null) {
return Container(
width: 20,
height: 20,
width: _photoSize,
height: _photoSize,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
Expand Down Expand Up @@ -420,47 +503,67 @@ class _MessagesConversationPanelState extends State<MessagesConversationPanel>

Widget _buildChatBar() {
bool enabled = true; // Always enabled for now, but you can adjust if needed
bool isEditing = (_editingMessage != null);

return Semantics(
container: true,
child: Material(
color: Styles().colors.background,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: Row(mainAxisSize: MainAxisSize.max, children: [
//_buildMessageOptionsWidget(),
SizedBox(width: 32,), //TODO: add image picker handling
Expanded(
child: Semantics(
container: true,
child: TextField(
key: _inputFieldKey,
enabled: enabled,
controller: _inputController,
minLines: 1,
maxLines: 5,
textCapitalization: TextCapitalization.sentences,
textInputAction: TextInputAction.send,
focusNode: _inputFieldFocus,
onSubmitted: _submitMessage,
onChanged: (_) => setStateIfMounted(() {}),
cursorColor: Styles().colors.fillColorPrimary,
decoration: InputDecoration(
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12.0), borderSide: BorderSide(color: Styles().colors.fillColorPrimary)),
fillColor: Styles().colors.surface,
focusColor: Styles().colors.surface,
hoverColor: Styles().colors.surface,
hintText: "Message ${_getConversationTitle()}",
hintStyle: Styles().textStyles.getTextStyle('widget.item.small')
),
style: Styles().textStyles.getTextStyle('widget.title.regular')
)
),
container: true,
child: Material(
color: Styles().colors.background,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: Row(
mainAxisSize: MainAxisSize.max,
//_buildMessageOptionsWidget(),
children: [
if (isEditing) ...[
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: GestureDetector(
onTap: () {
setState(() {
_editingMessage = null;
_inputController.clear();
});
},
child: Styles().images.getImage('close', size: 32) ?? Container()
),
_buildSendImage(enabled),
])
)
)
),
SizedBox(width: 8),
] else ...[
SizedBox(width: 32),
],
Expanded(
child: Semantics(
container: true,
child: TextField(
key: _inputFieldKey,
enabled: enabled,
controller: _inputController,
minLines: 1,
maxLines: 5,
textCapitalization: TextCapitalization.sentences,
textInputAction: TextInputAction.send,
focusNode: _inputFieldFocus,
onSubmitted: _submitMessage,
onChanged: (_) => setStateIfMounted(() {}),
cursorColor: Styles().colors.fillColorPrimary,
decoration: InputDecoration(
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12.0), borderSide: BorderSide(color: Styles().colors.fillColorPrimary)),
fillColor: Styles().colors.surface,
focusColor: Styles().colors.surface,
hoverColor: Styles().colors.surface,
hintText: "Message ${_getConversationTitle()}",
hintStyle: Styles().textStyles.getTextStyle('widget.item.small')
),
style: Styles().textStyles.getTextStyle('widget.title.regular')
)
),
),
_buildSendImage(enabled),
],
),
),
),
);
}

Expand Down Expand Up @@ -715,6 +818,7 @@ class _MessagesConversationPanelState extends State<MessagesConversationPanel>

_editingMessage = null;
_submitting = false;
_inputController.clear();
// _shouldScrollToTarget = _ScrollTarget.bottom;
});
} else {
Expand Down
23 changes: 15 additions & 8 deletions lib/ui/messages/MessagesHomePanel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class MessagesHomePanel extends StatefulWidget with AnalyticsInfo {
// 1) Add a field to hold the search text
final String? search;
final List<Conversation>? conversations;
static bool enableMute = false;

// Make the constructor private, but accept the new param
MessagesHomePanel._({Key? key, this.search, this.conversations}) : super(key: key);
Expand Down Expand Up @@ -79,10 +80,10 @@ class MessagesHomePanel extends StatefulWidget with AnalyticsInfo {
}

class _MessagesHomePanelState extends State<MessagesHomePanel> with TickerProviderStateMixin implements NotificationsListener {
final List<_FilterEntry> _mutedValues = [
_FilterEntry(name: Localization().getStringEx("panel.messages.label.muted.show", "Show Muted"), value: null), // Show both muted and not muted conversations
_FilterEntry(name: Localization().getStringEx("panel.messages.label.muted.hide", "Hide Muted"), value: false), // Show only not muted conversations
];
final List<_FilterEntry> _mutedValues = MessagesHomePanel.enableMute ? [
_FilterEntry(name: Localization().getStringEx("panel.messages.label.muted.show", "Show Muted"), value: null),
_FilterEntry(name: Localization().getStringEx("panel.messages.label.muted.hide", "Hide Muted"), value: false),
] : [];

final List<_FilterEntry> _times = [
_FilterEntry(name: Localization().getStringEx("panel.messages.label.time.any", "Any Time"), value: null),
Expand Down Expand Up @@ -383,7 +384,8 @@ class _MessagesHomePanelState extends State<MessagesHomePanel> with TickerProvid
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: SingleChildScrollView(scrollDirection: Axis.horizontal, child:
Row(crossAxisAlignment: CrossAxisAlignment.center, children: <Widget>[
FilterSelector(
if (MessagesHomePanel.enableMute)
FilterSelector(
padding: EdgeInsets.symmetric(horizontal: 4),
title: _FilterEntry.entryInList(_mutedValues, _selectedMutedValue)?.name ?? '',
titleTextStyle: Styles().textStyles.getTextStyle('widget.button.title.medium.fat'),
Expand All @@ -399,7 +401,10 @@ class _MessagesHomePanelState extends State<MessagesHomePanel> with TickerProvid
active: _selectedFilter == _FilterType.Time,
onTap: () { _onFilter(_FilterType.Time); }
),
_buildEditBar(),
Visibility(
visible: MessagesHomePanel.enableMute == true,
child: _buildEditBar()
),
],
)),
);
Expand Down Expand Up @@ -604,7 +609,8 @@ class _MessagesHomePanelState extends State<MessagesHomePanel> with TickerProvid

Row(children:<Widget>[Expanded(child: Container(color: Styles().colors.fillColorPrimary.withAlpha(38), height: 1))]),

InkWell(onTap: () => _onToggleMute(mute: true), child:
if (MessagesHomePanel.enableMute) ...[
InkWell(onTap: () => _onToggleMute(mute: true), child:
Padding(padding: EdgeInsets.symmetric(vertical: 12), child:
Row(children:<Widget>[
Padding(padding: EdgeInsets.only(right: 8), child:
Expand All @@ -616,6 +622,7 @@ class _MessagesHomePanelState extends State<MessagesHomePanel> with TickerProvid
]),
)
),
],

Row(children:<Widget>[Expanded(child: Container(color: Styles().colors.fillColorPrimary.withAlpha(38), height: 1))]),

Expand Down Expand Up @@ -1085,7 +1092,7 @@ class _ConversationCardState extends State<ConversationCard> implements Notifica
style: Styles().textStyles.getTextStyle('widget.card.title.small')
),
),
if (widget.conversation?.mute == true)
if (MessagesHomePanel.enableMute && widget.conversation?.mute == true)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Styles().images.getImage('notification-off'),
Expand Down
2 changes: 1 addition & 1 deletion plugin