User is not being recognized #144
-
I am trying to build a simple one-screen chat application (like a group where everyone can send and read messages). The backend is connected with firebase. I am using your chat library because it has very good features. I can send and receive other messages but the problem is the message is not being recognized, for some users, the message they sent appears perfectly on the right side and for some users, the messages are displayed on the left (message they sent). The implementation is very simple. I am providing a Firebase Auth generated unique ID to the author of the chat. Here is my implementation of UI body: StreamBuilder<QuerySnapshot<types.TextMessage>>(
stream: context.read<MessagesService>().getAllMessages(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const LoadingScreenWithOutScaffold();
}
if (snapshot.connectionState == ConnectionState.active) {
if (snapshot.hasData && snapshot.data != null) {
final data = snapshot.data?.docs;
types.TextMessage? message;
final List<types.Message> messagesList =
data == null || data.isEmpty
? []
: data.map((e) {
message = e.data();
return types.TextMessage(
id: message!.id,
createdAt: message!.createdAt,
text: message!.text,
author: message!.author,
);
}).toList();
print('USER ID == ${message?.author.id}');
return chat.Chat(
// onBackgroundTap: () {
// print('onBackgroundTap');
// },
theme: const chat.DefaultChatTheme(
backgroundColor: cPrimaryColor,
inputBackgroundColor: Color(0xFF104C85), // Dark blue
primaryColor: Color(0xFF104C85),
dateDividerTextStyle: TextStyle(
color: cWhite,
fontWeight: FontWeight.bold,
),
emptyChatPlaceholderTextStyle: TextStyle(
color: cWhite,
fontWeight: FontWeight.bold,
),
),
showUserNames: true,
timeFormat: DateFormat('hh:mm a'),
messages: messagesList,
onSendPressed: context.read<MessagesService>().sendMessage,
user: types.User(id: message?.author.id ?? ''),
);
}
} Getting messages Stream<QuerySnapshot<types.TextMessage>> getAllMessages() {
return databaseService
.messages()
.orderBy('createdAt', descending: true)
.snapshots();
} Sending a Message Future<DocumentReference<types.Message>> sendMessage(
types.PartialText message) async {
final user = databaseService.user;
final now = DateTime.now().millisecondsSinceEpoch;
final _message = types.TextMessage(
id: const Uuid().v4(),
createdAt: now,
text: message.text,
author: types.User(
id: user.uid,
firstName: user.displayName,
createdAt: user.metadata.creationTime?.millisecondsSinceEpoch,
),
);
return databaseService.messages().add(_message);
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I found the issue. I was providing user id from the message coming from the database rather than providing it from the phone memory |
Beta Was this translation helpful? Give feedback.
I found the issue. I was providing user id from the message coming from the database rather than providing it from the phone memory