Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

room.lastMessages is Always null #25

Closed
mashegoindustries opened this issue Jul 23, 2021 · 15 comments
Closed

room.lastMessages is Always null #25

mashegoindustries opened this issue Jul 23, 2021 · 15 comments
Labels

Comments

@mashegoindustries
Copy link

mashegoindustries commented Jul 23, 2021

I am streaming rooms using code below
FirebaseChatCore.instance.rooms(orderByUpdatedAt: true)

However it looks like lastMessages is always null
room.lastMessages

I am 100 percent sure that I have last messages on the rooms collection (Which is updated by cloud function)

@mashegoindustries mashegoindustries added the feature New feature or request label Jul 23, 2021
@markzakharyan
Copy link
Contributor

i had the same issue, it could be that you didnt create a firestore index
image

@demchenkoalex demchenkoalex added question and removed feature New feature or request labels Jul 25, 2021
@demchenkoalex
Copy link
Member

Are you sure room at all is not empty? You need an index as described in the documentation comment for the orderByUpdatedAt or in the comment above. If you have it

I am 100 percent sure that I have last messages on the rooms collection (Which is updated by cloud function)

So you can see lastMessages inside the console but not in the dart code?

@mashegoindustries
Copy link
Author

I did create an index. Hence the rooms are showing nicely and the recent active room always appear at the top... Which is awesome.

I can see however lastMessages is always null NOT empty

@mashegoindustries
Copy link
Author


Screenshot 2021-07-25 at 13 29 53

@demchenkoalex
Copy link
Member

@mashegoindustries I understand, but is it null in the console? Why do you think this is a problem in the library and not in the cloud function which updates it?

@mashegoindustries
Copy link
Author

Screenshot 2021-07-25 at 17 04 06

@mashegoindustries
Copy link
Author

mashegoindustries commented Jul 25, 2021

From console, it looks like Cloud functions has successfully updated last message.

However from FirebaseChatCore dart class, I am not seeing any reference to lastMessages array.

I think data exist in firestore, we are just not referencing the property lastMessages.

I could be wrong

@demchenkoalex
Copy link
Member

Are you saying you don't see lastMessages at all? Update to the latest version

@mashegoindustries
Copy link
Author

mashegoindustries commented Aug 19, 2021

@demchenkoalex I started from scratch, followed the instructions , created firestore index. Using latest version of the plugins.
However I am still not getting any last messages.

Isn't the attached screenshot not the issue? lastMessages is never set

Something like LINE 33 and LINE 68 is absent from the plugin itself

Screenshot 2021-08-19 at 03 08 36

@demchenkoalex
Copy link
Member

demchenkoalex commented Aug 21, 2021

LOL. How embarrassing :D sorry about that. You could have also done a PR with that so it would be released sooner. Will do now anyway.

UPD: Dart can't manage dynamic and Map<String, dynamic>, apparently it is too hard. Can't create lastMessages from doc.data(). Will need more time to figure that out.

@eopeter
Copy link

eopeter commented Aug 22, 2021

I need this fix too. Running into error
flutter type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type....

@eopeter
Copy link

eopeter commented Aug 22, 2021

I tried the highlighted lines in the screenshot above with

final lastMessages = doc.data()?['lastMessages'] as List<dynamic>?;

and then while creating the room, I did

lastMessages: lastMessages != null ? lastMessages.map((e) => types.Message.fromJson(e)).toList() : <types.Message>[],

But issue is the lastMessage only has authorId and the toJson is failing because author property is null and it expected a types.User map

@eopeter
Copy link

eopeter commented Aug 22, 2021

resolved author by setting it in cloud function for lastMessages but now it createdAt on lasts message is also failing because it expects an int and the value is DateTime. We may need to write a parser if one does not already exists.

image

@demchenkoalex
Copy link
Member

demchenkoalex commented Aug 22, 2021

That's correct. My thought is to create a json from the document data, replace fields like DateTime etc to match the underlying data, and the pass it to the fromJson function, after I'll replace that with some package for JSON serialisation, because chat_ui became too big to manually parse things + this dynamic issue is driving me mad, hopefully some packages work better with whatever values are passed inside, when we know they are correct.

@demchenkoalex
Copy link
Member

Fixed in v1.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants