1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-06 11:58:30 +01:00

Conpherence - implement join / view rules for rooms

Summary:
Ref T7585. This implements everything specified, with a few caveats

- since rooms you have yet to join can't be viewed in the column yet, the column view has some bugs and isn't expected to work.
- the room you're looking at is just pre-pending to the top of the "recent" list

Test Plan: made a room that no one could join. verified when viewing that there was no comment ui. made a room that others could join. verified folks who had yet to join had a "join" button with an area for text. tried joining with / without message text and it worked in both cases

Reviewers: chad, epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T7585

Differential Revision: https://secure.phabricator.com/D12149
This commit is contained in:
Bob Trahan 2015-03-24 18:38:16 -07:00
parent aa310230b6
commit 25767096c9
11 changed files with 178 additions and 62 deletions

View file

@ -49,7 +49,7 @@ return array(
'rsrc/css/application/conpherence/message-pane.css' => 'e78e9d3c', 'rsrc/css/application/conpherence/message-pane.css' => 'e78e9d3c',
'rsrc/css/application/conpherence/notification.css' => '04a6e10a', 'rsrc/css/application/conpherence/notification.css' => '04a6e10a',
'rsrc/css/application/conpherence/update.css' => '1099a660', 'rsrc/css/application/conpherence/update.css' => '1099a660',
'rsrc/css/application/conpherence/widget-pane.css' => '9efbfed0', 'rsrc/css/application/conpherence/widget-pane.css' => '9199d87c',
'rsrc/css/application/contentsource/content-source-view.css' => '4b8b05d4', 'rsrc/css/application/contentsource/content-source-view.css' => '4b8b05d4',
'rsrc/css/application/countdown/timer.css' => '86b7b0a0', 'rsrc/css/application/countdown/timer.css' => '86b7b0a0',
'rsrc/css/application/dashboard/dashboard.css' => '17937d22', 'rsrc/css/application/dashboard/dashboard.css' => '17937d22',
@ -354,7 +354,7 @@ return array(
'rsrc/js/application/config/behavior-reorder-fields.js' => '14a827de', 'rsrc/js/application/config/behavior-reorder-fields.js' => '14a827de',
'rsrc/js/application/conpherence/ConpherenceThreadManager.js' => '24561adb', 'rsrc/js/application/conpherence/ConpherenceThreadManager.js' => '24561adb',
'rsrc/js/application/conpherence/behavior-durable-column.js' => 'eedc463c', 'rsrc/js/application/conpherence/behavior-durable-column.js' => 'eedc463c',
'rsrc/js/application/conpherence/behavior-menu.js' => 'c4151295', 'rsrc/js/application/conpherence/behavior-menu.js' => 'be9207ed',
'rsrc/js/application/conpherence/behavior-pontificate.js' => '21ba5861', 'rsrc/js/application/conpherence/behavior-pontificate.js' => '21ba5861',
'rsrc/js/application/conpherence/behavior-quicksand-blacklist.js' => '7927a7d3', 'rsrc/js/application/conpherence/behavior-quicksand-blacklist.js' => '7927a7d3',
'rsrc/js/application/conpherence/behavior-widget-pane.js' => '2c1cd7f5', 'rsrc/js/application/conpherence/behavior-widget-pane.js' => '2c1cd7f5',
@ -519,7 +519,7 @@ return array(
'conpherence-notification-css' => '04a6e10a', 'conpherence-notification-css' => '04a6e10a',
'conpherence-thread-manager' => '24561adb', 'conpherence-thread-manager' => '24561adb',
'conpherence-update-css' => '1099a660', 'conpherence-update-css' => '1099a660',
'conpherence-widget-pane-css' => '9efbfed0', 'conpherence-widget-pane-css' => '9199d87c',
'differential-changeset-view-css' => '79c27a4c', 'differential-changeset-view-css' => '79c27a4c',
'differential-core-view-css' => '7ac3cabc', 'differential-core-view-css' => '7ac3cabc',
'differential-inline-comment-editor' => 'f2431bc1', 'differential-inline-comment-editor' => 'f2431bc1',
@ -556,7 +556,7 @@ return array(
'javelin-behavior-boards-dropdown' => '0ec56e1d', 'javelin-behavior-boards-dropdown' => '0ec56e1d',
'javelin-behavior-choose-control' => '6153c708', 'javelin-behavior-choose-control' => '6153c708',
'javelin-behavior-config-reorder-fields' => '14a827de', 'javelin-behavior-config-reorder-fields' => '14a827de',
'javelin-behavior-conpherence-menu' => 'c4151295', 'javelin-behavior-conpherence-menu' => 'be9207ed',
'javelin-behavior-conpherence-pontificate' => '21ba5861', 'javelin-behavior-conpherence-pontificate' => '21ba5861',
'javelin-behavior-conpherence-widget-pane' => '2c1cd7f5', 'javelin-behavior-conpherence-widget-pane' => '2c1cd7f5',
'javelin-behavior-countdown-timer' => 'e4cc26b3', 'javelin-behavior-countdown-timer' => 'e4cc26b3',
@ -1718,14 +1718,7 @@ return array(
'javelin-util', 'javelin-util',
'phabricator-shaped-request', 'phabricator-shaped-request',
), ),
'c1700f6f' => array( 'be9207ed' => array(
'javelin-install',
'javelin-util',
'javelin-stratcom',
'javelin-dom',
'javelin-vector',
),
'c4151295' => array(
'javelin-behavior', 'javelin-behavior',
'javelin-dom', 'javelin-dom',
'javelin-util', 'javelin-util',
@ -1737,6 +1730,13 @@ return array(
'phabricator-shaped-request', 'phabricator-shaped-request',
'conpherence-thread-manager', 'conpherence-thread-manager',
), ),
'c1700f6f' => array(
'javelin-install',
'javelin-util',
'javelin-stratcom',
'javelin-dom',
'javelin-vector',
),
'c51ae228' => array( 'c51ae228' => array(
'javelin-behavior', 'javelin-behavior',
'javelin-util', 'javelin-util',

View file

@ -5,6 +5,7 @@ final class ConpherenceUpdateActions extends ConpherenceConstants {
const METADATA = 'metadata'; const METADATA = 'metadata';
const MESSAGE = 'message'; const MESSAGE = 'message';
const DRAFT = 'draft'; const DRAFT = 'draft';
const JOIN_ROOM = 'join_room';
const ADD_PERSON = 'add_person'; const ADD_PERSON = 'add_person';
const REMOVE_PERSON = 'remove_person'; const REMOVE_PERSON = 'remove_person';
const NOTIFICATIONS = 'notifications'; const NOTIFICATIONS = 'notifications';

View file

@ -69,11 +69,23 @@ final class ConpherenceListController extends ConpherenceController {
if ($conpherence->getTitle()) { if ($conpherence->getTitle()) {
$title = $conpherence->getTitle(); $title = $conpherence->getTitle();
} }
$cursor = $conpherence->getParticipant($user->getPHID()); $cursor = $conpherence->getParticipantIfExists($user->getPHID());
$data = $this->loadParticipationWithMidCursor($cursor); if ($cursor) {
$all_participation = $data['participation']; $data = $this->loadParticipationWithMidCursor($cursor);
$scroll_up_participant = $data['scroll_up_participant']; $all_participation = $data['all_participation'];
$scroll_down_participant = $data['scroll_down_participant']; $scroll_up_participant = $data['scroll_up_participant'];
$scroll_down_participant = $data['scroll_down_participant'];
} else {
$data = $this->loadDefaultParticipation($too_many);
$all_participation = $data['all_participation'];
$scroll_down_participant = $data['scroll_down_participant'];
$menu_participation = $this->getEmptyParticipant()
->setConpherencePHID($conpherence->getPHID())
->setParticipantPHID($user->getPHID());
$all_participation =
array($conpherence->getPHID() => $menu_participation) +
$all_participation;
}
break; break;
case self::PAGING_MODE: case self::PAGING_MODE:
$direction = $request->getStr('direction'); $direction = $request->getStr('direction');
@ -108,16 +120,9 @@ final class ConpherenceListController extends ConpherenceController {
break; break;
case self::UNSELECTED_MODE: case self::UNSELECTED_MODE:
default: default:
$too_many = ConpherenceParticipantQuery::LIMIT + 1; $data = $this->loadDefaultParticipation($too_many);
$all_participation = id(new ConpherenceParticipantQuery()) $all_participation = $data['all_participation'];
->withParticipantPHIDs(array($user->getPHID())) $scroll_down_participant = $data['scroll_down_participant'];
->setLimit($too_many)
->execute();
if (count($all_participation) == $too_many) {
$node = end($all_participation);
unset($all_participation[$node->getConpherencePHID()]);
$scroll_down_participant = $node;
}
break; break;
} }
@ -171,6 +176,26 @@ final class ConpherenceListController extends ConpherenceController {
} }
private function loadDefaultParticipation($too_many) {
$viewer = $this->getRequest()->getUser();
$scroll_down_participant = $this->getEmptyParticipant();
$all_participation = id(new ConpherenceParticipantQuery())
->withParticipantPHIDs(array($viewer->getPHID()))
->setLimit($too_many)
->execute();
if (count($all_participation) == $too_many) {
$node = end($all_participation);
unset($all_participation[$node->getConpherencePHID()]);
$scroll_down_participant = $node;
}
return array(
'all_participation' => $all_participation,
'scroll_down_participant' => $scroll_down_participant,);
}
/** /**
* Handles the curious case when we are visiting a conpherence directly * Handles the curious case when we are visiting a conpherence directly
* by issuing two separate queries. Otherwise, additional conpherences * by issuing two separate queries. Otherwise, additional conpherences
@ -224,7 +249,7 @@ final class ConpherenceListController extends ConpherenceController {
return array( return array(
'scroll_up_participant' => $scroll_up_participant, 'scroll_up_participant' => $scroll_up_participant,
'scroll_down_participant' => $scroll_down_participant, 'scroll_down_participant' => $scroll_down_participant,
'participation' => $participation, 'all_participation' => $participation,
); );
} }

View file

@ -53,6 +53,28 @@ final class ConpherenceUpdateController
$draft->setDraft($request->getStr('text')); $draft->setDraft($request->getStr('text'));
$draft->replaceOrDelete(); $draft->replaceOrDelete();
return new AphrontAjaxResponse(); return new AphrontAjaxResponse();
case ConpherenceUpdateActions::JOIN_ROOM:
PhabricatorPolicyFilter::requireCapability(
$user,
$conpherence,
PhabricatorPolicyCapability::CAN_JOIN);
$xactions[] = id(new ConpherenceTransaction())
->setTransactionType(
ConpherenceTransactionType::TYPE_PARTICIPANTS)
->setNewValue(array('+' => array($user->getPHID())));
$delete_draft = true;
$message = $request->getStr('text');
if ($message) {
$message_xactions = $editor->generateTransactionsFromText(
$user,
$conpherence,
$message);
$xactions = array_merge($xactions, $message_xactions);
}
// for now, just redirect back to the conpherence so everything
// will work okay...!
$response_mode = 'redirect';
break;
case ConpherenceUpdateActions::MESSAGE: case ConpherenceUpdateActions::MESSAGE:
$message = $request->getStr('text'); $message = $request->getStr('text');
$xactions = $editor->generateTransactionsFromText( $xactions = $editor->generateTransactionsFromText(
@ -86,7 +108,10 @@ final class ConpherenceUpdateController
break; break;
case ConpherenceUpdateActions::NOTIFICATIONS: case ConpherenceUpdateActions::NOTIFICATIONS:
$notifications = $request->getStr('notifications'); $notifications = $request->getStr('notifications');
$participant = $conpherence->getParticipant($user->getPHID()); $participant = $conpherence->getParticipantIfExists($user->getPHID());
if (!$participant) {
return id(new Aphront404Response());
}
$participant->setSettings(array('notifications' => $notifications)); $participant->setSettings(array('notifications' => $notifications));
$participant->save(); $participant->save();
$result = pht( $result = pht(
@ -126,23 +151,23 @@ final class ConpherenceUpdateController
break; break;
} }
if ($xactions || ($action == ConpherenceUpdateActions::LOAD)) { if ($xactions) {
if ($xactions) { try {
try { $xactions = $editor->applyTransactions($conpherence, $xactions);
$xactions = $editor->applyTransactions($conpherence, $xactions); if ($delete_draft) {
if ($delete_draft) { $draft = PhabricatorDraft::newFromUserAndKey(
$draft = PhabricatorDraft::newFromUserAndKey( $user,
$user, $conpherence->getPHID());
$conpherence->getPHID()); $draft->delete();
$draft->delete();
}
} catch (PhabricatorApplicationTransactionNoEffectException $ex) {
return id(new PhabricatorApplicationTransactionNoEffectResponse())
->setCancelURI($this->getApplicationURI($conpherence_id.'/'))
->setException($ex);
} }
} catch (PhabricatorApplicationTransactionNoEffectException $ex) {
return id(new PhabricatorApplicationTransactionNoEffectResponse())
->setCancelURI($this->getApplicationURI($conpherence_id.'/'))
->setException($ex);
} }
}
if ($xactions || ($action == ConpherenceUpdateActions::LOAD)) {
switch ($response_mode) { switch ($response_mode) {
case 'ajax': case 'ajax':
$latest_transaction_id = $request->getInt('latest_transaction_id'); $latest_transaction_id = $request->getInt('latest_transaction_id');

View file

@ -27,12 +27,14 @@ final class ConpherenceViewController extends
} }
$this->setConpherence($conpherence); $this->setConpherence($conpherence);
$participant = $conpherence->getParticipant($user->getPHID());
$transactions = $conpherence->getTransactions(); $transactions = $conpherence->getTransactions();
$latest_transaction = head($transactions); $latest_transaction = head($transactions);
$write_guard = AphrontWriteGuard::beginScopedUnguardedWrites(); $participant = $conpherence->getParticipantIfExists($user->getPHID());
$participant->markUpToDate($conpherence, $latest_transaction); if ($participant) {
unset($write_guard); $write_guard = AphrontWriteGuard::beginScopedUnguardedWrites();
$participant->markUpToDate($conpherence, $latest_transaction);
unset($write_guard);
}
$data = ConpherenceTransactionView::renderTransactions( $data = ConpherenceTransactionView::renderTransactions(
$user, $user,
@ -85,9 +87,24 @@ final class ConpherenceViewController extends
$conpherence = $this->getConpherence(); $conpherence = $this->getConpherence();
$user = $this->getRequest()->getUser(); $user = $this->getRequest()->getUser();
$can_join = PhabricatorPolicyFilter::hasCapability(
$user,
$conpherence,
PhabricatorPolicyCapability::CAN_JOIN);
$participating = $conpherence->getParticipantIfExists($user->getPHID());
if (!$can_join && !$participating) {
return null;
}
$draft = PhabricatorDraft::newFromUserAndKey( $draft = PhabricatorDraft::newFromUserAndKey(
$user, $user,
$conpherence->getPHID()); $conpherence->getPHID());
if ($participating) {
$action = ConpherenceUpdateActions::MESSAGE;
$button_text = pht('Send');
} else {
$action = ConpherenceUpdateActions::JOIN_ROOM;
$button_text = pht('Join');
}
$update_uri = $this->getApplicationURI('update/'.$conpherence->getID().'/'); $update_uri = $this->getApplicationURI('update/'.$conpherence->getID().'/');
$this->initBehavior('conpherence-pontificate'); $this->initBehavior('conpherence-pontificate');
@ -98,7 +115,7 @@ final class ConpherenceViewController extends
->addSigil('conpherence-pontificate') ->addSigil('conpherence-pontificate')
->setWorkflow(true) ->setWorkflow(true)
->setUser($user) ->setUser($user)
->addHiddenInput('action', 'message') ->addHiddenInput('action', $action)
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setUser($user) ->setUser($user)
@ -106,7 +123,7 @@ final class ConpherenceViewController extends
->setValue($draft->getDraft())) ->setValue($draft->getDraft()))
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->setValue(pht('Send'))) ->setValue($button_text))
->render(); ->render();
return $form; return $form;

View file

@ -130,8 +130,24 @@ final class ConpherenceWidgetController extends ConpherenceController {
private function renderSettingsWidgetPaneContent() { private function renderSettingsWidgetPaneContent() {
$viewer = $this->getViewer(); $viewer = $this->getViewer();
$conpherence = $this->getConpherence(); $conpherence = $this->getConpherence();
$participants = $conpherence->getParticipants(); $participant = $conpherence->getParticipantIfExists($viewer->getPHID());
$participant = $participants[$viewer->getPHID()]; if (!$participant) {
$can_join = PhabricatorPolicyFilter::hasCapability(
$viewer,
$conpherence,
PhabricatorPolicyCapability::CAN_JOIN);
if ($can_join) {
$text = pht('Settings are available after joining the room.');
} else {
$text = pht('Settings not applicable to rooms you can not join.');
}
return phutil_tag(
'div',
array(
'class' => 'no-settings',
),
$text);
}
$default = ConpherenceSettings::EMAIL_ALWAYS; $default = ConpherenceSettings::EMAIL_ALWAYS;
$preference = $this->getUserPreferences(); $preference = $this->getUserPreferences();
if ($preference) { if ($preference) {

View file

@ -321,6 +321,15 @@ final class ConpherenceEditor extends PhabricatorApplicationTransactionEditor {
PhabricatorLiskDAO $object, PhabricatorLiskDAO $object,
array $xactions) { array $xactions) {
$message_count = 0;
foreach ($xactions as $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorTransactions::TYPE_COMMENT:
$message_count++;
break;
}
}
// update everyone's participation status on the last xaction -only- // update everyone's participation status on the last xaction -only-
$xaction = end($xactions); $xaction = end($xactions);
$xaction_phid = $xaction->getPHID(); $xaction_phid = $xaction->getPHID();
@ -333,8 +342,8 @@ final class ConpherenceEditor extends PhabricatorApplicationTransactionEditor {
if ($phid != $user->getPHID()) { if ($phid != $user->getPHID()) {
if ($participant->getParticipationStatus() != $behind) { if ($participant->getParticipationStatus() != $behind) {
$participant->setBehindTransactionPHID($xaction_phid); $participant->setBehindTransactionPHID($xaction_phid);
// decrement one as this is the message putting them behind! $participant->setSeenMessageCount(
$participant->setSeenMessageCount($object->getMessageCount() - 1); $object->getMessageCount() - $message_count);
} }
$participant->setParticipationStatus($behind); $participant->setParticipationStatus($behind);
$participant->setDateTouched($time); $participant->setDateTouched($time);

View file

@ -98,9 +98,9 @@ final class ConpherenceThread extends ConpherenceDAO
$participants = $this->getParticipants(); $participants = $this->getParticipants();
return $participants[$phid]; return $participants[$phid];
} }
public function getParticipantIfExists($phid) { public function getParticipantIfExists($phid, $default = null) {
$participants = $this->getParticipants(); $participants = $this->getParticipants();
return idx($participants, $phid); return idx($participants, $phid, $default);
} }
public function getParticipantPHIDs() { public function getParticipantPHIDs() {
@ -221,7 +221,10 @@ final class ConpherenceThread extends ConpherenceDAO
); );
} }
/* -( PhabricatorPolicyInterface Implementation )-------------------------- */ /* -( PhabricatorPolicyInterface Implementation )-------------------------- */
public function getCapabilities() { public function getCapabilities() {
return array( return array(
PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_VIEW,

View file

@ -393,6 +393,10 @@ abstract class PhabricatorApplicationTransactionEditor
case PhabricatorTransactions::TYPE_EDIT_POLICY: case PhabricatorTransactions::TYPE_EDIT_POLICY:
$object->setEditPolicy($xaction->getNewValue()); $object->setEditPolicy($xaction->getNewValue());
break; break;
case PhabricatorTransactions::TYPE_JOIN_POLICY:
$object->setJoinPolicy($xaction->getNewValue());
break;
case PhabricatorTransactions::TYPE_CUSTOMFIELD: case PhabricatorTransactions::TYPE_CUSTOMFIELD:
$field = $this->getCustomFieldForTransaction($object, $xaction); $field = $this->getCustomFieldForTransaction($object, $xaction);
return $field->applyApplicationTransactionInternalEffects($xaction); return $field->applyApplicationTransactionInternalEffects($xaction);

View file

@ -376,3 +376,15 @@
.conpherence-widget-pane .notifications-update { .conpherence-widget-pane .notifications-update {
margin: 3px 0px 0px 4px; margin: 3px 0px 0px 4px;
} }
.conpherence-widget-pane .no-settings {
width: 200px;
padding: 20px;
text-align: center;
color: {$greytext};
}
.device .conpherence-widget-pane .no-settings {
width: 60px;
margin: 0 auto 0 auto;
}

View file

@ -321,13 +321,17 @@ JX.behavior('conpherence-menu', function(config) {
function _focusTextarea() { function _focusTextarea() {
var root = JX.DOM.find(document, 'div', 'conpherence-layout'); var root = JX.DOM.find(document, 'div', 'conpherence-layout');
var form_root = JX.DOM.find(root, 'div', 'conpherence-form'); var form_root = JX.DOM.find(root, 'div', 'conpherence-form');
var textarea = JX.DOM.find(form_root, 'textarea'); try {
// We may have a draft so do this JS trick so we end up focused at the var textarea = JX.DOM.find(form_root, 'textarea');
// end of the draft. // We may have a draft so do this JS trick so we end up focused at the
var textarea_value = textarea.value; // end of the draft.
textarea.value = ''; var textarea_value = textarea.value;
JX.DOM.focus(textarea); textarea.value = '';
textarea.value = textarea_value; JX.DOM.focus(textarea);
textarea.value = textarea_value;
} catch (ex) {
// no textarea? no problem
}
} }
JX.Stratcom.listen( JX.Stratcom.listen(
'conpherence-redraw-thread', 'conpherence-redraw-thread',