Giter VIP home page Giter VIP logo

socialize-friendships's Introduction

Friendships

Provides social network style Friend Requests and Friendships.

This is a Meteor package with part of it's code published as a companion NPM package made to work with clients other than Meteor. For example your server is Meteor, but you want to build a React Native app for the client. This allows you to share code between your Meteor server and other clients to give you a competitive advantage when bringing your mobile and web application to market.

Supporting The Project

Finding the time to maintain FOSS projects can be quite difficult. I am myself responsible for over 30 personal projects across 2 platforms, as well as Multiple others maintained by the Meteor Community Packages organization. Therfore, if you appreciate my work, I ask that you either sponsor my work through GitHub, or donate via Paypal or Patreon. Every dollar helps give cause for spending my free time fielding issues, feature requests, pull requests and releasing updates. Info can be found in the "Sponsor this project" section of the GitHub Repo

Installation

This package relies on the npm package simpl-schema so when using with Meteor, you will need to make sure it is installed as well.

meteor npm install --save simpl-schema
meteor add socialize:messaging

NPM Installation

When using this package with React Native, the dependency tree ensures that simpl-schema is loaded so there's no need to install it as when using within Meteor.

npm install --save @socialize/user-friendships

Usage Outside Meteor

The client side parts of this package are published to NPM as @socialize/cloudinary for use in front ends outside of Meteor.

When using the npm package you'll need to connect to a server, which hosts the server side Meteor code for your app, using Meteor.connect as per the @socialize/react-native-meteor usage example documentation.

Meteor.connect('ws://192.168.X.X:3000/websocket');

React Native

When using this package with React Native there is some minor setup required by the @socialize/react-native-meteor package. See @socialize/react-native-meteor react-native for necessary instructions.

Basic Usage

When using this package with React Native you will need to import the package to cause the user class to be properly extended. This way new instances of the User class returned from Meteor.users find and findOne methods as well as Meteor.user() will have this packages methods available on them.

import '@socialize/friendships';
Meteor.users.findOne({username:'copleykj'}).requestFriendship();

Meteor.users.findOne({username:'storytellercz'}).acceptFriendshipRequest();

Meteor.user().requests().fetch(); // fetch all the requests from other users
Meteor.user().pendingRequests().fetch() // fetch all requests to other users

For a more in depth explanation of how to use this package see API.md

Requests

This package implements the socialize:requestable package to allow friendship requests between users

Requests are created by calling user.requestFriendship where user is an instance of the User class. The request will be created as a request from the currently logged in user to the user represented by user.

Other methods for retaining information about requests or interacting with requests pertaining to the current user are also available on the User class and are detailed in the User Extensions section of API.md.

Blocking

This package also implements blocking of other users through the socialize:user-blocking package and will not allow requests from blocked users. Also if a user is blocked and the user is a friend at the time of blocking, the friendship will be severed as well. For more information about the user-blocking API, refer to it's package documentation.

Scalability - Redis Oplog

This package implements cultofcoders:redis-oplog's namespaces to provide reactive scalability as an alternative to Meteor's livedata. Use of redis-oplog is not required and will not engage until you install the cultofcoders:redis-oplog package and configure it.

socialize-friendships's People

Contributors

copleykj avatar dependabot[bot] avatar storytellercz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

socialize-friendships's Issues

Request object state

Hello,

I feel like there has to be an active / inactive attribute for the request object.

When I accept a request I do not want to remove it because that just allows me to send a request again.
But once I am friends I also do not want to show that request anymore.

Regards,
Joe

Problems displaying requests in React

Currently im just testing this package with sending a friendrequest like this:
askFriend(email){ var user = Accounts.findUserByEmail(email); user.requestFriendship(); }

and displaying the number of requests like this:
console.log('this.user: ', Meteor.user().numRequests());
But I am just getting up 0 whatever I do.

Is there a way to "sort" the users' friends by a field on the profile

Hi, I'm using this amazing package like this:

