@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add Conduit method for querying user status

Summary:
I want to use this to warn user if he specifies reviewers that are away.

We can also implement a general query method but I think that this usage is the
most useful not only for me but also in general case.

Test Plan:
Call the method for user which is away and which is not away.
Add user status through Conduit.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran, epriestley

Differential Revision: https://secure.phabricator.com/D2492

vrana 2476c872 f1f43f0a

+96 -9
+2
src/__phutil_library_map__.php
··· 185 185 'ConduitAPI_user_Method' => 'applications/conduit/method/user/base', 186 186 'ConduitAPI_user_addstatus_Method' => 'applications/conduit/method/user/addstatus', 187 187 'ConduitAPI_user_find_Method' => 'applications/conduit/method/user/find', 188 + 'ConduitAPI_user_getcurrentstatus_Method' => 'applications/conduit/method/user/getcurrentstatus', 188 189 'ConduitAPI_user_info_Method' => 'applications/conduit/method/user/info', 189 190 'ConduitAPI_user_query_Method' => 'applications/conduit/method/user/query', 190 191 'ConduitAPI_user_removestatus_Method' => 'applications/conduit/method/user/removestatus', ··· 1217 1218 'ConduitAPI_user_Method' => 'ConduitAPIMethod', 1218 1219 'ConduitAPI_user_addstatus_Method' => 'ConduitAPI_user_Method', 1219 1220 'ConduitAPI_user_find_Method' => 'ConduitAPI_user_Method', 1221 + 'ConduitAPI_user_getcurrentstatus_Method' => 'ConduitAPI_user_Method', 1220 1222 'ConduitAPI_user_info_Method' => 'ConduitAPI_user_Method', 1221 1223 'ConduitAPI_user_query_Method' => 'ConduitAPI_user_Method', 1222 1224 'ConduitAPI_user_removestatus_Method' => 'ConduitAPI_user_Method',
+1 -9
src/applications/conduit/method/user/addstatus/ConduitAPI_user_addstatus_Method.php
··· 73 73 throw new ConduitException('ERR-OVERLAP'); 74 74 } 75 75 76 - switch ($request->getValue('status')) { 77 - case 'sporadic': 78 - $status = PhabricatorUserStatus::STATUS_SPORADIC; 79 - break; 80 - default: 81 - $status = PhabricatorUserStatus::STATUS_AWAY; 82 - break; 83 - } 84 76 id(new PhabricatorUserStatus()) 85 77 ->setUserPHID($user_phid) 86 78 ->setDateFrom($from) 87 79 ->setDateTo($to) 88 - ->setStatus($status) 80 + ->setTextStatus($request->getValue('status')) 89 81 ->save(); 90 82 91 83 $table->endWriteLocking();
+64
src/applications/conduit/method/user/getcurrentstatus/ConduitAPI_user_getcurrentstatus_Method.php
··· 1 + <?php 2 + 3 + /* 4 + * Copyright 2012 Facebook, Inc. 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + */ 18 + 19 + /** 20 + * @group conduit 21 + */ 22 + final class ConduitAPI_user_getcurrentstatus_Method 23 + extends ConduitAPI_user_Method { 24 + 25 + public function getMethodStatus() { 26 + return self::METHOD_STATUS_UNSTABLE; 27 + } 28 + 29 + public function getMethodDescription() { 30 + return "Get current status (away or sporadic) of specified users."; 31 + } 32 + 33 + public function defineParamTypes() { 34 + return array( 35 + 'userPHIDs' => 'required list', 36 + ); 37 + } 38 + 39 + public function defineReturnType() { 40 + return 'dict'; 41 + } 42 + 43 + public function defineErrorTypes() { 44 + return array( 45 + ); 46 + } 47 + 48 + protected function execute(ConduitAPIRequest $request) { 49 + $statuses = id(new PhabricatorUserStatus())->loadAllWhere( 50 + 'userPHID IN (%Ls) AND UNIX_TIMESTAMP() BETWEEN dateFrom AND dateTo', 51 + $request->getValue('userPHIDs')); 52 + 53 + $return = array(); 54 + foreach ($statuses as $status) { 55 + $return[$status->getUserPHID()] = array( 56 + 'fromEpoch' => $status->getDateFrom(), 57 + 'toEpoch' => $status->getDateTo(), 58 + 'status' => $status->getTextStatus(), 59 + ); 60 + } 61 + return $return; 62 + } 63 + 64 + }
+15
src/applications/conduit/method/user/getcurrentstatus/__init__.php
··· 1 + <?php 2 + /** 3 + * This file is automatically generated. Lint this module to rebuild it. 4 + * @generated 5 + */ 6 + 7 + 8 + 9 + phutil_require_module('phabricator', 'applications/conduit/method/user/base'); 10 + phutil_require_module('phabricator', 'applications/people/storage/userstatus'); 11 + 12 + phutil_require_module('phutil', 'utils'); 13 + 14 + 15 + phutil_require_source('ConduitAPI_user_getcurrentstatus_Method.php');
+14
src/applications/people/storage/userstatus/PhabricatorUserStatus.php
··· 21 21 const STATUS_AWAY = 1; 22 22 const STATUS_SPORADIC = 2; 23 23 24 + private static $statusTexts = array( 25 + self::STATUS_AWAY => 'away', 26 + self::STATUS_SPORADIC => 'sporadic', 27 + ); 28 + 24 29 protected $userPHID; 25 30 protected $dateFrom; 26 31 protected $dateTo; 27 32 protected $status; 33 + 34 + public function getTextStatus() { 35 + return self::$statusTexts[$this->status]; 36 + } 37 + 38 + public function setTextStatus($status) { 39 + $statuses = array_flip(self::$statusTexts); 40 + return $this->setStatus($statuses[$status]); 41 + } 28 42 29 43 }