getLastMessage method
Fetches the custom lastMsg field for a specific room by its ID.
Implementation
Future<String?> getLastMessage(String roomId) async {
try {
final roomDoc = await getFirebaseFirestore()
.collection(config.roomsCollectionName)
.doc(roomId)
.get();
if (roomDoc.exists) {
// Return the `lastMsg` field if it exists
return roomDoc.data()?['lastMsg'] as String?;
} else {
// Room document does not exist
return null;
}
} catch (e) {
if (kDebugMode) {
print('Error fetching last message: $e');
}
return null;
}
}