Merge branch 'trunk' into newwincert
continuous-integration/drone/pr Build was killed Details

This commit is contained in:
Sarah Jamie Lewis 2022-06-24 05:33:49 +00:00
commit 93adb32ca5
5 changed files with 34 additions and 17 deletions

View File

@ -1,8 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'dart:ffi';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'message.dart'; import 'message.dart';
// we only count up to 100 unread messages, if more than that we can't accurately resync message cache, just reset // we only count up to 100 unread messages, if more than that we can't accurately resync message cache, just reset
@ -118,6 +115,10 @@ class MessageCache extends ChangeNotifier {
return cache[id]; return cache[id];
} }
int findIndex(int id) {
return cacheByIndex.indexWhere((element) => element.messageId == id);
}
MessageInfo? getByContentHash(String contenthash) => cache[cacheByHash[contenthash]]; MessageInfo? getByContentHash(String contenthash) => cache[cacheByHash[contenthash]];
void addNew(String profileOnion, int conversation, int messageID, DateTime timestamp, String senderHandle, String senderImage, bool isAuto, String data, String contenthash) { void addNew(String profileOnion, int conversation, int messageID, DateTime timestamp, String senderHandle, String senderImage, bool isAuto, String data, String contenthash) {

View File

@ -1,6 +1,7 @@
import 'dart:convert'; import 'dart:convert';
import 'package:cwtch/models/message.dart'; import 'package:cwtch/models/message.dart';
import 'package:cwtch/models/messages/malformedmessage.dart';
import 'package:cwtch/widgets/malformedbubble.dart'; import 'package:cwtch/widgets/malformedbubble.dart';
import 'package:cwtch/widgets/messagerow.dart'; import 'package:cwtch/widgets/messagerow.dart';
import 'package:cwtch/widgets/quotedmessage.dart'; import 'package:cwtch/widgets/quotedmessage.dart';
@ -54,7 +55,7 @@ class QuotedMessage extends Message {
dynamic message = jsonDecode(this.content); dynamic message = jsonDecode(this.content);
if (message["body"] == null || message["quotedHash"] == null) { if (message["body"] == null || message["quotedHash"] == null) {
return MalformedBubble(); return MalformedMessage(this.metadata).getWidget(context, key, index);
} }
return ChangeNotifierProvider.value( return ChangeNotifierProvider.value(
@ -64,7 +65,7 @@ class QuotedMessage extends Message {
key: key); key: key);
}); });
} catch (e) { } catch (e) {
return MalformedBubble(); return MalformedMessage(this.metadata).getWidget(context, key, index);
} }
} }
} }

View File

