This commit is contained in:
otsmr 2025-07-24 22:27:28 +02:00
parent 02045e8fc0
commit 8979c44e53

View file

@ -298,6 +298,7 @@ class _UserListItem extends State<UserListItem> {
late StreamSubscription<List<Message>> lastMessageStream; late StreamSubscription<List<Message>> lastMessageStream;
List<Message> previewMessages = []; List<Message> previewMessages = [];
bool hasNonOpenedMediaFile = false;
@override @override
void initState() { void initState() {
@ -352,6 +353,17 @@ class _UserListItem extends State<UserListItem> {
} }
} }
final msgs =
previewMessages.where((x) => x.kind == MessageKind.media).toList();
if (msgs.isNotEmpty &&
msgs.first.kind == MessageKind.media &&
msgs.first.messageOtherId != null &&
msgs.first.openedAt == null) {
hasNonOpenedMediaFile = true;
} else {
hasNonOpenedMediaFile = false;
}
lastMessages = newLastMessages; lastMessages = newLastMessages;
messagesNotOpened = newMessagesNotOpened; messagesNotOpened = newMessagesNotOpened;
setState(() { setState(() {
@ -368,12 +380,10 @@ class _UserListItem extends State<UserListItem> {
)); ));
return; return;
} }
if (hasNonOpenedMediaFile) {
final msgs = final msgs =
previewMessages.where((x) => x.kind == MessageKind.media).toList(); previewMessages.where((x) => x.kind == MessageKind.media).toList();
if (msgs.isNotEmpty &&
msgs.first.kind == MessageKind.media &&
msgs.first.messageOtherId != null &&
msgs.first.openedAt == null) {
switch (msgs.first.downloadState) { switch (msgs.first.downloadState) {
case DownloadState.pending: case DownloadState.pending:
await startDownloadMedia(msgs.first, true); await startDownloadMedia(msgs.first, true);
@ -447,12 +457,18 @@ class _UserListItem extends State<UserListItem> {
onPressed: () { onPressed: () {
Navigator.push(context, MaterialPageRoute( Navigator.push(context, MaterialPageRoute(
builder: (context) { builder: (context) {
if (hasNonOpenedMediaFile) {
return ChatMessagesView(widget.user);
} else {
return CameraSendToView(widget.user); return CameraSendToView(widget.user);
}
}, },
)); ));
}, },
icon: FaIcon( icon: FaIcon(
FontAwesomeIcons.camera, hasNonOpenedMediaFile
? FontAwesomeIcons.solidComments
: FontAwesomeIcons.camera,
color: context.color.outline.withAlpha(150), color: context.color.outline.withAlpha(150),
), ),
), ),