Meteor:如何让我的应用程序识别来自其他用户的其他消息
我已经创建了一个messenger应用程序。当用户登录时,他们可以选择与谁聊天。然而,当他们开始聊天时。它只识别已登录的用户,而不识别其他聊天者。这是我的意思的截图。我从firefox和chrome分别以用户身份登录。任何例子都很好,谢谢。我对这一点很陌生:) 这是我的模板Meteor:如何让我的应用程序识别来自其他用户的其他消息,meteor,chat,messaging,Meteor,Chat,Messaging,我已经创建了一个messenger应用程序。当用户登录时,他们可以选择与谁聊天。然而,当他们开始聊天时。它只识别已登录的用户,而不识别其他聊天者。这是我的意思的截图。我从firefox和chrome分别以用户身份登录。任何例子都很好,谢谢。我对这一点很陌生:) 这是我的模板 <template name="chat_message"> <div class = "container"> <div class = "row">
<template name="chat_message">
<div class = "container">
<div class = "row">
<img src="/{{avatar}}" class="avatar_img">
{{getUsername _id}} said: {{text}}
</div>
</div>
<br>
</template>
服务器
Meteor.publish("chats", function () {
return Chats.find();
});
Meteor.publish("messages", function () {
return Chats.find();
});
Meteor.publish("userStatus", function() {
return Meteor.users.find({ "status.online": true });
});
Meteor.publish("userData", function(){
return Meteor.users.find({_id: this.userId});
});
Meteor.publish("users", function(){
return Meteor.users.find({ "status.online": true })
});
Chats.allow({
insert: function () { return true; },
update: function () { return true; },
remove: function () { return true; }
});
Meteor.methods({
sendMessage: function (chat) {
Chats.insert({
chat: chat,
createdAt: new Date(),
username: Meteor.user().profile.username,
avatar: Meteor.user().profile.avatar,
});
},
默认情况下,Meteor仅将登录用户的数据(从Meteor.user collection)发布到客户端。这意味着您无法从客户端访问其他用户的数据,除非您显式发布它们。这就是我发布的内容。我应该添加其他内容吗?添加了上面的服务器端。是的,您的发布是正确的。确保您订阅了正确的出版物。更多信息请访问。另外,
return Meteor.user()&&Meteor.user().profile.username将始终返回登录用户的数据。改为使用Meteor.users.find()
替换为Meteor.users.find()为我提供了一个损坏的图像和[object]作为用户名。不知道为什么。
Meteor.publish("chats", function () {
return Chats.find();
});
Meteor.publish("messages", function () {
return Chats.find();
});
Meteor.publish("userStatus", function() {
return Meteor.users.find({ "status.online": true });
});
Meteor.publish("userData", function(){
return Meteor.users.find({_id: this.userId});
});
Meteor.publish("users", function(){
return Meteor.users.find({ "status.online": true })
});
Chats.allow({
insert: function () { return true; },
update: function () { return true; },
remove: function () { return true; }
});
Meteor.methods({
sendMessage: function (chat) {
Chats.insert({
chat: chat,
createdAt: new Date(),
username: Meteor.user().profile.username,
avatar: Meteor.user().profile.avatar,
});
},