@ -1,4 +1,5 @@
import 'dart:io'; import 'dart:io';
import 'dart:math';
import 'package:cwtch/config.dart'; import 'package:cwtch/config.dart';
import 'package:cwtch/models/contact.dart'; import 'package:cwtch/models/contact.dart';
@ -53,7 +54,7 @@ class FileBubbleState extends State<FileBubble> {
filterQuality: FilterQuality.medium, filterQuality: FilterQuality.medium,
fit: BoxFit.scaleDown, fit: BoxFit.scaleDown,
alignment: Alignment.center, alignment: Alignment.center,
height: MediaQuery.of(context).size.height * 0.30, height: min(MediaQuery.of(context).size.height * 0.30, 150),
isAntiAlias: false, isAntiAlias: false,
errorBuilder: (context, error, stackTrace) { errorBuilder: (context, error, stackTrace) {
return MalformedBubble(); return MalformedBubble();
@ -86,7 +87,7 @@ class FileBubbleState extends State<FileBubble> {
if (downloadComplete && path != null) { if (downloadComplete && path != null) {
var lpath = path.toLowerCase(); var lpath = path.toLowerCase();
if (lpath.endsWith(".jpg") || lpath.endsWith(".jpeg") || lpath.endsWith(".png") || lpath.endsWith(".gif") || lpath.endsWith(".webp") || lpath.endsWith(".bmp")) { if (lpath.endsWith(".jpg") || lpath.endsWith(".jpeg") || lpath.endsWith(".png") || lpath.endsWith(".gif") || lpath.endsWith(".webp") || lpath.endsWith(".bmp")) {
if (myFile == null) { if (myFile == null || myFile?.path != path) {
setState(() { setState(() {
myFile = new File(path!); myFile = new File(path!);
@ -153,6 +154,7 @@ class FileBubbleState extends State<FileBubble> {
if (Provider.of<Settings>(context).shouldPreview(path)) { if (Provider.of<Settings>(context).shouldPreview(path)) {
isPreview = true; isPreview = true;
wdgDecorations = Center( wdgDecorations = Center(
widthFactor: 1.0,
child: MouseRegion( child: MouseRegion(
cursor: SystemMouseCursors.click, cursor: SystemMouseCursors.click,
child: GestureDetector( child: GestureDetector(
@ -223,7 +225,18 @@ class FileBubbleState extends State<FileBubble> {
crossAxisAlignment: fromMe ? CrossAxisAlignment.end : CrossAxisAlignment.start, crossAxisAlignment: fromMe ? CrossAxisAlignment.end : CrossAxisAlignment.start,
mainAxisAlignment: fromMe ? MainAxisAlignment.end : MainAxisAlignment.start, mainAxisAlignment: fromMe ? MainAxisAlignment.end : MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [wdgSender, isPreview ? Container() : wdgMessage, wdgDecorations, messageStatusWidget]), children: [
wdgSender,
isPreview
? Container(
width: 0,
padding: EdgeInsets.zero,
margin: EdgeInsets.zero,
)
: wdgMessage,
wdgDecorations,
messageStatusWidget
]),
)); ));
}); });
} }

View File

@ -85,19 +85,19 @@ class _MessageListState extends State<MessageList> {
itemCount: Provider.of<ContactInfoState>(outerContext).totalMessages, itemCount: Provider.of<ContactInfoState>(outerContext).totalMessages,
reverse: true, // NOTE: There seems to be a bug in flutter that corrects the mouse wheel scroll, but not the drag direction... reverse: true, // NOTE: There seems to be a bug in flutter that corrects the mouse wheel scroll, but not the drag direction...
itemBuilder: (itemBuilderContext, index) { itemBuilder: (itemBuilderContext, index) {
var profileOnion = Provider.of<ProfileInfoState>(outerContext, listen: false).onion; var profileOnion = Provider.of<ProfileInfoState>(itemBuilderContext, listen: false).onion;
var contactHandle = Provider.of<ContactInfoState>(outerContext, listen: false).identifier; var contactHandle = Provider.of<ContactInfoState>(itemBuilderContext, listen: false).identifier;
var messageIndex = index; var messageIndex = index;
return FutureBuilder( return FutureBuilder(
future: messageHandler(outerContext, profileOnion, contactHandle, ByIndex(messageIndex)), future: messageHandler(itemBuilderContext, profileOnion, contactHandle, ByIndex(messageIndex)),
builder: (context, snapshot) { builder: (context, snapshot) {
if (snapshot.hasData) { if (snapshot.hasData) {
var message = snapshot.data as Message; var message = snapshot.data as Message;
// here we create an index key for the contact and assign it to the row. Indexes are unique so we can // here we create an index key for the contact and assign it to the row. Indexes are unique so we can
// reliably use this without running into duplicate keys...it isn't ideal as it means keys need to be re-built // reliably use this without running into duplicate keys...it isn't ideal as it means keys need to be re-built
// when new messages are added...however it is better than the alternative of not having widget keys at all. // when new messages are added...however it is better than the alternative of not having widget keys at all.
var key = Provider.of<ContactInfoState>(outerContext, listen: false).getMessageKey(contactHandle, messageIndex); var key = Provider.of<ContactInfoState>(itemBuilderContext, listen: false).getMessageKey(contactHandle, messageIndex);
return message.getWidget(context, key, messageIndex); return message.getWidget(context, key, messageIndex);
} else { } else {
return MessageLoadingBubble(); return MessageLoadingBubble();

View File

@ -87,10 +87,13 @@ class QuotedMessageBubbleState extends State<QuotedMessageBubble> {
cursor: SystemMouseCursors.click, cursor: SystemMouseCursors.click,
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () {
var index = Provider.of<ContactInfoState>(context, listen: false).messageCache.cacheByHash[qMessage.getMetadata().contenthash]; var messageInfo = Provider.of<ContactInfoState>(context, listen: false).messageCache.getByContentHash(qMessage.getMetadata().contenthash);
var totalMessages = Provider.of<ContactInfoState>(context, listen: false).totalMessages; if (messageInfo != null) {
// we have to reverse here because the list itself is reversed... var index = Provider.of<ContactInfoState>(context, listen: false).messageCache.findIndex(messageInfo.metadata.messageID);
Provider.of<ContactInfoState>(context).messageScrollController.scrollTo(index: totalMessages - index!, duration: Duration(milliseconds: 100)); if (index != null) {
Provider.of<ContactInfoState>(context, listen: false).messageScrollController.scrollTo(index: index, duration: Duration(milliseconds: 100));
}
}
}, },
child: Container( child: Container(
margin: EdgeInsets.all(5), margin: EdgeInsets.all(5),
@ -111,7 +114,6 @@ class QuotedMessageBubbleState extends State<QuotedMessageBubble> {
)) ))
])))); ]))));
} catch (e) { } catch (e) {
print(e);
return MalformedBubble(); return MalformedBubble();
} }
} else { } else {