我正在使用firebase功能通过云消息传递创建通知.但我总是得到这个错误:
Function execution took 60006 ms, finished with status: 'timeout'
Run Code Online (Sandbox Code Playgroud)
但通知有效.
这是我在index.js中使用的代码:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.SendNotification = functions.https.onRequest((req, res) => {
var payload = {
notification: {
title: "this is a test",
body: req.rawBody.toString('utf8')
}
}
return admin.messaging().sendToTopic("all", payload);
});
Run Code Online (Sandbox Code Playgroud)
我必须实施回复吗?什么时候,我该怎么做?
J3nsis
javascript node.js firebase google-cloud-functions firebase-cloud-messaging
我正在使用 Flutter 和 Firestore 插件开发一个群聊应用程序。从数据库中获取数据并将快照转换为消息列表完全正常。但是现在我想将数据库中的 uid 转换为用户名(uid 及其用户名保存在 db 中)。这是我的代码:
final CollectionReference messagesCollection =
Firestore.instance.collection('messages');
final CollectionReference usersCollection =
Firestore.instance.collection('users');
Future<String> getUsernameByUID(String _uid) async {
String username =
await usersCollection.document(uid).get().then((querySnapshot) {
return (querySnapshot.data["username"]);
});
return username;
}
List<Message> _messagesFromSnapshot(QuerySnapshot snapshot){
return snapshot.documents.map((doc) {
String username = await getUsernameByUID(doc.data["uid"]);
return Message(
text: doc.data["text"] ?? "",
username: username ?? "",
time: doc.data["time"] ?? "",
);
}).toList();
}
Stream<List<Message>> get messages {
return messagesCollection
.orderBy("time")
.snapshots()
.map(_messagesFromSnapshot);
}
Run Code Online (Sandbox Code Playgroud)
问题出在这一行,因为我无法在 map() 内运行此异步代码。
String username …Run Code Online (Sandbox Code Playgroud)