Fix Bugs in Quoted Message Selection found by Fuzzbot

This commit is contained in:
Sarah Jamie Lewis 2022-06-23 11:25:26 -07:00
parent 0aa0d286ef
commit ab77ad80d1
2 changed files with 11 additions and 4 deletions

View File

@ -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) {

View File

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