From b00bcbb1c150246731822f0e22c1ba80000ff027 Mon Sep 17 00:00:00 2001
From: Hypolite Petovan <hypolite@mrpetovan.com>
Date: Mon, 10 Jun 2019 21:40:44 -0400
Subject: [PATCH] Normalize the contact sidebar with the profile sidebar

- Remove un/follow text links in contact status window
---
 src/Module/Contact.php                     | 38 +++++++++++++---------
 view/templates/contact_edit.tpl            |  5 ---
 view/templates/widget/vcard.tpl            | 15 +++++++++
 view/theme/frio/templates/contact_edit.tpl |  5 ---
 view/theme/frio/templates/widget/vcard.tpl | 25 ++++++++++++++
 view/theme/vier/templates/contact_edit.tpl |  5 ---
 6 files changed, 62 insertions(+), 31 deletions(-)

diff --git a/src/Module/Contact.php b/src/Module/Contact.php
index 989896ef73..feae601fdd 100644
--- a/src/Module/Contact.php
+++ b/src/Module/Contact.php
@@ -309,6 +309,21 @@ class Contact extends BaseModule
 				$network_link = '';
 			}
 
+			$follow_link = '';
+			$unfollow_link = '';
+			if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
+				if ($contact['uid'] && in_array($contact['rel'], [Model\Contact::SHARING, Model\Contact::FRIEND])) {
+					$unfollow_link = 'unfollow?url=' . urlencode($contact['url']);
+				} elseif(!$contact['pending']) {
+					$follow_link = 'follow?url=' . urlencode($contact['url']);
+				}
+			}
+
+			$wallmessage_link = '';
+			if ($contact['uid'] && Model\Contact::canReceivePrivateMessages($contact)) {
+				$wallmessage_link = 'message/new/' . $contact['id'];
+			}
+
 			$vcard_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/vcard.tpl'), [
 				'$name'         => $contact['name'],
 				'$photo'        => $contact['photo'],
@@ -316,7 +331,13 @@ class Contact extends BaseModule
 				'$addr'         => defaults($contact, 'addr', ''),
 				'$network_link' => $network_link,
 				'$network'      => L10n::t('Network:'),
-				'$account_type' => Model\Contact::getAccountType($contact)
+				'$account_type' => Model\Contact::getAccountType($contact),
+				'$follow'       => L10n::t('Follow'),
+				'$follow_link'   => $follow_link,
+				'$unfollow'     => L10n::t('Unfollow'),
+				'$unfollow_link' => $unfollow_link,
+				'$wallmessage'  => L10n::t('Message'),
+				'$wallmessage_link' => $wallmessage_link,
 			]);
 
 			$findpeople_widget = '';
@@ -557,19 +578,6 @@ class Contact extends BaseModule
 				$profile_select = ContactSelector::profileAssign($contact['profile-id'], $contact['network'] !== Protocol::DFRN);
 			}
 
-			/// @todo Only show the following link with DFRN when the remote version supports it
-			$follow = '';
-			$follow_text = '';
-			if ($contact['uid'] && in_array($contact['rel'], [Model\Contact::FRIEND, Model\Contact::SHARING])) {
-				if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
-					$follow = $a->getBaseURL(true) . '/unfollow?url=' . urlencode($contact['url']);
-					$follow_text = L10n::t('Disconnect/Unfollow');
-				}
-			} elseif(!$contact['pending']) {
-				$follow = $a->getBaseURL(true) . '/follow?url=' . urlencode($contact['url']);
-				$follow_text = L10n::t('Connect/Follow');
-			}
-
 			// Load contactact related actions like hide, suggest, delete and others
 			$contact_actions = self::getContactActions($contact);
 
@@ -610,8 +618,6 @@ class Contact extends BaseModule
 				'$updpub'         => L10n::t('Update public posts'),
 				'$last_update'    => $last_update,
 				'$udnow'          => L10n::t('Update now'),
-				'$follow'         => $follow,
-				'$follow_text'    => $follow_text,
 				'$profile_select' => $profile_select,
 				'$contact_id'     => $contact['id'],
 				'$block_text'     => ($contact['blocked'] ? L10n::t('Unblock') : L10n::t('Block')),
diff --git a/view/templates/contact_edit.tpl b/view/templates/contact_edit.tpl
index 644121cadd..d78d4162ef 100644
--- a/view/templates/contact_edit.tpl
+++ b/view/templates/contact_edit.tpl
@@ -44,11 +44,6 @@
 						{{if $ignored}}<li><div id="ignore-message">{{$ignored}}</div></li>{{/if}}
 						{{if $archived}}<li><div id="archive-message">{{$archived}}</div></li>{{/if}}
 					</ul>
-
-					<ul>
-						<!-- <li><a href="network/?cid={{$contact_id}}" id="contact-edit-view-recent">{{$lblrecent}}</a></li> -->
-						{{if $follow}}<li><div id="contact-edit-follow"><a href="{{$follow}}">{{$follow_text}}</a></div></li>{{/if}}
-					</ul>
 				</div> {{* End of contact-edit-status-wrapper *}}
 
 				{{* Some information about the contact from the profile *}}
