@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 138 lines 3.9 kB view raw
1<?php 2 3final class ConpherenceNotificationPanelController 4 extends ConpherenceController { 5 6 public function handleRequest(AphrontRequest $request) { 7 $user = $request->getUser(); 8 $conpherences = array(); 9 require_celerity_resource('conpherence-notification-css'); 10 11 $participant_data = id(new ConpherenceParticipantQuery()) 12 ->withParticipantPHIDs(array($user->getPHID())) 13 ->setLimit(5) 14 ->execute(); 15 $participant_data = mpull($participant_data, null, 'getConpherencePHID'); 16 17 if ($participant_data) { 18 $conpherences = id(new ConpherenceThreadQuery()) 19 ->setViewer($user) 20 ->withPHIDs(array_keys($participant_data)) 21 ->needProfileImage(true) 22 ->needTransactions(true) 23 ->setTransactionLimit(100) 24 ->execute(); 25 } 26 27 if ($conpherences) { 28 // re-order the conpherences based on participation data 29 $conpherences = array_select_keys( 30 $conpherences, array_keys($participant_data)); 31 $view = new AphrontNullView(); 32 foreach ($conpherences as $conpherence) { 33 $p_data = $participant_data[$conpherence->getPHID()]; 34 $d_data = $conpherence->getDisplayData($user); 35 $classes = array( 36 'phabricator-notification', 37 'conpherence-notification', 38 ); 39 40 if (!$p_data->isUpToDate($conpherence)) { 41 $classes[] = 'phabricator-notification-unread'; 42 } 43 $uri = $this->getApplicationURI($conpherence->getID().'/'); 44 $title = $d_data['title']; 45 $subtitle = $d_data['subtitle']; 46 $unread_count = $d_data['unread_count']; 47 $epoch = $d_data['epoch']; 48 $image = $d_data['image']; 49 50 $msg_view = id(new ConpherenceMenuItemView()) 51 ->setUser($user) 52 ->setTitle($title) 53 ->setSubtitle($subtitle) 54 ->setHref($uri) 55 ->setEpoch($epoch) 56 ->setImageURI($image) 57 ->setUnreadCount($unread_count); 58 59 $view->appendChild(javelin_tag( 60 'div', 61 array( 62 'class' => implode(' ', $classes), 63 'sigil' => 'notification', 64 'meta' => array( 65 'href' => $uri, 66 ), 67 ), 68 $msg_view)); 69 } 70 $content = $view->render(); 71 } else { 72 $rooms_uri = phutil_tag( 73 'a', 74 array( 75 'href' => '/conpherence/', 76 'class' => 'no-room-notification', 77 ), 78 pht('You have joined no rooms.')); 79 80 $content = phutil_tag_div( 81 'phabricator-notification no-notifications', $rooms_uri); 82 } 83 84 $content = hsprintf( 85 '<div class="phabricator-notification-header grouped">%s%s</div>'. 86 '%s', 87 phutil_tag( 88 'a', 89 array( 90 'href' => '/conpherence/', 91 ), 92 pht('Rooms')), 93 $this->renderPersistentOption(), 94 $content); 95 96 $unread = id(new ConpherenceParticipantCountQuery()) 97 ->withParticipantPHIDs(array($user->getPHID())) 98 ->withUnread(true) 99 ->execute(); 100 $unread_count = idx($unread, $user->getPHID(), 0); 101 102 $json = array( 103 'content' => $content, 104 'number' => (int)$unread_count, 105 ); 106 107 return id(new AphrontAjaxResponse())->setContent($json); 108 } 109 110 private function renderPersistentOption() { 111 $viewer = $this->getViewer(); 112 $column_key = PhabricatorConpherenceColumnVisibleSetting::SETTINGKEY; 113 $show = (bool)$viewer->getUserSetting($column_key, false); 114 115 $view = phutil_tag( 116 'div', 117 array( 118 'class' => 'persistent-option', 119 ), 120 array( 121 javelin_tag( 122 'input', 123 array( 124 'type' => 'checkbox', 125 'checked' => ($show) ? 'checked' : null, 126 'value' => !$show, 127 'sigil' => 'conpherence-persist-column', 128 )), 129 phutil_tag( 130 'span', 131 array(), 132 pht('Persistent Chat')), 133 )); 134 135 return $view; 136 } 137 138}