Activities are now displayed as Emojis

This commit is contained in:
Michael 2023-02-18 06:56:03 +00:00
parent 960fdb9076
commit 608b5a37a4
9 changed files with 264 additions and 70 deletions

View file

@ -979,6 +979,11 @@ class Conversation
$condition['author-hidden'] = false;
}
if ($this->config->get('system', 'emoji_activities')) {
$emojis = $this->getEmojis($uriids);
$condition = DBA::mergeConditions($condition, ["(`gravity` != ? OR `origin`)", ItemModel::GRAVITY_ACTIVITY]);
}
$condition = DBA::mergeConditions($condition,
["`uid` IN (0, ?) AND (NOT `vid` IN (?, ?, ?) OR `vid` IS NULL)", $uid, Verb::getID(Activity::FOLLOW), Verb::getID(Activity::VIEW), Verb::getID(Activity::READ)]);
@ -1081,6 +1086,8 @@ class Conversation
}
foreach ($items as $key => $row) {
$items[$key]['emojis'] = $emojis[$key] ?? [];
$always_display = in_array($mode, [self::MODE_CONTACTS, self::MODE_CONTACT_POSTS]);
$items[$key]['user-blocked-author'] = !$always_display && in_array($row['author-id'], $blocks);
@ -1102,6 +1109,53 @@ class Conversation
return $items;
}
/**
* Fetch emoji reaction from the conversation
*
* @param array $uriids
* @return array
*/
private function getEmojis(array $uriids): array
{
$activity_emoji = [
Activity::LIKE => '👍',
Activity::DISLIKE => '👎',
Activity::ATTEND => '✔️',
Activity::ATTENDMAYBE => '❓',
Activity::ATTENDNO => '❌',
Activity::ANNOUNCE => '♻',
Activity::VIEW => '📺',
];
$index_list = array_values($activity_emoji);
$verbs = array_merge(array_keys($activity_emoji), [Activity::EMOJIREACT]);
$condition = DBA::mergeConditions(['parent-uri-id' => $uriids, 'gravity' => ItemModel::GRAVITY_ACTIVITY, 'verb' => $verbs], ["NOT `deleted`"]);
$separator = chr(255) . chr(255) . chr(255);
$sql = "SELECT `thr-parent-id`, `body`, `verb`, COUNT(*) AS `total`, GROUP_CONCAT(REPLACE(`author-name`, '" . $separator . "', ' ') SEPARATOR '". $separator ."' LIMIT 50) AS `title` FROM `post-view` WHERE " . array_shift($condition) . " GROUP BY `thr-parent-id`, `verb`, `body`";
$emojis = [];
$rows = DBA::p($sql, $condition);
while ($row = DBA::fetch($rows)) {
$row['verb'] = $row['body'] ? Activity::EMOJIREACT : $row['verb'];
$emoji = $row['body'] ?: $activity_emoji[$row['verb']];
if (!isset($index_list[$emoji])) {
$index_list[] = $emoji;
}
$index = array_search($emoji, $index_list);
$emojis[$row['thr-parent-id']][$index]['emoji'] = $emoji;
$emojis[$row['thr-parent-id']][$index]['verb'] = $row['verb'];
$emojis[$row['thr-parent-id']][$index]['total'] = $emojis[$row['thr-parent-id']][$emoji]['total'] ?? 0 + $row['total'];
$emojis[$row['thr-parent-id']][$index]['title'] = array_unique(array_merge($emojis[$row['thr-parent-id']][$emoji]['title'] ?? [], explode($separator, $row['title'])));
}
DBA::close($rows);
return $emojis;
}
/**
* Plucks the children of the given parent from a given item list.
*