Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Bob Dietrich
Friends not added or accepted
September 17, 2011 6:18 PM
Answer

Bob Dietrich

Rank: Regular Member

Posts: 221

Join Date: May 15, 2005

Recent Posts

In one of my portlets I'd like to establish a friend relationship between two users. In addition, I'd like to automatically accept the request so the users don't need to accept the request

Starting with Rich Sezov's excellent book, I added the following code:
1            com.liferay.portlet.social.model.SocialRequest request =
2                SocialRequestLocalServiceUtil.addRequest( userId, 0, User.class.getName(),
3                    userId, SocialRelationConstants.TYPE_BI_COWORKER, StringPool.BLANK, requester);
4            // Confirm this request on behalf of the receiver
5            request.setStatus( SocialRequestConstants.STATUS_CONFIRM);
6            SocialRequestLocalServiceUtil.updateSocialRequest( request);

Unfortunately, although no exceptions are thrown, the users are never marked as friends. What am I doing wrong? Thanks.
Jelmer Kuperus
RE: Friends not added or accepted
September 18, 2011 4:09 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

I believe you need to call

1SocialRelationLocalServiceUtil.addRelation(request.getUserId(), request.getReceiverUserId(), SocialRelationConstants. TYPE_BI_COWORKER);
Bob Dietrich
RE: Friends not added or accepted
September 18, 2011 11:01 AM
Answer

Bob Dietrich

Rank: Regular Member

Posts: 221

Join Date: May 15, 2005

Recent Posts

Thanks for the suggestion. I tried this call and it seems to work when I get a list of friends via:
1            List<User> relations = UserLocalServiceUtil.getSocialUsers( userId, start, end, new UserLastNameComparator(true));

But these friends do not show up in the LR friends portlet. Suggestions?
Jelmer Kuperus
RE: Friends not added or accepted
September 18, 2011 11:16 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

You mean the social networking portlet ?

That portlet will only list relations of type SocialRelationConstants.TYPE_BI_FRIEND

You are establishing a co-worker relationship, not a friend relationship
Bob Dietrich
RE: Friends not added or accepted
September 20, 2011 11:16 PM
Answer

Bob Dietrich

Rank: Regular Member

Posts: 221

Join Date: May 15, 2005

Recent Posts

Yes, the social networking portlet. I was under the impression from Rich's book that the portlet uses TYPE_BI_COWORKER, although perusing the 6.0.6 code I couldn't determine what was actually used (I certainly could have missed it). Anyway, thanks for your help.