flyerhq / flutter_firebase_chat_core

Actively maintained, community-driven Firebase BaaS for chat applications with an optional chat UI.
https://flyer.chat
Apache License 2.0
261 stars 208 forks source link

Is it possible to edit firebase_chat_core.dart? #96

Closed jeffmayn closed 1 year ago

jeffmayn commented 1 year ago

Is it possible to edit the firebase_chat_core.dart-file? I specifically need to add an extra where-clause to this stream

Stream<List<types.Room>> rooms({bool orderByUpdatedAt = false}) {
    final fu = firebaseUser;

    if (fu == null) return const Stream.empty();

    final collection = orderByUpdatedAt
        ? getFirebaseFirestore()
            .collection(config.roomsCollectionName)
            .where('userIds', arrayContains: fu.uid)
            .orderBy('updatedAt', descending: true)
        : getFirebaseFirestore()
            .collection(config.roomsCollectionName)
            .where('userIds', arrayContains: fu.uid);

    return collection.snapshots().asyncMap(
          (query) => processRoomsQuery(
            fu,
            getFirebaseFirestore(),
            query,
            config.usersCollectionName,
          ),
        );
gwbischof commented 1 year ago

There are a few ways that you can make this change. The best way to do it depends on what you want to do.

Ways to make your change:

  1. Edit the file directly.
  2. Move FirebaseChatCore into your app code, and edit it.
  3. Override the FirebaseChatCore class.
  4. Make a PR into this repo with the fix.
  5. Fork this repo, make the change on your fork, and install it from your fork.

I am pretty new to Flutter and this repo, but if you want we can do a zoom call to figure it out.

gwbischof commented 1 year ago

.../flutter/.pub-cache/hosted/pub.dartlang.org/flutter_firebase_chat_core-1.6.3/lib/src/firebase_chat_core.dart The file is here for me

jeffmayn commented 1 year ago

Hi thanks. I did the 2. suggestion and moved the file into my own code. Works fine with this file, however, tried the same for the User-model at ../flutter/.pub-cache/hosted/pub.dartlang.org/flutter_firebase_chat_core-1.6.3/lib/src/user.dart, it have some generated code referencing part of user.g.dart, and won't work just copying it in. Do you know how to do this file? Would like to add some fields to this model

gwbischof commented 1 year ago

I don't see the file mentioned. I think you are talking about this file, in the flutter_chat_types package: ../flutter/.pub-cache/hosted/pub.dartlang.org/flutter_chat_types-3.5.0/lib/src/user.dart

You have to move the user.g.dart file into your project also. ../flutter/.pub-cache/hosted/pub.dartlang.org/flutter_chat_types-3.5.0/lib/src/user.g.dart

Once you have copied the code in you probably also need to change where the User type gets imported from.

Copy-pasting like this is not a good solution for production software. But might be a good choice in some situations.

jeffmayn commented 1 year ago

Yeah, I can see why it would be a mess. Well, last solution for adding fields to the user is just to add them as a map to the metadata-field. Thanks a lot for your answers:)

demchenkoalex commented 1 year ago

Types come from a separate lib https://github.com/flyerhq/flutter_chat_types because I needed this for UI as well. I tried to add metadata everywhere so arbitrary fields can be added as needed. Regarding original question - this lib is quite small and straightforward, if some clauses are missing in some functions inside the lib itself, fetch code can be written from scratch, using same database name with all needed filters I guess.