Esempio n. 1
0
 public function getMembersTokens($withMe = false)
 {
     $tokens = array();
     if (isset($this->id) && (int) $this->id > 0) {
         $ids = array();
         ChatMember::where('chat_id', $this->id)->get()->each(function ($member) use(&$ids, $withMe) {
             if ($withMe || $member->user_id != Auth::user()->id) {
                 $ids[] = $member->user_id;
             }
         });
         if (count($ids) > 0) {
             Device::whereIn('user_id', $ids)->get()->each(function ($device) use(&$tokens) {
                 $tokens[] = $device->auth_token;
             });
         }
     }
     return $tokens;
 }
Esempio n. 2
0
 /**
  * Display a listing of messages.
  *
  * @param int $chatId Chat ID
  * @param int|null $lastShownMessageId Last shown message ID
  * @param int $size Reponse size
  * @return Response
  */
 public function getList($chatId, $lastShownMessageId = null, $size = 50)
 {
     if ((int) $chatId > 0) {
         if (!is_null($chat = Chat::find((int) $chatId)) && !ChatMember::whereRaw('chat_id = ? and user_id = ?', array($chatId, Auth::user()->id))->get()->isEmpty()) {
             $result = array();
             $size = (int) $size > 0 ? (int) $size : 50;
             $unread = array();
             if (is_null($lastShownMessageId)) {
                 MessageUnread::whereRaw('chat_id = ? and user_id = ? and message_id not in (select b.message_id from messages_removed b where b.chat_id = chat_id and user_id = ' . Auth::user()->id . ')', array($chat->id, Auth::user()->id))->get()->each(function ($message) use(&$unread) {
                     $unread[] = $message->message_id;
                 });
             }
             $cleared = ChatCleared::whereRaw('chat_id = ? and user_id = ?', array($chat->id, Auth::user()->id))->orderBy('message_id', 'desc')->get()->first();
             $query = 'select a.* from messages a where a.chat_id = ' . $chat->id . ' and a.id not in (select b.message_id from messages_removed b where b.chat_id = a.chat_id and b.user_id = ' . Auth::user()->id . ')';
             if (count($unread) > 0) {
                 $query .= ' and a.id not in (' . implode(',', $unread) . ')';
             }
             if ($cleared) {
                 $query .= ' and a.id > ' . $cleared->message_id;
             }
             if (!is_null($lastShownMessageId) && (int) $lastShownMessageId > 0) {
                 $query .= ' and a.id < ' . $lastShownMessageId;
             }
             $query .= ' order by a.timestamp desc limit ' . $size;
             $messages = DB::select($query);
             if (count($unread) > 0) {
                 $unreadMessages = DB::table('messages')->whereRaw('chat_id = ? and id in (' . implode(',', $unread) . ')', array($chat->id))->orderBy('timestamp', 'desc');
                 $messages = array_merge($unreadMessages->get(), $messages);
             }
             foreach ($messages as $message) {
                 $data = (new Message((array) $message))->getAsArray();
                 if (in_array($message->id, $unread)) {
                     $data['unread'] = true;
                 }
                 $result['messages'][] = $data;
             }
             return $this->respond($result);
         } else {
             return $this->respondWithError('Chat doesn\'t exist');
         }
     } else {
         return $this->respondWithError('Chat doesn\'t exist');
     }
 }
    public function searchMemberBaru()
    {
        $qi = isset($_GET['qi']) ? addslashes($_GET['qi']) : "";
        $t = isset($_GET['t']) ? addslashes($_GET['t']) : "";
        $gid = isset($_GET['gid']) ? addslashes($_GET['gid']) : die("NO GID");
        $acc = new Account();
        $myid = Account::getMyID();
        $cg = new ChatMember();
        $arrMember = $cg->getMemberFromGID($gid);
        foreach ($arrMember as $mm) {
            $arrz[] = "admin_id != '" . $mm->admin_id . "'";
        }
        $imp = implode(" AND ", $arrz);
        $arr = $acc->getWhere("admin_aktiv = 1 AND {$imp} AND (admin_nama_depan LIKE '%{$qi}%' OR admin_username LIKE '%{$qi}%') ORDER BY admin_nama_depan ASC LIMIT 0,15");
        foreach ($arr as $ac) {
            ?>
            <div class="usercheckbox" style="padding: 5px;">
                <input type="checkbox" onclick="addToMemberArr('<?php 
            echo $ac->admin_id;
            ?>
','<?php 
            echo $ac->admin_nama_depan;
            ?>
','<?php 
            echo $t;
            ?>
');" value="<?php 
            echo $ac->admin_id;
            ?>
"> <?php 
            echo $ac->admin_nama_depan;
            ?>
            </div>
        <?php 
        }
        //pr($arr);
    }
 public function leaveGroup()
 {
     $gid = isset($_POST['inboxid']) ? addslashes($_POST['inboxid']) : die("NO GID");
     $g = new ChatGroup();
     $g->getByID($gid);
     //check apa dia owner
     if ($g->inbox_from == Account::getMyID()) {
         $json['bool'] = 0;
         $json['err'] = Lang::t("Cannot leave group");
     } else {
         $cg = new ChatMember();
         $json['bool'] = $cg->leaveMemberByGID(Account::getMyID(), $gid);
         //$g = new ChatGroup();
         //$g->removeNotifPortal($gid);
     }
     echo json_encode($json);
     die;
 }
Esempio n. 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getChatMembers()
 {
     return $this->hasMany(ChatMember::className(), ['profile_id' => 'id']);
 }
Esempio n. 6
0
 /**
  * Except a new user to the chat
  *
  * @param int|null $chatId Chat ID
  * @return Response
  */
 public function exceptUser($chatId = null, $userId = null)
 {
     if ((int) $chatId > 0 && !is_null($chat = Chat::find((int) $chatId)) && $chat->hasMember(Auth::user()->id)) {
         if ($chat->isGroup()) {
             if ((int) $userId > 0 && !is_null($user = User::find((int) $userId)) && ChatMember::whereRaw('chat_id = ? and user_id = ?', array($chatId, $user->id))->get()->count() == 1) {
                 if ($chat->owner_id != $user->id) {
                     ChatMember::whereRaw('chat_id = ? and user_id = ?', array($chatId, $user->id))->delete();
                     $this->setChatIsUpdated((int) $chatId);
                     return $this->respond(array('chat_id' => $chatId, 'owner_id' => $chat->owner_id, 'topic' => $chat->topic, 'timestamp' => $chat->getTimestamp(), 'users' => $chat->getUsersArray()));
                 } else {
                     return $this->respondWithError('Can\'t exclude chat owner');
                 }
             } else {
                 return $this->respondWithError('User doesn\'t exist');
             }
         } else {
             return $this->respondWithError('Can\'t exclude user from private chat');
         }
     } else {
         return $this->respondWithError('Chat doesn\'t exist');
     }
 }