private function heartbeatParser::remove_message_duplicates in Heartbeat 6.3
Same name and namespace in other branches
- 6.4 includes/heartbeatparser.inc \heartbeatParser::remove_message_duplicates()
- 7 includes/heartbeatparser.inc \heartbeatParser::remove_message_duplicates()
Function to remove duplicate messages meaning remove exactly the same already build messages, incrementing the count of the messages User-user relation always have duplicates that need to be removed. This is handled here as well. Take care: the counter cannot increment! @TODO Refactor this crappy shit
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 85
Class
Code
private function remove_message_duplicates($message_set) {
global $user;
$ow_relations = array();
foreach ($message_set as $key => $message) {
if ($message->concat_args['group_by'] == 'user-user') {
if (!isset($ow_relations[$message->uid_target])) {
$ow_relations[$message->uid_target] = array();
}
// Find bad duplicates in two way relations (5-2 and 2-5)
if (!in_array($message->uid, $ow_relations[$message->uid_target])) {
$ow_relations[$message->uid][] = $message->uid_target;
}
}
}
foreach ($message_set as $key => $message) {
if ($message->concat_args['group_by'] == 'user-user') {
// If i am not the actor, but one of my relations is
// and i am the target for the relation, then
// it is a duplicate message
/*if($this->_info->access == HEARTBEAT_PUBLIC_TO_CONNECTED) {
if($message->uid_target == $user->uid && in_array($message->uid, $user->heartbeat_relations)) {
unset($message_set[$key]);
}
}
if($this->_info->access == HEARTBEAT_PUBLIC_TO_ALL) {
if(!in_array($message->uid, $ow_relations[$message->uid_target])) {
unset($message_set[$key]);
}
}*/
if (!in_array($message->uid, $ow_relations[$message->uid_target])) {
unset($message_set[$key]);
}
}
}
// hash holding all unique values
// if this would be static ...you could do it for all timespan-sets
$holder = array();
foreach ($message_set as $key => $message) {
// if an exact identical message occurs contextual wise,
// then skip it with an incrementation of the frequency
// of the message
$id = $message->message_id . '-' . $message->uid . '-' . $message->uid_target . '-' . $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;
}
}
return $message_set;
}