Meteor:如何让我的应用识别来自其​​他用户的其他消息

时间:2016-02-15 17:23:22

标签: meteor chat messaging

我创建了一个Messenger应用程序。当用户登录时,他们可以选择与谁聊天。但是,当他们开始聊天时。它只识别登录的用户而不是其他聊天者。这是我的意思的屏幕截图。我是来自firefox的用户和来自chrome的另一个用户。任何例子都会很棒,谢谢。我是新手:)

Here is a screenshot.

这是我的模板

<template name="chat_message">
    <div class = "container">
        <div class = "row">
            <img src="/{{avatar}}" class="avatar_img">
            {{getUsername _id}} said: {{text}} 
        </div>
    </div>  
    <br>
</template>

我的助手

Template.chat_message.helpers ({
    getUsername:function(userId){
      user = Meteor.users.findOne({_id:userId});
      return Meteor.user() && Meteor.user().profile.username;
    },
    avatar:function(userId){
      user = Meteor.users.findOne({_id:userId});
      return Meteor.user() && Meteor.user().profile.avatar;
    } 
  });

服务器

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,
      });
    },

0 个答案:

没有答案
相关问题