Add custom class to views row depending on field value
Can you please try the following code snippet. I swapped the line to retrieve the author's user ID.
/**
 * Implements hook_preprocess_HOOK().
 */
function MYMODULE_preprocess_views_view_unformatted(&amp;$variables) {

  $view = $variables['view'];
  if ($view-&gt;id() == 'MY_VIEW' &amp;&amp; $view-&gt;current_display == 'MY_DISPLAY') {

    $uid = \Drupal::currentUser()-&gt;id();

    $rows = $variables['rows'];
    foreach ($rows as $id =&gt; $row) {

      // Get user ID.
      $owner = $row['content']['#row']-&gt;_entity-&gt;get('uid')-&gt;target_id;

      $class = ($uid == $owner) ? 'own' : 'other';
      $custom_row_class = 'views-row-' . $class;

      $variables['rows'][$id]['attributes']-&gt;addClass($custom_row_class);
    }
  }
}