android pre load unsynced messages

This commit is contained in:
Dan Ballard 2022-04-28 16:19:32 -07:00
parent 0bcfe75a63
commit 0647a2d98d
3 changed files with 14 additions and 6 deletions

View File

@ -101,8 +101,6 @@ class MessageCache extends ChangeNotifier {
// On android reconnect, if backend supplied message count > UI message count, add the differnce to the front of the index
void addFrontIndexGap(int count) {
this._indexUnsynced = count;
// TODO: needed? maybe not? since after totalmessatges and profile will notify
//notifyListeners();
}
int get indexUnsynced => _indexUnsynced;

View File

@ -168,6 +168,16 @@ class _MessageViewState extends State<MessageView> {
Future<bool> _onWillPop() async {
Provider.of<ContactInfoState>(context, listen: false).unreadMessages = 0;
var previouslySelected = Provider.of<AppState>(context, listen: false).selectedConversation;
if (previouslySelected != null) {
Provider
.of<ProfileInfoState>(context, listen: false)
.contactList
.getContact(previouslySelected)!
.unselected();
}
Provider.of<AppState>(context, listen: false).selectedConversation = null;
return true;
}

View File

@ -25,10 +25,10 @@ class _MessageListState extends State<MessageList> {
@override
Widget build(BuildContext outerContext) {
// On Android we can have unsynced messages at the front of the index from when the UI was asleep, if there are some, kick off sync of those first
if (Provider.of<ContactInfoState>(outerContext).messageCache.indexUnsynced != 0) {
var conversationId = Provider.of<AppState>(context, listen: false).selectedConversation!;
MessageCache? cache = Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(conversationId)?.messageCache;
ByIndex(Provider.of<AppState>(context, listen: false).selectedIndex!).loadUnsynced(Provider.of<FlwtchState>(context, listen: false).cwtch, Provider.of<AppState>(context, listen: false).selectedProfile!, conversationId, cache!);
if (Provider.of<ContactInfoState>(context).messageCache.indexUnsynced != 0) {
var conversationId = Provider.of<AppState>(outerContext, listen: false).selectedConversation!;
MessageCache? cache = Provider.of<ProfileInfoState>(outerContext, listen: false).contactList.getContact(conversationId)?.messageCache;
ByIndex(0).loadUnsynced(Provider.of<FlwtchState>(context, listen: false).cwtch, Provider.of<AppState>(outerContext, listen: false).selectedProfile!, conversationId, cache!);
}
var initi = Provider.of<AppState>(outerContext, listen: false).initialScrollIndex;