You are here

private function heartbeatParser::remove_message_duplicates in Heartbeat 6.4

Same name and namespace in other branches
  1. 6.3 includes/heartbeatparser.inc \heartbeatParser::remove_message_duplicates()
  2. 7 includes/heartbeatparser.inc \heartbeatParser::remove_message_duplicates()

Function to remove duplicate messages Duplicate messages whish are exactly the same as already build messages, delete them and increment the count of the message instance Duplicate reversive messages that occur at the same server request time are deleted as well

1 call to heartbeatParser::remove_message_duplicates()
heartbeatParser::prepare_candidates in includes/heartbeatparser.inc
Prepare message candidates This is an important method that handles several things

File

includes/heartbeatparser.inc, line 35
HeartbeatParser object

Class

heartbeatParser
Class heartbeatParser

Code

private function remove_message_duplicates($message_set) {
  global $user;

  // hash holding all unique values
  // if this would be static ...you could do it for all timespan-sets
  $holder = array();
  $duplicates = array();
  $users_relations = array();
  foreach ($message_set as $key => $message) {

    // if an exact identical message occurs > twice contextual wise,
    // then skip it with an incrementation of the frequency
    // of the message. Eg: a node or comment has been edited several times
    // in a too small timespan, then we only show the last one
    $message->template->concat_args['type'] = isset($message->template->concat_args['type']) ? $message->template->concat_args['type'] : 'single';
    if ($message->template->concat_args['type'] != 'single' && ($message->nid > 0 || $message->nid_target > 0)) {
      $id = $message->message_id . '-' . $message->uid . '-' . $message->uid_target . '-' . $message->nid . '-' . $message->nid_target;
      if (in_array($id, $holder)) {
        $message_set[array_search($id, $holder)]->count++;
        unset($message_set[$key]);
      }
      else {
        $holder[$key] = $id;

        //$message->message;
      }
    }

    // Remove duplicates that were created by duplicate user logging
    // This happens when two users were active for the same event
    if (isset($message->variables['duplicate']) && $message->variables['duplicate']) {
      $users_relations[$message->message_id][$message->uid . '-' . $message->uid_target] = array(
        'duplicate' => isset($users_relations[$message->message_id][$message->uid_target . '-' . $message->uid]) ? TRUE : FALSE,
        'uid' => $message->uid,
        'relation' => $message->uid_target,
        'message_id' => $message->message_id,
        'key' => $key,
      );
    }
  }
  if (!empty($users_relations)) {
    foreach ($users_relations as $type => $relations) {

      // Check which of the duplicates should be second
      foreach ($relations as $uid => $relationship) {
        $uid = $relationship['uid'];
        $rel_uid = $relationship['relation'];
        if ($user->uid == $uid && isset($relations[$rel_uid . '-' . $uid])) {
          $duplicates[] = $relations[$rel_uid . '-' . $uid]['key'];
        }
        elseif ($user->uid == $rel_uid) {
          $duplicates[] = $relationship['key'];
        }
        elseif (isset($relations[$rel_uid . '-' . $uid]) && $relationship['duplicate']) {
          $duplicates[] = $relations[$rel_uid . '-' . $uid]['key'];
        }
      }
    }
  }
  $duplicates = array_unique($duplicates);
  foreach ($duplicates as $duplicate_key => $duplicate) {
    unset($message_set[$duplicate]);
  }
  return $message_set;
}