afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)
afuna ([personal profile] afuna) wrote in [site community profile] changelog2009-04-06 05:58 pm

[dw-free] Re-add contextual popups

[commit: http://hg.dwscoalition.org/dw-free/rev/295ff64f1a59]

http://bugs.dwscoalition.org/show_bug.cgi?id=573

Fix up contextual hover menu for WTF, self-messaging, community membership.

Patch by [personal profile] janinedog.

Files modified:
  • etc/config.pl
  • htdocs/js/contextualhover.js
  • htdocs/tools/endpoints/changerelation.bml
  • htdocs/tools/endpoints/ctxpopup.bml
--------------------------------------------------------------------------------
diff -r a99db500a12f -r 295ff64f1a59 etc/config.pl
--- a/etc/config.pl	Mon Apr 06 17:39:44 2009 +0000
+++ b/etc/config.pl	Mon Apr 06 17:57:46 2009 +0000
@@ -854,6 +854,9 @@
             safe_search_level => 11,
         },
     );
+
+    # enable contextual hover
+    $CTX_POPUP = 1;
 }
 
 1;
diff -r a99db500a12f -r 295ff64f1a59 htdocs/js/contextualhover.js
--- a/htdocs/js/contextualhover.js	Mon Apr 06 17:39:44 2009 +0000
+++ b/htdocs/js/contextualhover.js	Mon Apr 06 17:57:46 2009 +0000
@@ -262,34 +262,53 @@ ContextualPopup.renderPopup = function (
         // relation
         var relation = document.createElement("div");
         if (data.is_comm) {
+            var m_label = "";
+            var w_label = "";
+
             if (data.is_member)
-                relation.innerHTML = "You are a member of " + username;
-            else if (data.is_friend)
-                relation.innerHTML = "You are watching " + username;
+                m_label = "You are a member of " + username;
+
+            if (data.is_watching)
+                w_label = "You have subscribed to " + username;
+
+            if (m_label && w_label)
+                relation.innerHTML = m_label + "<br />" + w_label;
+            else if (m_label || w_label)
+                relation.innerHTML = m_label + w_label;
             else
                 relation.innerHTML = username;
         } else if (data.is_syndicated) {
-            if (data.is_friend)
-                relation.innerHTML = "You are subscribed to " + username;
+            if (data.is_watching)
+                relation.innerHTML = "You have subscribed to " + username;
             else
                 relation.innerHTML = username;
         } else {
             if (data.is_requester) {
                 relation.innerHTML = "This is you";
             } else {
-                var label = username + " ";
+                var t_label = "";
+                var w_label = "";
 
-                if (data.is_friend_of) {
-                    if (data.is_friend)
-                        label += "is your mutual friend";
-                    else
-                        label += "lists you as a friend";
-                } else {
-                    if (data.is_friend)
-                        label += "is your friend";
-                }
+                if (data.is_trusting && data.is_trusted_by)
+                    t_label = username + " and you have mutual access";
+                else if (data.is_trusting)
+                    t_label = "You have granted access to " + username;
+                else if (data.is_trusted_by)
+                    t_label = username + " has granted access to you";
 
-                relation.innerHTML = label;
+                if (data.is_watching && data.is_watched_by)
+                    w_label = username + " and you have mutual subscriptions";
+                else if (data.is_watching)
+                    w_label = "You have subscribed to " + username;
+                else if (data.is_watched_by)
+                    w_label = username + " has subscribed to you";
+
+                if (t_label && w_label)
+                    relation.innerHTML = t_label + "<br />" + w_label;
+                else if (t_label || w_label)
+                    relation.innerHTML = t_label + w_label;
+                else
+                    relation.innerHTML = username;
             }
         }
         DOM.addClassName(relation, "Relation");
@@ -329,7 +348,7 @@ ContextualPopup.renderPopup = function (
 
         // send message
         var message;
-        if (data.is_logged_in && data.is_person && ! data.is_requester && data.url_message) {
+        if (data.is_logged_in && data.is_person && data.url_message) {
             message = document.createElement("span");
 
             var sendmessage = document.createElement("a");
@@ -338,71 +357,118 @@ ContextualPopup.renderPopup = function (
 
             message.appendChild(sendmessage);
             content.appendChild(message);
+
+            if (data.is_requester)
+                content.appendChild(document.createElement("br"));
         }
 
-        // friend
-        var friend;
+        // relationships
+        var trust;
+        var watch;
         if (data.is_logged_in && ! data.is_requester) {
-            friend = document.createElement("span");
+            if (!data.is_trusting) {
+                // add trust link
+                var addTrust = document.createElement("span");
+                var addTrustLink = document.createElement("a");
+                addTrustLink.href = data.url_addtrust;
 
-            if (! data.is_friend) {
-                // add friend link
-                var addFriend = document.createElement("span");
-                var addFriendLink = document.createElement("a");
-                addFriendLink.href = data.url_addfriend;
+                if (data.is_person) {
+                    trust = document.createElement("span");
+                    addTrustLink.innerHTML = "Grant access";
+                }
 
-                if (data.is_comm)
-                    addFriendLink.innerHTML = "Watch community";
-                else if (data.is_syndicated)
-                    addFriendLink.innerHTML = "Subscribe to feed";
-                else
-                    addFriendLink.innerHTML = "Add friend";
-
-                addFriend.appendChild(addFriendLink);
-                DOM.addClassName(addFriend, "AddFriend");
+                addTrust.appendChild(addTrustLink);
+                DOM.addClassName(addTrust, "AddTrust");
 
                 if (!ContextualPopup.disableAJAX) {
-                    DOM.addEventListener(addFriendLink, "click", function (e) {
+                    DOM.addEventListener(addTrustLink, "click", function (e) {
                         Event.prep(e);
                         Event.stop(e);
-                        return ContextualPopup.changeRelation(data, ctxPopupId, "addFriend", e); });
+                        return ContextualPopup.changeRelation(data, ctxPopupId, "addTrust", e); });
                 }
 
-                friend.appendChild(addFriend);
+                if (trust)
+                    trust.appendChild(addTrust);
             } else {
-                // remove friend link (omg!)
-                var removeFriend = document.createElement("span");
-                var removeFriendLink = document.createElement("a");
-                removeFriendLink.href = data.url_addfriend;
+                // remove trust link
+                var removeTrust = document.createElement("span");
+                var removeTrustLink = document.createElement("a");
+                removeTrustLink.href = data.url_addtrust;
 
-                if (data.is_comm)
-                    removeFriendLink.innerHTML = "Stop watching";
-                else if (data.is_syndicated)
-                    removeFriendLink.innerHTML = "Unsubscribe";
-                else
-                    removeFriendLink.innerHTML = "Remove friend";
+                if (data.is_person) {
+                    trust = document.createElement("span");
+                    removeTrustLink.innerHTML = "Remove access";
+                }
 
-                removeFriend.appendChild(removeFriendLink);
-                DOM.addClassName(removeFriend, "RemoveFriend");
+                removeTrust.appendChild(removeTrustLink);
+                DOM.addClassName(removeTrust, "RemoveTrust");
 
                 if (!ContextualPopup.disableAJAX) {
-                    DOM.addEventListener(removeFriendLink, "click", function (e) {
+                    DOM.addEventListener(removeTrustLink, "click", function (e) {
                         Event.stop(e);
-                        return ContextualPopup.changeRelation(data, ctxPopupId, "removeFriend", e); });
+                        return ContextualPopup.changeRelation(data, ctxPopupId, "removeTrust", e); });
                 }
 
-                friend.appendChild(removeFriend);
+                if (trust)
+                    trust.appendChild(removeTrust);
             }
 
-            DOM.addClassName(relation, "FriendStatus");
+            if (!data.is_watching) {
+                // add watch link
+                var addWatch = document.createElement("span");
+                var addWatchLink = document.createElement("a");
+                addWatchLink.href = data.url_addwatch;
+
+                watch = document.createElement("span");
+                addWatchLink.innerHTML = "Subscribe";
+
+                addWatch.appendChild(addWatchLink);
+                DOM.addClassName(addWatch, "AddWatch");
+
+                if (!ContextualPopup.disableAJAX) {
+                    DOM.addEventListener(addWatchLink, "click", function (e) {
+                        Event.prep(e);
+                        Event.stop(e);
+                        return ContextualPopup.changeRelation(data, ctxPopupId, "addWatch", e); });
+                }
+
+                watch.appendChild(addWatch);
+            } else {
+                // remove watch link
+                var removeWatch = document.createElement("span");
+                var removeWatchLink = document.createElement("a");
+                removeWatchLink.href = data.url_addwatch;
+
+                watch = document.createElement("span");
+                removeWatchLink.innerHTML = "Remove subscription";
+
+                removeWatch.appendChild(removeWatchLink);
+                DOM.addClassName(removeWatch, "RemoveWatch");
+
+                if (!ContextualPopup.disableAJAX) {
+                    DOM.addEventListener(removeWatchLink, "click", function (e) {
+                        Event.stop(e);
+                        return ContextualPopup.changeRelation(data, ctxPopupId, "removeWatch", e); });
+                }
+
+                watch.appendChild(removeWatch);
+            }
+
+            DOM.addClassName(relation, "RelationshipStatus");
         }
 
         // add a bar between stuff if we have community actions
-        if ((data.is_logged_in && data.is_comm) || (message && friend))
+        if ((data.is_logged_in && data.is_comm) || (message && (trust || watch)))
             content.appendChild(document.createElement("br"));
 
-        if (friend)
-            content.appendChild(friend);
+        if (trust)
+            content.appendChild(trust);
+
+        if (trust && watch)
+            content.appendChild(document.createElement("br"));
+
+        if (watch)
+            content.appendChild(watch);
 
         if ((data.is_person || data.is_comm) && !data.is_requester && data.can_receive_vgifts) {
             var vgift = document.createElement("span");
@@ -413,7 +479,7 @@ ContextualPopup.renderPopup = function (
 
             vgift.appendChild(sendvgift);
 
-            if (friend)
+            if (trust || watch)
                 content.appendChild(document.createElement("br"));
 
             content.appendChild(vgift);
@@ -549,7 +615,7 @@ ContextualPopup.changeRelation = functio
         if (!data.success) return;
 
         if (ContextualPopup.cachedResults[ctxPopupId + ""]) {
-            var updatedProps = ["is_friend", "is_member", 'is_banned'];
+            var updatedProps = ["is_trusting", "is_watching", "is_member", "is_banned"];
             updatedProps.forEach(function (prop) {
                 ContextualPopup.cachedResults[ctxPopupId + ""][prop] = data[prop];
             });
diff -r a99db500a12f -r 295ff64f1a59 htdocs/tools/endpoints/changerelation.bml
--- a/htdocs/tools/endpoints/changerelation.bml	Mon Apr 06 17:39:44 2009 +0000
+++ b/htdocs/tools/endpoints/changerelation.bml	Mon Apr 06 17:57:46 2009 +0000
@@ -32,98 +32,72 @@
 
     my %ret = ();
 
-    if ($action eq 'addFriend') {
-        my $errmsg = "";
-        return $err->($errmsg)
-            unless $remote->can_add_friends(\$errmsg, {friend => $targetu});
+    if ( $action eq 'addTrust' ) {
+        my $error;
+        return $err->( $error )
+            unless $remote->can_trust( $targetu, errref => \$error );
 
-        $success = $remote->friend_and_watch($targetu);
-    } elsif ($action eq 'removeFriend') {
-        $success = $remote->remove_friend($targetu);
-    } elsif ($action eq 'join') {
-        return $err->("Not a community") unless $targetu->is_comm;
+        $success = $remote->add_edge( $targetu, trust => {} );
+    } elsif ( $action eq 'addWatch' ) {
+        my $error;
+        return $err->( $error )
+            unless $remote->can_watch( $targetu, errref => \$error );
 
-        my $ci = LJ::get_community_row($targetu);
+        $success = $remote->add_edge( $targetu, watch => {} );
+    } elsif ( $action eq 'removeTrust' ) {
+        $success = $remote->remove_edge( $targetu, trust => {} );
+    } elsif ( $action eq 'removeWatch' ) {
+        $success = $remote->remove_edge( $targetu, watch => {} );
+    } elsif ( $action eq 'join' ) {
+        my $error;
+        my $can_join = $remote->can_join( $targetu, errref => \$error ) ? 1 : 0;
+        if ( $can_join ) {
+            $success = LJ::join_community( $remote, $targetu );
+        } else {
+            if ( $error eq LJ::Lang::ml( 'edges.membership.error.targetnotopen' ) && $targetu->is_moderated_membership ) {
+                LJ::comm_join_request( $targetu, $remote );
+                $ret{note} = BML::ml( '/community/join.bml.reqsubmitted.body' );
+            } else {
+                return $err->( $error );
+            }
+        }
+    } elsif ( $action eq 'leave' ) {
+        my $error;
+        return $err->( $error )
+            unless $remote->can_leave( $targetu, errref => \$error );
 
-        my $adult_content;
-        unless ($remote->can_join_adult_comm( comm => $targetu, adultref => \$adult_content )) {
-            my $join_err;
-            if ($adult_content eq "concepts") {
-                $join_err = BML::ml('/community/join.bml.error.ischild', {'comm' => $targetu->ljuser_display});
-            } elsif ($adult_content eq "explicit") {
-                $join_err = BML::ml('/community/join.bml.error.isminor', {'comm' => $targetu->ljuser_display});
-            }
+        # log to userlog if remote is a maintainer
+        $targetu->log_event( 'maintainer_remove', { actiontarget => $remote->id, remote => $remote } )
+            if $remote->can_manage( $targetu );
 
-            return $err->($join_err);
-        }
+        $success = LJ::leave_community( $remote, $targetu );
+    } elsif ( $action eq 'setBan' ) {
+        my $list_of_banned = LJ::load_rel_user($remote, 'B') || [ ];
 
-
-        # get maintainers
-        my $maintainers = LJ::load_rel_user($targetu->{userid}, 'A') || [];
-        my %userhash;
-        LJ::load_userids_multiple([ map { $_, \$userhash{$_} }
-                                    @$maintainers ]);
-        my @maints = map { LJ::ljuser($_) } values %userhash;
-
-        if ($ci->{membership} eq 'closed') {
-            $ret{note} = BML::ml('/community/join.bml.error.closed', { admins => join(', ', @maints) });
-        } elsif ($ci->{membership} ne 'open') {
-            # submit request
-            LJ::comm_join_request($targetu, $remote);
-
-              $ret{note} = BML::ml('/community/join.bml.reqsubmitted.body') .
-                  join(', ', @maints);
-          } else {
-              my $joined = LJ::join_community($remote, $targetu);
-              $ret{note} = LJ::last_error() unless $joined;
-              $success = $joined;
-          }
-    } elsif ($action eq 'leave') {
-        return $err->("Not a community") unless $targetu->is_comm;
-
-        # error if we're a maintainer and there are no others
-        my $maintids = LJ::load_rel_user($targetu->{userid}, 'A');
-        my $ismaint     = grep { $_ == $remote->{userid} } @$maintids;
-        my $othermaints = grep { $_ != $remote->{userid} } @$maintids;
-        if ($ismaint) {
-            return $err->(BML::ml('/community/leave.bml.label.lastmaintainer')) unless $othermaints;
-
-            # log to userlog
-            $targetu->log_event('maintainer_remove', { actiontarget => $remote->id, remote => $remote });
-        }
-
-        $success = LJ::leave_community($remote, $targetu);
-    } elsif ($action eq 'setBan') {
-        my $list_of_banned = LJ::load_rel_user($remote, 'B') || [ ];
-        
         return $err->("Exceeded limit maximum of banned users")
             if @$list_of_banned >= ($LJ::MAX_BANS || 5000);
-        
+
         my $ban_user = LJ::load_user($target);
         $success = $remote->ban_user($ban_user);
         LJ::run_hooks('ban_set', $remote, $ban_user);
 
         #$ret{is_banned} = $remote->is_banned($ban_user) ? 1 : 0;
-        
-    } elsif ($action eq 'setUnban') {    
+    } elsif ( $action eq 'setUnban' ) {
         my $unban_user = LJ::load_user($target);
         $success = $remote->unban_user_multi($unban_user->{userid});
         #$ret{is_banned} = $remote->is_banned($unban_user) ? 1 : 0;
-    
     } else {
         return $err->("Invalid action $action");
     }
 
     sleep 1 if $LJ::IS_DEV_SERVER;
 
-    # we (maybe) just changed the relation. we don't want to return stale
-    # relation status, so force is_friend to use the master
-    local $LJ::_PRAGMA_FORCE_MASTER = 1;
     return JSON::objToJson({
-        success   => $success,
-        is_friend => LJ::is_friend($remote, $targetu),
-        is_member => LJ::is_friend($targetu, $remote),
-        is_banned => $remote->is_banned(LJ::load_user($target)),
+        success     => $success,
+        is_trusting => $remote->trusts( $targetu ),
+        is_watching => $remote->watches( $targetu ),
+        is_member   => $remote->member_of( $targetu ),
+        is_banned   => $remote->has_banned( $targetu ),
         %ret,
     });
 }
diff -r a99db500a12f -r 295ff64f1a59 htdocs/tools/endpoints/ctxpopup.bml
--- a/htdocs/tools/endpoints/ctxpopup.bml	Mon Apr 06 17:39:44 2009 +0000
+++ b/htdocs/tools/endpoints/ctxpopup.bml	Mon Apr 06 17:57:46 2009 +0000
@@ -66,7 +66,8 @@
     # actions to generate auth tokens for
     my @actions = ();
 
-    $ret{url_addfriend} = "$LJ::SITEROOT/manage/circle/add.bml?user=" . $u->{user};
+    $ret{url_addtrust} = "$LJ::SITEROOT/manage/circle/add.bml?user=" . $u->{user} . "&action=access";
+    $ret{url_addwatch} = "$LJ::SITEROOT/manage/circle/add.bml?user=" . $u->{user} . "&action=subscribe";
 
     my $up = $u->userpic;
     if ($up) {
@@ -87,9 +88,11 @@
     }
 
     if ($remote) {
-        $ret{is_friend}    = LJ::is_friend($remote, $u);
-        $ret{is_friend_of} = LJ::is_friend($u, $remote);
-        $ret{is_requester} = LJ::u_equals($remote, $u);
+        $ret{is_trusting}   = $remote->trusts( $u );
+        $ret{is_trusted_by} = $u->trusts( $remote );
+        $ret{is_watching}   = $remote->watches( $u );
+        $ret{is_watched_by} = $u->watches( $remote );
+        $ret{is_requester}  = $remote->equals( $u );
     }
 
     $ret{is_logged_in}  = $remote ? 1 : 0;
@@ -97,14 +100,14 @@
     if ($u->is_comm) {
         $ret{url_joincomm}   = "$LJ::SITEROOT/community/join.bml?comm=" . $u->{user};
         $ret{url_leavecomm}  = "$LJ::SITEROOT/community/leave.bml?comm=" . $u->{user};
-        $ret{is_member} = LJ::is_friend($u, $remote) if $remote;
+        $ret{is_member} = $remote->member_of( $u ) if $remote;
 
         push @actions, 'join', 'leave';
     }
 
     # generate auth tokens
     if ($remote) {
-        push @actions, 'addFriend', 'removeFriend', 'setBan' , 'setUnban';
+        push @actions, 'addTrust', 'addWatch', 'removeTrust', 'removeWatch', 'setBan' , 'setUnban';
         foreach my $action (@actions) {
             $ret{"${action}_authtoken"} = LJ::Auth->ajax_auth_token(
                                                                     $remote,
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org