Exemple #1
0
 public function testClear()
 {
     /**
      * @var array $users
      * @var integer $groupId
      * @var integer $chatroomId
      */
     require __DIR__ . '/initData.php';
     $userList = [];
     foreach ($users as $user) {
         UserManager::getInstance()->removeUser($user['account']);
         $userList[] = $user['uid'];
     }
     // create group, and user to group
     GroupManager::getInstance()->removeGroupUsers($groupId, $userList);
     // create chatroom, add user to chatroom
     ChatroomManager::getInstance()->removeChatroomUsers($chatroomId, $userList);
 }
 public function dispatchReceivePacket(Packet $packet, Session $session)
 {
     if (!$session->isAuth()) {
         return;
     }
     /* @var \jegarn\session\SwooleSession $session
      * @var GroupChatPacket $pkt
      */
     if ($pkt = GroupChatPacket::getPacketFromPacket($packet)) {
         // check send user is a member of this group
         $gm = GroupManager::getInstance();
         $fromUid = $pkt->getFrom();
         $isSystemUser = $packet->isFromSystemUser();
         if ($isSystemUser || $gm->isGroupUser($pkt->getGroupId(), $fromUid)) {
             if ($pkt->isSendToAll()) {
                 if ($uidList = $gm->getGroupUsers($pkt->getGroupId())) {
                     foreach ($uidList as $uid) {
                         if ($uid != $fromUid) {
                             $this->sendOrSavePacket($pkt, $uid);
                         }
                     }
                 } else {
                     Logger::addInfo('group ' . $pkt->getGroupId() . ' users lost, from uid ' . $fromUid);
                 }
             } else {
                 $toUid = $pkt->getTo();
                 if ($fromUid != $toUid) {
                     if ($isSystemUser || $gm->isGroupUser($pkt->getGroupId(), $toUid)) {
                         $this->sendOrSavePacket($pkt, $toUid);
                     } else {
                         Logger::addInfo('group ' . $pkt->getGroupId() . ' users lost, from uid ' . $fromUid);
                     }
                 }
             }
         } else {
             Logger::addInfo('group ' . $pkt->getGroupId() . ' has no user ' . $fromUid);
         }
     }
 }
Exemple #3
0
 public static function quitGroup($groupId, $requestUid)
 {
     GroupManager::getInstance()->removeGroupUser(intval($groupId), intval($requestUid));
 }
Exemple #4
0
 public function managerUser(User $manager, GroupUser $model, GroupUser $previousGroupUser)
 {
     $resp = $this->request('/api/group/manage_user', ['uid' => $manager->id, 'token' => $manager->token, 'gid' => $previousGroupUser->gid, 'user_id' => $previousGroupUser->uid, 'status' => $model->status, 'permission' => $model->permission], true);
     $this->assertRequestSuccess($resp);
     $result = $this->getResponseBody($resp);
     if ($model->status != $previousGroupUser->status) {
         if ($model->status == GroupUser::STATUS_AGREE) {
             self::assertTrue(\jegarn\manager\GroupManager::getInstance()->isGroupUser($previousGroupUser->gid, $previousGroupUser->uid) != false);
             $this->assertNotificationPacket($previousGroupUser->uid, new GroupAgreeNotification());
         } else {
             if ($model->status == GroupUser::STATUS_REFUSED) {
                 $this->assertNotificationPacket($previousGroupUser->uid, new GroupRefusedNotification());
             }
         }
     }
     return ConvertUtil::arrayToObject($result, new GroupUser(), ['id', 'gid', 'uid', 'status', 'permission', 'create_time', 'remark']);
 }
Exemple #5
0
 public static function getUser()
 {
     $user = ['uid' => self::$uidIndex, 'account' => 'tester_' . self::$uidIndex, 'password' => rand(100000, 999999), 'groupId' => self::getGroup(), 'chatroomId' => self::getChatroom()];
     self::$uidList[] = self::$uidIndex;
     ++self::$uidIndex;
     UserManager::getInstance()->addUser($user['uid'], $user['account'], $user['password']);
     GroupManager::getInstance()->addGroupUser($user['groupId'], $user['uid']);
     ChatroomManager::getInstance()->addChatroomUser($user['chatroomId'], $user['uid']);
     return $user;
 }