diff --git a/view/templates/widget/vcard.tpl b/view/templates/widget/vcard.tpl
index 240466460e..465d206b81 100644
--- a/view/templates/widget/vcard.tpl
+++ b/view/templates/widget/vcard.tpl
@@ -10,5 +10,20 @@
 	{{/if}}
 	{{if $account_type}}<div class="account-type">{{$account_type}}</div>{{/if}}
 	{{if $network_link}}<dl class="network"><dt class="network-label">{{$network}}</dt><dd class="x-network">{{$network_link nofilter}}</dd></dl>{{/if}}
+
+	<div id="profile-extra-links">
+		<ul>
+			{{if $follow_link}}
+				<li><a id="dfrn-request-link" href="{{$follow_link}}">{{$follow}}</a></li>
+			{{/if}}
+			{{if $unfollow_link}}
+				<li><a id="dfrn-request-link" href="{{$unfollow_link}}">{{$unfollow}}</a></li>
+			{{/if}}
+			{{if $wallmessage_link}}
+				<li><a id="wallmessage-link" href="{{$wallmessage_link}}">{{$wallmessage}}</a></li>
+			{{/if}}
+		</ul>
+	</div>
+
 	<div id="profile-vcard-break"></div>
 </div>
diff --git a/view/theme/frio/templates/contact_edit.tpl b/view/theme/frio/templates/contact_edit.tpl
index 92ff615a98..f9454dc654 100644
--- a/view/theme/frio/templates/contact_edit.tpl
+++ b/view/theme/frio/templates/contact_edit.tpl
@@ -58,11 +58,6 @@
 						{{if $ignored}}<li><div id="ignore-message">{{$ignored}}</div></li>{{/if}}
 						{{if $archived}}<li><div id="archive-message">{{$archived}}</div></li>{{/if}}
 					</ul>
-
-					<ul>
-						<!-- <li><a href="network/?cid={{$contact_id}}" id="contact-edit-view-recent">{{$lblrecent}}</a></li> -->
-						{{if $follow}}<li><div id="contact-edit-follow"><a href="{{$follow}}">{{$follow_text}}</a></div></li>{{/if}}
-					</ul>
 				</div> {{* End of contact-edit-status-wrapper *}}
 
 				<div id="contact-edit-links-end"></div>
diff --git a/view/theme/frio/templates/widget/vcard.tpl b/view/theme/frio/templates/widget/vcard.tpl
index d1b41728b1..366c570a74 100644
--- a/view/theme/frio/templates/widget/vcard.tpl
+++ b/view/theme/frio/templates/widget/vcard.tpl
@@ -34,5 +34,30 @@
 
 			{{if $network_link}}<dl class="network"><dt class="network-label">{{$network}}</dt><dd class="x-network">{{$network_link nofilter}}</dd></dl>{{/if}}
 		</div>
+
+		<div id="profile-extra-links">
+			<div id="dfrn-request-link-button">
+				{{if $follow_link}}
+					<a id="dfrn-request-link" class="btn btn-labeled btn-primary btn-sm" href="{{$follow_link}}"">
+						<span class=""><i class="fa fa-user-plus"></i></span>
+						<span class="">{{$follow}}</span>
+					</a>
+				{{/if}}
+				{{if $unfollow_link}}
+					<a id="dfrn-request-link" class="btn btn-labeled btn-primary btn-sm" href="{{$unfollow_link}}">
+						<span class=""><i class="fa fa-user-times"></i></span>
+						<span class="">{{$unfollow}}</span>
+					</a>
+				{{/if}}
+			</div>
+			{{if $wallmessage_link}}
+				<div id="wallmessage-link-botton">
+					<button type="button" id="wallmessage-link" class="btn btn-labeled btn-primary btn-sm" onclick="openWallMessage('{{$wallmessage_link}}')">
+						<span class=""><i class="fa fa-envelope"></i></span>
+						<span class="">{{$wallmessage}}</span>
+					</button>
+				</div>
+			{{/if}}
+		</div>
 	</div>
 </div>
diff --git a/view/theme/vier/templates/contact_edit.tpl b/view/theme/vier/templates/contact_edit.tpl
index a01fac9ee4..bd07f18213 100644
--- a/view/theme/vier/templates/contact_edit.tpl
+++ b/view/theme/vier/templates/contact_edit.tpl
@@ -45,11 +45,6 @@
 						{{if $ignored}}<li><div id="ignore-message">{{$ignored}}</div></li>{{/if}}
 						{{if $archived}}<li><div id="archive-message">{{$archived}}</div></li>{{/if}}
 					</ul>
-
-					<ul>
-						<!-- <li><a href="network/?cid={{$contact_id}}" id="contact-edit-view-recent">{{$lblrecent}}</a></li> -->
-						{{if $follow}}<li><div id="contact-edit-follow"><a href="{{$follow}}">{{$follow_text}}</a></div></li>{{/if}}
-					</ul>
 				</div> {{* End of contact-edit-status-wrapper *}}
 
 				{{* Some information about the contact from the profile *}}
-- 
2.39.5