. * */ namespace Friendica\Module\Api\Friendica\DirectMessages; use Friendica\Database\DBA; use Friendica\Module\BaseApi; /** * API endpoint: /api/friendica/direct_messages_setseen */ class Setseen extends BaseApi { public static function rawContent(array $parameters = []) { self::checkAllowedScope(self::SCOPE_WRITE); $uid = self::getCurrentUserID(); $request = self::getRequest([ 'id' => 0, // Id of the direct message ]); // return error if id is zero if (empty($request['id'])) { $answer = ['result' => 'error', 'message' => 'message id not specified']; self::exit('direct_messages_setseen', ['$result' => $answer], $parameters['extension'] ?? null); } // error message if specified id is not in database if (!DBA::exists('mail', ['id' => $request['id'], 'uid' => $uid])) { $answer = ['result' => 'error', 'message' => 'message id not in database']; self::exit('direct_messages_setseen', ['$result' => $answer], $parameters['extension'] ?? null); } // update seen indicator $result = DBA::update('mail', ['seen' => true], ['id' => $request['id']]); if ($result) { // return success $answer = ['result' => 'ok', 'message' => 'message set to seen']; self::exit('direct_messages_setseen', ['$result' => $answer], $parameters['extension'] ?? null); } else { $answer = ['result' => 'error', 'message' => 'unknown error']; self::exit('direct_messages_setseen', ['$result' => $answer], $parameters['extension'] ?? null); } } }