{{#each usuario.friends}}
        {{#ionItem class="item-checkbox checkbox-amigos"}}
          <label class="checkbox">
            <input type="checkbox" value="{{user._id}}" name="amigos"/>
          </label>
          {{user.profile.nombre}} {{user.profile.apellidos}} ({{user.emails.[0].address}})
        {{/ionItem}}
      {{/each}}
usuario: function(){
    return Meteor.user();
  },

but I would like to know if there is a way to sort the order on which this users get displayed, maybe by their first or last name, thanks in advance!

Examples on how to use socialize-friendships

Thanks for the package. I am trying to understand how to use the functionality and wondering if you could provide some direction.

Could you please provide some examples on how to use e.g. how to send a friend request, how to check if a user is a friend, etc? Something on the lines of Azeirah/meteor-friends but with sample code?

Please fix documentation error for Instance Methods

Under "Instance Methods", please update the following from {{user.username}} to {{requester.username}} . Will save people a bunch of time looking for a bug that is not really there. :-)

{{user.username}} would like to be friends

should be

{{requester.username}} would like to be friends

Publication of friends

When subscribing to the friends publication with Meteor.subscribe('friends'); and trying to access the friends of a user by calling Meteor.user().friends().fetch() in a browser console I was getting an empty array result - despite there being a friendship existing for the user in the friends collection.
Looking into the publication (friend-model/server/publication.js) it uses SimplePublication and the selector has document properties that match the schema of the friends collection but the options property is given a value which is set here: options.fields = {username:1, createdAt:1, "profile.online":1, "profile.tagline":1, "profile.photo":1};. My understanding of mongo is that this is to force the result to return only those properties (fields) in the result, but they look like properties of a user document rather than friend document.
When removing that line, the friend publication works and the aforementioned fetch of user friends works as expected - I don't fully understand the simple publication package yet but wondered if this is a line that shouldn't be there or if I'm doing something else wrong here?

Requesting friendship after denying request

Not sure how you feel about this one but I was thinking about the following scenario:

User Alice requests Bob as a friend.
Bob denies the request.

My understanding at this point is that Alice can't make another request until after restrictRequestDays days has expired (30 by default).
However if Bob decides within the 30 days (maybe even the next day) that he does want to be friends with Alice, he can't make a request to her because there is a restriction in place in the RequestsCollection insert function which ensures there aren't any existing requests that are denied or within the restrictRequestDays period in either direction.
So my thinking is, that Bob should be able to request Alice as a friend, having already recently denied her..

I've done a quick test by removing the requester.hasRequestFrom(user) check in the insert and this seems to work, so the line now looks like this:

var pendingRequests = user.hasRequestFrom(requester);

What do you think? I'm wondering if there are scenarios where denying a user's friendship request should then not allow you to make a friend request back to them for a period but figured you would have thought of some when developing this bit..

I was also wondering, when a friend request is accepted, whether the requests should be removed in both directions from the RequestsCollection? Currently it looks like it's only one way:

RequestsCollection.remove({userId:document.userId, requesterId:document.friendId});

Accept friendship

  1. User A requests friendship with User B
  2. User B accepts with "this.acceptFriendshipRequest();" where context is User A
  3. Two documents are added to Friends collection (see image below)
    image
  4. User B will find User A among his friends, but User A will not find User B among his. As you can see in the second document, userId and friendId are the same.

TypeError: user is null meteor.js:930:11 .hasRequestFrom@http://localhost:3000/packages Socialize friendship meteor

image

some time it gives in chrome also, but it always gives in mozilla whenever i refresh.

whenever i refresh browser, it gives an error hasRequestFrom ._id is null.
Exception from Tracker recompute function: meteor.js:930:11
Error: No such function: hasRequestFrom

Exception from Tracker recompute function: meteor.js:930:11
TypeError: user is null meteor.js:930:11
.isFriendsWith@http://localhost:3000/packages

Exception from Tracker recompute function: meteor.js:930:11
TypeError: user is null meteor.js:930:11
.hasRequestFrom@http://localhost:3000/packages

Access denied when trying to send a requestFriendship()

Hi, I am trying to send a friend request like this:

Meteor.users.findOne({_id:"ACTUAL USER ID"}).requestFriendship()

But I'm getting the error insert failed: Access denied I think this has something to do with the fact that the model 'Request' doesn't has the allow method on the server to add it, as I looked in the package I think you should add it the same way RequestsCollection has it. Or do you have any other suggestion?

request.requester() won't work if I refresh the page.

So I have a problem where I subscribe to the request collection and I am getting all the data I need if I just click on the link etc. But if I am in my friend page and refresh the page with F5 I will get all my requests, then after I map through them it will stop at request.requester(). How can I solve this problem ?

No such function: isFriendsWith

hi,
I was following your socilize youtube tutorial of facebook clone. I forked the repo and copied your code from the youtube video. But I am getting this error. Any advice ?
screen shot 2015-10-14 at 8 39 38 pm

Publications

I know that you have plans to take publications out of the packages. However you should look at publish-composite, with the subscriptions you have, stuff with this is a breeze.

Meteor.publishComposite('friendConversation', function(friendUsername) {
    //check(friendUsername, String);
  return {
    find: function() {
        var user = Meteor.users.findOne(this.userId);
        var friend = Meteor.users.findOne({username: friendUsername});
        return Meteor.conversations.find({"_participants":{$in: [this.userId, friend._id]}});
    },
    children: [
    {
        find: function(convo){
            return convo.messages();
        }
    }
    ]
  }
});

what if: meteor remove insecure autopublish

When I remove the insecure and autopublish packages in Meteor 1.2.1 I see at most one (the current logged in) user with Meteor.users.find().fetch() in de browser' developer console .

What would need to be done to have socialize:friendships work safely without these two packages that are just for prototyping?

Wishlist

1- privacy for friend list <everyone, friends, nobody>

denied requests are still showing up in subscription

Meteor.publish('friendRequests', function(options){
    if(!this.userId){
        return this.ready();
    }

    options = options || {};

    check(options, publicationOptionsSchema);

    Meteor.publishWithRelations({
        handle: this,
        collection: Meteor.requests,
        filter: {userId:this.userId, denied:{$exists:false}, ignored:{$exists:false}},// Shouldn't this be deniedAt?
        options:options,
        mappings: [{
            key: 'requesterId',
            collection: Meteor.users,
            options:{fields:{username:true, avatarId:true}}
        }]
    });

});

In the publication, the filter is applied with denied: { $exists: false } but the schema states that it is supposed to be deniedAt: { $exists: false }.
This causes the denied requests to still be published to the client.
Shouldn't it publish only the pending ones? This is also the case in the user extensions and by proxy, the socialize.friendRequests publication.

Iron-router to Flow-router

Thanks @copleykj for all your hard work. I am wondering will it be possible for all the sociallize package be updated to Flow-router? Iron-router seems to not be continuous development and maintenance as well as flow-router!

Error when installing on socailize on my Meteor project

Hi, I'm getting this error when I add the socialize package to my Meteor project, any idea how can I solve it? Thanks in advance!

PD: Great update on the readme, and amazing video explaining how to use this package!

W20150906-18:44:40.366(-5)? (STDERR) /Users/jeronimocosio/.meteor/packages/meteor-tool/.1.1.4.mdycm0++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245
W20150906-18:44:40.367(-5)? (STDERR)                        throw(ex);
W20150906-18:44:40.367(-5)? (STDERR)                              ^
W20150906-18:44:40.367(-5)? (STDERR) Error: A method named 'getServerTime' is already defined
W20150906-18:44:40.367(-5)? (STDERR)     at packages/ddp/livedata_server.js:1461:1
W20150906-18:44:40.367(-5)? (STDERR)     at Function._.each._.forEach (packages/underscore/underscore.js:113:1)
W20150906-18:44:40.367(-5)? (STDERR)     at [object Object]._.extend.methods (packages/ddp/livedata_server.js:1459:1)
W20150906-18:44:40.367(-5)? (STDERR)     at Object.Meteor.methods (packages/meteorhacks:kadira/lib/hijack/wrap_session.js:157:1)
W20150906-18:44:40.367(-5)? (STDERR)     at Package (packages/socialize:server-time/server/server-time.js:1:1)
W20150906-18:44:40.367(-5)? (STDERR)     at /Users/jeronimocosio/vynomvp/vynomvp/.meteor/local/build/programs/server/packages/socialize_server-time.js:57:4
W20150906-18:44:40.367(-5)? (STDERR)     at /Users/jeronimocosio/vynomvp/vynomvp/.meteor/local/build/programs/server/packages/socialize_server-time.js:66:3
W20150906-18:44:40.368(-5)? (STDERR)     at /Users/jeronimocosio/vynomvp/vynomvp/.meteor/local/build/programs/server/boot.js:222:10
W20150906-18:44:40.368(-5)? (STDERR)     at Array.forEach (native)
W20150906-18:44:40.368(-5)? (STDERR)     at Function._.each._.forEach (/Users/jeronimocosio/.meteor/packages/meteor-tool/.1.1.4.mdycm0++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)

I think there's a little error on pendingRequests method

The documentation says that the pendingRequests is 'a cursor of requests that the user has sent but have not been approved, denied or ignored.' but if you look at the actual method, just the requests that were not denied or ignored are the ones that get displayed.

pendingRequests: function (limit, skip) {
        var options = {limit:limit, skip:skip};
        return RequestsCollection.find({requesterId:this._id, denied:{$exists:false}, ignored:{$exists:false}}, options);
    }, 

Publish and Subscribe to Friends of the user whose profile page was visited by the logged In user

When I subscribe to "friends" it returns the friends of the loggedIn User (say cvsakpal). How would I list the friends of a particular user say "/users/copleykj". What would the publish and the subscribe function look like?
With the help of Publications WIki...
I am able to do this in the userProfile template

{{#each currentUser.friendsAsUsers}}
        <p> {{username}} </p>
{{/each}}

while I wish to do this...

{{#each user.friendsAsUsers}}
        <p> {{username}} </p>
{{/each}}

(where 'user' is the instance of the user whose profile page is currently visited by the logged in user)

While I've seen this work in the example video and the facebook clone video... but I suspect those videos had autopublish enabled... Or Am I doing something wrong??? Please help...

insert a new "seen:false" field in the request Schema

Hi,
I am trying to insert a new "seen:false" field in the request Schema. I know there are ways to locally edit packages , I am not after that info. What I am asking is whether adding a seen:false for notification and and using a click event to set it to seen:true is proper way to achieve the notification ? I only need to feed a cursor.count() to a template.

Currently I am trying like this
screen shot 2016-02-13 at 11 39 43 am

Help making requests on the server

Hi, so I want to use this package on my app, but for users to request friendship I don't want to publish all my users to the client, so I'm trying to make the request on the server, the think is that when I do it, a user can make many times the same request, something that isn't possible using the client, what could be wrong with my approach, here is what I'm trying to do:

somewhere-in-client.js

Meteor.call("buscarUsuario", emailUsuario, celularUsuario, function(error, result){
           if(error){
             swal({
               title: "Error",
               text: error.reason,
               type: "info",
               timer: 3000,
               showConfirmButton: false
            });
           }
           if(result){
             console.log('Este es el resultado');
             console.log(result);
           }
         });

somewhere-in-server.js

Meteor.methods({
  buscarUsuario: function (email,celular) {
    if(celular || email){
      var usuarioAmigo = Meteor.users.findOne(
        {$or:
          [
            {"emails.address": email},
            {"profile.celular": celular}
          ]
        }
      );
      if(usuarioAmigo){
        usuarioAmigo.requestFriendship();
        return usuarioAmigo;
      }else{
        throw new Meteor.Error("buscar-usuario-no-existe", "El usuario que estás buscando no existe.");
      }
    }else{
      throw new Meteor.Error("buscar-usuario-sin-info", "Esta información está incorrecta.");
    }
  }
});

I also tried returning the friend through the same method, but when I tried running

if(result){
             result.requestFriendship
           }

I get an error, so I hope you can help me out with this, thanks in advance!

Running request.deny() throws error

After running request.deny() in Firefox 40.0.3 on Ubuntu 14.04 LTS I got the following error

16:35:30.239 update failed: getErrorObject@http://localhost:3000/packages/aldeed_collection2.js?fdc7f0975dd1b3446ea4afd5f820cb1242a521af:409:15
doValidate@http://localhost:3000/packages/aldeed_collection2.js?fdc7f0975dd1b3446ea4afd5f820cb1242a521af:392:13
Mongo.Collection.prototype[methodName]@http://localhost:3000/packages/aldeed_collection2.js?fdc7f0975dd1b3446ea4afd5f820cb1242a521af:194:20
@http://localhost:3000/packages/matb33_collection-hooks.js?84a1c8cf4708b40e4c95f8e059ef1a0bdb5f5897:423:20
CollectionHooks.extendCollectionInstance/</collection[method]@http://localhost:3000/packages/matb33_collection-hooks.js?84a1c8cf4708b40e4c95f8e059ef1a0bdb5f5897:143:1
BaseModel.prototype.update@http://localhost:3000/packages/socialize_base-model.js?8938e7c01a5774c0085007917afd232a414f0877:160:9
Request.prototype.deny@http://localhost:3000/packages/socialize_friendships.js?f90f9d4a486a3b0e3941480edfcde71b45e47d88:238:5
["click .reject-friendship"]@http://localhost:3000/client/views/userProfile.coffee.js?be4c7eb6373e16e18433f4da9e2842934fedea38:62:14
Template.prototype.events/eventMap2[k]</</<@http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:3502:18
Template._withTemplateInstanceFunc@http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:3476:12
Template.prototype.events/eventMap2[k]</<@http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:3501:1
attached_eventMaps/</</</<@http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:2543:22
Blaze._withCurrentView@http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:2197:12
attached_eventMaps/</</<@http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:2542:1
HandlerRec/this.delegatedHandler</<@http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:839:14
jQuery.event.dispatch@http://localhost:3000/packages/jquery.js?dd8bac56f8fd3666d433d2285ae01e52597cc51a:4697:15
jQuery.event.add/elemData.handle@http://localhost:3000/packages/jquery.js?dd8bac56f8fd3666d433d2285ae01e52597cc51a:4366:6
1 meteor.js:888:11

Below is the code that was calling the function

'click .reject-friendship': (e, tpl) ->
    user = this.user
    friendRequest = Request.collection.findOne
      userId: Meteor.userId()
      requesterId: user._id
    if friendRequest
      friendRequest.deny()

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.