ChatlyChatCore class
Provides access to Firebase chat data. Singleton, use ChatlyChatCore.instance to aceess methods.
Properties
- config ↔ ChatlyChatCoreConfig
-
Config to set custom names for rooms and users collections. Also
see ChatlyChatCoreConfig.
getter/setter pair
- firebaseUser ↔ User?
-
Current logged in user in Firebase. Does not update automatically.
Use
FirebaseAuth.authStateChangesto listen to the state changes.getter/setter pair - hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
createGroupRoom(
{Role creatorRole = types.Role.admin, String? imageUrl, Map< String, dynamic> ? metadata, required String name, required List<User> users}) → Future<Room> -
Creates a chat group room with
users. Creator is automatically added to the group.nameis required and will be used as a group name. Add an optionalimageUrlthat will be a group avatar andmetadatafor any additional custom data. -
createRoom(
User otherUser, {Map< String, dynamic> ? metadata}) → Future<Room> -
Creates a direct chat for 2 people. Add
metadatafor any additional custom data. -
createUserInFirestore(
User user) → Future< void> -
Creates
types.Userin Firebase to store name and avatar used on rooms list. -
deleteMessage(
String roomId, String messageId) → Future< void> - Removes message document.
-
deleteRoom(
String roomId) → Future< void> - Removes room document.
-
deleteUserFromFirestore(
String userId) → Future< void> -
Removes
types.Userfromuserscollection in Firebase. -
getFirebaseFirestore(
) → FirebaseFirestore -
Gets proper
FirebaseFirestoreinstance. -
getLastMessage(
String roomId) → Future< String?> -
Fetches the custom
lastMsgfield for a specific room by its ID. -
hasUserSeenMessage(
String roomId, String messageId) → Future< bool> - Checks if the user has seen a message.
-
isMessageSeen(
Message message) → bool - Checks if the recipient has seen the message.
-
markMessageAsSeen(
String roomId, String messageId) → Future< void> - Marks a message as seen if not already. Updates Firestore with the user's ID and timestamp.
-
messages(
Room room, {List< Object?> ? endAt, List<Object?> ? endBefore, int? limit, List<Object?> ? startAfter, List<Object?> ? startAt}) → Stream<List< Message> > - Returns a stream of messages from Firebase for a given room.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
room(
String roomId) → Stream< Room> - Returns a stream of changes in a room from Firebase.
-
rooms(
{bool orderByUpdatedAt = false}) → Stream< List< Room> > -
Returns a stream of rooms from Firebase. Only rooms where current
logged in user exist are returned.
orderByUpdatedAtis used in case you want to have last modified rooms on top, there are a couple of things you will need to do though: -
sendMessage(
dynamic partialMessage, String roomId) → void -
Sends a message to the Firestore. Accepts any partial message and a
room ID. If arbitraty data is provided in the
partialMessagedoes nothing. -
setConfig(
ChatlyChatCoreConfig chatlyChatCoreConfig) → void - Sets custom config to change default names for rooms and users collections. Also see ChatlyChatCoreConfig.
-
toString(
) → String -
A string representation of this object.
inherited
-
updateMessage(
Message message, String roomId) → void - Updates a message in the Firestore. Accepts any message and a room ID. Message will probably be taken from the messages stream.
-
updateRoom(
Room room) → void - Updates a room in the Firestore. Accepts any room. Room will probably be taken from the rooms stream.
-
users(
) → Stream< List< User> > - Returns a stream of all users from Firebase.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- instance → ChatlyChatCore
-
Singleton instance.
final