diff --git a/lib/models/messagecache.dart b/lib/models/messagecache.dart index b2c348ce..59c83b0c 100644 --- a/lib/models/messagecache.dart +++ b/lib/models/messagecache.dart @@ -118,6 +118,10 @@ class MessageCache extends ChangeNotifier { return cache[id]; } + int findIndex(int id) { + return cacheByIndex.indexWhere((element) => element.messageId == id); + } + 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) { diff --git a/lib/widgets/quotedmessage.dart b/lib/widgets/quotedmessage.dart index 14f9be72..51c157be 100644 --- a/lib/widgets/quotedmessage.dart +++ b/lib/widgets/quotedmessage.dart @@ -87,10 +87,13 @@ class QuotedMessageBubbleState extends State { cursor: SystemMouseCursors.click, child: GestureDetector( onTap: () { - var index = Provider.of(context, listen: false).messageCache.cacheByHash[qMessage.getMetadata().contenthash]; - var totalMessages = Provider.of(context, listen: false).totalMessages; - // we have to reverse here because the list itself is reversed... - Provider.of(context).messageScrollController.scrollTo(index: totalMessages - index!, duration: Duration(milliseconds: 100)); + var messageInfo = Provider.of(context, listen: false).messageCache.getByContentHash(qMessage.getMetadata().contenthash); + if (messageInfo != null) { + var index = Provider.of(context, listen: false).messageCache.findIndex(messageInfo.metadata.messageID); + if (index != null) { + Provider.of(context, listen: false).messageScrollController.scrollTo(index: index, duration: Duration(milliseconds: 100)); + } + } }, child: Container( margin: EdgeInsets.all(5),