mirror of
https://github.com/friendica/friendica
synced 2025-04-23 10:30:11 +00:00
Activities are now displayed as Emojis
This commit is contained in:
parent
960fdb9076
commit
608b5a37a4
9 changed files with 264 additions and 70 deletions
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -534,6 +534,7 @@ class Post
|
|||
'vote' => $buttons,
|
||||
'like_html' => $responses['like']['output'],
|
||||
'dislike_html' => $responses['dislike']['output'],
|
||||
'emojis' => $this->getEmojis($item),
|
||||
'responses' => $responses,
|
||||
'switchcomment' => DI::l10n()->t('Comment'),
|
||||
'reply_label' => DI::l10n()->t('Reply to %s', $profile_name),
|
||||
|
@ -602,6 +603,70 @@ class Post
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch emojis
|
||||
*
|
||||
* @param array $item
|
||||
* @return array
|
||||
*/
|
||||
private function getEmojis(array $item): array
|
||||
{
|
||||
if (empty($item['emojis'])) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$emojis = [];
|
||||
foreach ($item['emojis'] as $index => $element) {
|
||||
$actors = implode(', ', $element['title']);
|
||||
switch ($element['verb']) {
|
||||
case Activity::ANNOUNCE:
|
||||
$title = DI::l10n()->t('Reshared by: %s', $actors);
|
||||
$icon = ['fa' => 'fa-retweet', 'icon' => 'icon-retweet'];
|
||||
break;
|
||||
|
||||
case Activity::VIEW:
|
||||
$title = DI::l10n()->t('Viewed by: %s', $actors);
|
||||
$icon = ['fa' => 'fa-eye', 'icon' => 'icon-eye-open'];
|
||||
break;
|
||||
|
||||
case Activity::LIKE:
|
||||
$title = DI::l10n()->t('Liked by: %s', $actors);
|
||||
$icon = ['fa' => 'fa-thumbs-up', 'icon' => 'icon-thumbs-up'];
|
||||
break;
|
||||
|
||||
case Activity::DISLIKE:
|
||||
$title = DI::l10n()->t('Disliked by: %s', $actors);
|
||||
$icon = ['fa' => 'fa-thumbs-down', 'icon' => 'icon-thumbs-down'];
|
||||
break;
|
||||
|
||||
case Activity::ATTEND:
|
||||
$title = DI::l10n()->t('Attended by: %s', $actors);
|
||||
$icon = ['fa' => 'fa-check', 'icon' => 'icon-ok'];
|
||||
break;
|
||||
|
||||
case Activity::ATTENDMAYBE:
|
||||
$title = DI::l10n()->t('Maybe attended by: %s', $actors);
|
||||
$icon = ['fa' => 'fa-question', 'icon' => 'icon-question'];
|
||||
break;
|
||||
|
||||
case Activity::ATTENDNO:
|
||||
$title = DI::l10n()->t('Not attended by: %s', $actors);
|
||||
$icon = ['fa' => 'fa-times', 'icon' => 'icon-remove'];
|
||||
break;
|
||||
|
||||
default:
|
||||
$title = DI::l10n()->t('Reacted with %s by: %s', $element['emoji'], $actors);
|
||||
$icon = [];
|
||||
break;
|
||||
break;
|
||||
}
|
||||
$emojis[$index] = ['emoji' => $element['emoji'], 'total' => $element['total'], 'title' => $title, 'icon' => $icon];
|
||||
}
|
||||
ksort($emojis);
|
||||
|
||||
return $emojis;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue