diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 127f78f4b..ca58d2d35 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -157,6 +157,7 @@ - removed the old js file IndexedSearch/ColorPicker2.js that hasn't been used in about 3 years. - Fixed #8984: Weather Asset missing hoverhelp + - fixed #4177: You can send your people on your friends list a friends request 7.5.30 - fixed: can't add EMS tickets to badges diff --git a/lib/WebGUI/Friends.pm b/lib/WebGUI/Friends.pm index d28c8100f..2b7d98242 100644 --- a/lib/WebGUI/Friends.pm +++ b/lib/WebGUI/Friends.pm @@ -169,6 +169,37 @@ sub isFriend { #------------------------------------------------------------------- +=head2 isInvited ( userId ) + +Returns a booelean indicating whether the user has already been invited to the friends network. + +=head3 userId + +The userId to check against this user. + +=cut + +sub isInvited { + my $self = shift; + my $session = $self->session; + my $userId = shift; + + my ($isInvited) = $session->db->quickArray(q{ + select + count(*) + from + friendInvitations + where + inviterId = ? + and friendId = ? + }, + [$session->user->userId,$userId]); + + return $isInvited; +} + +#------------------------------------------------------------------- + =head2 new ( session, user ) Constructor. diff --git a/lib/WebGUI/Operation/Friends.pm b/lib/WebGUI/Operation/Friends.pm index 23acfb0cb..b20b68ac4 100644 --- a/lib/WebGUI/Operation/Friends.pm +++ b/lib/WebGUI/Operation/Friends.pm @@ -40,8 +40,24 @@ sub www_addFriend { return $session->privilege->insufficient() unless ($session->user->isRegistered); my $friendId = $session->form->get('userId'); my $protoFriend = WebGUI::User->new($session, $friendId); - + my $i18n = WebGUI::International->new($session, 'Friends'); + + my $friends = WebGUI::Friends->new($session); + if($friends->isFriend($friendId)) { + my $returnToProfile = sprintf($i18n->get('add to friends profile'),$protoFriend->getFirstName); + my $backUrl = $session->url->append($session->url->getRequestedUrl, 'op=viewProfile;uid='.$friendId); + return $session->style->userStyle( + sprintf($i18n->get("error user is already friend"),$backUrl,$returnToProfile) + ); + } + elsif($friends->isInvited($friendId)) { + my $returnToProfile = sprintf($i18n->get('add to friends profile'),$protoFriend->getFirstName); + my $backUrl = $session->url->append($session->url->getRequestedUrl, 'op=viewProfile;uid='.$friendId); + return $session->style->userStyle( + sprintf($i18n->get("error user is already invited"),$backUrl,$returnToProfile) + ); + } # Check for non-existant user id. if ((!$protoFriend->username) || (!$protoFriend->profileField('ableToBeFriend'))) { diff --git a/lib/WebGUI/i18n/English/Friends.pm b/lib/WebGUI/i18n/English/Friends.pm index 1ec74d64b..98a20e808 100644 --- a/lib/WebGUI/i18n/English/Friends.pm +++ b/lib/WebGUI/i18n/English/Friends.pm @@ -295,6 +295,16 @@ Thanks, lastUpdated => 1181493546, }, + 'error user is already friend' => { + message => q|This user is already a member of your friends network

%s

|, + lastUpdated => 1181493546, + }, + + 'error user is already invited' => { + message => q|You have already sent an invitation for this user to join your friends network

%s

|, + lastUpdated => 1181493546, + } + }; 1;