firebase - 是否有任何关于开发用户聊天消息屏幕的教程/链接,类似于 AirBnB 或 Instagram 等应用程序?
问题描述
我创建了一个 firebase 帐户并在下面创建了 Firebase 消息类来发送消息,但我不确定如何将消息发送给不同的用户。
小姐 FireMessage {
constructor() {
this.init()
this.checkAuth()
}
init = () => {
if (!firebase.apps.length && firebaseConfig.apps.length === 0) {
firebase.initializeApp({
apiKey: "AIzaSyCjWwL5rs6n-lTlqAkaEh5eK0yXo8",
authDomain: "unihome-36a8.firebaseapp.com",
databaseURL: "https://u36a8.firebaseio.com",
projectId: "u36a8",
storageBucket: "u36a8.appspot.com",
messagingSenderId: "89818921",
appId: "1:898189283761:web:9e09a6566fcb0629dfed90",
measurementId: "G-VYF6PH0MWC"
});
}
};
checkAuth = () => {
firebase.auth().onAuthStateChanged(user => {
if(!user) {
firebase.auth().signInAnonymously();
}
});
};
send = messages => {
messages.forEach(item => {
const message = {
text: item.text,
timestamp: firebase.database.ServerValue.TIMESTAMP,
user: item.user
};
this.db.push(message)
});
};
parse = message => {
const { user, text, timestamp } = message.val();
const { key: _id } = message;
const createdAt = new Date(timestamp);
return {
_id,
createdAt,
text,
user
};
};
get = callback => {
this.db.on("child_added", snapshot => callback(this.parse(snapshot)));
};
off() {
this.db.off();
}
get db() {
return firebase.database().ref("messages");
}
get uid() {
return (firebase.auth().currentUser || {}).uid;
}
}
我在这里错过了什么吗?是否将用于向 firebase 中的不同用户发送消息的 uid。我对此很陌生,不知道该怎么做。谢谢。
解决方案
推荐阅读
- payara - 以非管理员用户身份部署或取消部署应用程序
- linkedin - LinkedIn V2 公共 API 端点
- ios - 如何解决mac上flutter中的“error running pod install”?
- mysql - MySQL 帮助优化这一点 - 在 24 小时内计算所有内容
- html - Bootstrap 顶部导航栏在滚动时消失
- sql - 在 oracle (CTE) 中将时间拆分为小时间隔
- python - 基于字符串创建新列
- android - android studio启动期间同步失败
- javascript - 投注脚本改进 - 随机投注
- html - 您将如何使用 align-items:stretch 处理这些嵌套的 Flexbox?