public static function get($userId, $limit, $history = true, $key = null)
{
$query = static::baseQuery($userId);
if (null !== $key) {
$query->andHaving([$history ? '<' : '>', 'last_message_id', $key]);
}
return new DataProvider(['query' => $query, 'key' => 'last_message_id', 'pagination' => ['pageSize' => $limit]]);
}