Giter VIP home page Giter VIP logo

Comments (2)

copleykj avatar copleykj commented on June 2, 2024 1

You would just have to rework the publication to take a users _id as one of the parameters and then use it in place of this.userId in the publication.

//Publish friend records with their related user records
Meteor.publish("friendsFor", function (userId, options) {
    if(userId){
        return this.ready();
    }

    options = options || {};

    check(options, publicationOptionsSchema);

    Meteor.publishWithRelations({
        handle: this,
        collection: Meteor.friends,
        filter: {userId:userId, friendId:{$ne:userId}},
        options:options,
        mappings: [{
            key: 'friendId',
            collection: Meteor.users,
            options:{fields:{username:true, status:true}}
        }]
    });
});

from socialize-friendships.

cvsakpal avatar cvsakpal commented on June 2, 2024

Thanks for your reply... This was the final thing I have based on ur reply..
I still haven't understood what this.ready(); does... but returning it seems to be an early exit strategy...

//Publish any user's friend records with their related user records
Meteor.publish("friendsFor", function (username, options) {
    if(!username){
        return this.ready();
    }

    options = options || {};

    check(options, publicationOptionsSchema);

    var user = Meteor.users.findOne({username: username});

    Meteor.publishWithRelations({
        handle: this,
        collection: Meteor.friends,
        filter: {userId:user._id, friendId:{$ne:user._id}},
        options:options,
        mappings: [{
            key: 'friendId',
            collection: Meteor.users,
            options:{fields:{username:true, avatarId:true, status:true}}
        }]
    });
});

Thanks a lot for your prompt reply... I'll close the issue... :)

Also the router method to subscribe... if anyone needs it in the future... (The userProfile Publication I used... since I kept getting undefined methods error)

Router.route('/users/:username', {
    name: 'userProfile',
    template: "userProfile",
    waitOn: function() {
        return [Meteor.subscribe('outgoingFriendRequests'),
               Meteor.subscribe('friendRequests'),
               Meteor.subscribe('userProfile', this.params.username),
               Meteor.subscribe('friendsFor', this.params.username)];
    },
    data: function() {
        return {
            user: Meteor.users.findOne({ username: this.params.username }), 
            requests: Meteor.requests.find({}),
            friends: Meteor.friends.find({})
        };
    },
    action: function() {
        this.render();
    }
});

and I might as well add the template code...

<template name="userProfile">
    <h3>{{user.username}} profile ACCESSED BY {{currentUser.username}}</h3>
    {{#if user.hasRequestFrom currentUser}}
        <button class="btn btn-danger cancel">Cancel Request</button>
    {{else}}
        {{#if currentUser.hasRequestFrom user}}
            <button class="btn btn-success accept">Confirm Request</button>
            <button class="btn btn-danger deny">Deny Request</button>
        {{else}}    
            {{#if user.isFriendsWith currentUser}}
                <button class="btn btn-danger end">Unfriend</button>
            {{else}}
                <button class="btn btn-primary add">Add Friend</button>
            {{/if}}
        {{/if}}
    {{/if}}
    <h4>Friends</h4>
    {{#each user.friendsAsUsers}}
        <p>
        <a href="{{pathFor 'userProfile' username=username}}">
          {{username}}
        </a>
        </p>
    {{else}}
        <p>No friends.</p>
    {{/each}}
</template>

from socialize-friendships.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.