/** * Mark all messages as read or delete all read messages * * <b>Request Type</b>: PUT<br/><br/> * <b>Request Endpoint</b>:http://{server-domain}/api/common/message/update<br/><br/> * <b>Content-type</b>: application/json<br/><br/> * <b>Summary</b>: This api is used for mark all messages as read or delete all read messages * <br/><br/> * * <b>Request Params</b>:<br/> * isRead: integer, the message read status * <br/><br/> * * <b>Response Params:</b><br/> * status: string, update result * <br/><br/> * * <b>Request Example:</b><br/> * <pre> * { * "isRead": 1 * } * </pre> * <br/><br/> * * <b>Response Example</b>:<br/> * <pre> * { * 'status': 'ok' * } * </pre> */ public function actionUpdate() { $token = $this->getAccessToken(); $isRead = (bool) $this->getParams('isRead', false); $tokenInfo = Token::getToken($token); $accountId = $tokenInfo->accountId; $userId = $tokenInfo->userId; $condition = ['accountId' => $accountId, '$or' => [['to.target' => Message::TO_TARGET_ACCOUNT], ['to.target' => Message::TO_TARGET_USER, 'to.id' => $userId]], 'isRead' => $isRead]; if ($isRead) { Message::deleteAll($condition); } else { Message::updateAll(['isRead' => true, 'readAt' => new \MongoDate()], $condition); } return ['status' => 'ok']; }