Comments (7)
Not at the moment I think, but we are open for proposals
from flutter_firebase_chat_core.
Hi @markzakharyan!
We can add lastMessages
array to the room type for convenience (we planned to do so anyway for our own backend version) but to make it work with Firebase you will need to write a cloud function which will update that field when new messages come in. Will that work?
from flutter_firebase_chat_core.
Hmmm maybe that could be written in the same firebase function as the one you already have in the docs. Would this work?
import * as functions from 'firebase-functions';
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();
export const changeLastMessage = functions.firestore
.document('rooms/{roomId}/messages/{messageId')
.onWrite((change) => {
const message = change.after.data()
if (message) {
db.doc('rooms/{roomId}').set({
lastMessage: message,
});
} else {
return null
}
})
export const changeMessageStatus = functions.firestore
.document('rooms/{roomId}/messages/{messageId}')
.onWrite((change) => {
const message = change.after.data()
if (message) {
if (['delivered', 'read'].includes(message.status)) {
return null
} else {
return change.after.ref.update({
status: 'delivered',
});
}
} else {
return null
}
})
I'd also be curious about making adding "seen" functionality to it as well.
from flutter_firebase_chat_core.
maybe, I'm not a cloud function expert and this is more "backend" related part. What we did provide in the example is more like an entry point on what can/should be done via cloud functions and then sky is the limit. We for sure can't provide them out of the box, because they are not related to Flutter in any way. Also, all cloud functions are now requiring paid plan and of course usage will be different for different people, another reason why we can't give you everything. What we can do is receive a tested solution from somebody in the community and add it to the docs, as an example implementation.
Regarding the "seen" status - there is a support for that in types and UI (if UI is used), but again somebody who knows backend and/or cloud functions can help out with the possible implementation and we can add whatever is needed (like a timestamp sent when user opens the chat or anything) to the core package.
from flutter_firebase_chat_core.
I made a PR containing firebase functions code adding latestMessage
to firestore.
Here's code that works really well that retrieves the latest message:
Widget latestMessageFormat(String text) {
return Text(text,
style: TextStyle(color: Colors.grey, fontSize: 15, height: 1.1),
maxLines: 2,
overflow: TextOverflow.ellipsis);
}
var latestMessageDisplayText;
Widget _latestMessage(types.Room room) {
return StreamBuilder<DocumentSnapshot>(
stream: FirebaseFirestore.instance
.collection('rooms')
.doc('${room.id}')
.snapshots(),
builder:
(BuildContext context, AsyncSnapshot<DocumentSnapshot> snapshot) {
if (snapshot.hasError) {
return Text('Something went wrong collecting the latest message');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return latestMessageFormat(latestMessageDisplayText == null
? 'Loading...'
: latestMessageDisplayText);
}
Map<String, dynamic> dataMap = snapshot.data!.data() as Map<String, dynamic>; //When in doubt, use a hashmap :D
latestMessageDisplayText = dataMap.containsKey('lastMessage')
? dataMap['lastMessage']['text']
: 'No messages yet';
return latestMessageFormat(latestMessageDisplayText);
});
}
The reason there's latestMessageDisplayText
is to prevent flickering "Loading..." when a message is uploaded.
I'm pretty new to dart/flutter so I'm sure it could be improved but I'm actually pretty proud of it. It works well, so if anyone needs it, here it is to save the hassle.
from flutter_firebase_chat_core.
@demchenkoalex is there a way I can check if the user has seen the latest message? (or be at the bottom of the scroll) to check for their last read message
from flutter_firebase_chat_core.
Everything related to the seen
status we can continue here #9 and regarding the initial issue discussion is in #16. Closing this one.
from flutter_firebase_chat_core.
Related Issues (20)
- testing on a firebase emulator?
- Limit first initial messages then append new messages
- Process for creating group room and allowing others to join unclear. HOT 2
- Add a firebase extension for the rules and cloud functions
- Add option to mixin the chat user to an existing user class HOT 1
- Start new chat messages at the top of the screen? HOT 2
- Set custom location for Firebase Storage so We can setup our own security rules. HOT 2
- How to send SystemMessage? HOT 2
- How to create room for a specific user without using ```FirebaseChatCore.instance.users()``` and ```StreamBuilder()``` HOT 6
- createGroupRoom with specific metadata HOT 1
- [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value. HOT 5
- Rooms list. How is it supposed to look?
- any documentation on how to create the structure the firebase database ? HOT 3
- Where to define App Name HOT 1
- New Message Badge / Notifiication New Unread Message HOT 1
- Debug banner is hiding "+" icon
- Last Message Remove Important Property HOT 1
- v2 release HOT 1
- Firebase Core got a major upgrade to 3.0.0 from 2.x.x, we now have a conflict issue. HOT 3
- CocoaPods's specs repository is too out-of-date to satisfy dependencies. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_firebase_chat_core.