Search code examples
meteorpublish-subscribeavatar

Meteor utilities:avatar data


I'd like to use the utilities:avatar package, but I'm having some major reservations.

The docs tell me that I should publish my user data, like this:

Meteor.publish("otherUserData", function() {
var data = Meteor.users.find({
    }, {
        fields : {
            "services.twitter.profile_image_url_https" : true,
            "services.facebook.id" : true,
            "services.google.picture" : true,
            "services.github.username" : true,
            "services.instagram.profile_picture" : true
        }
    });
    return data;

});

If I understand Meteor's publish/subscribe mechanism correctly, this would push these fields for the entire user database to every client! Clearly, this is not a sustainable solution. Equally clearly, however, either I am doing something wrong, or I am understanding something wrong.

Also: This unscalable solution works fine in a browser, but no avatar icons are visible when the app is deployed to a mobile device, for some reason.

Any ideas?


Solution

  • Separate the issue of which fields to publish from which users you want to publish data on.

    Presumably you want to show avatars for other users that the current user is interacting with. You need to decide what query to use in

    Meteor.users.find(query,{fields: {...}});
    

    so that you narrow down the list from all users to just pertinent ones.

    In my app I end up using reywood:publish-composite to publish the users that are related to the current user via an intermediate collection.