Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show legacy forum icons on topic listing, posts, and post search #11277

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/Libraries/Search/ForumSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ public function data()
return $this->response();
}

/**
* @return Builder<Post>
*/
public function posts(): Builder
{
return Post::withTrashed()->whereKey($this->response()->ids('post_id'));
}

/**
* Returns a Builder for a Collection of all the posts that appeared in this query.
*/
Expand Down
26 changes: 26 additions & 0 deletions app/Models/Forum/LegacyIcon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

namespace App\Models\Forum;

/**
* Icons used to label various models from phpBB. On the old website, they were
* available for use, but now they are read-only.
*
* @property bool $display_on_posting
* @property int $icons_height
* @property int $icons_id
* @property int $icons_order
* @property string $icons_url
* @property int $icons_width
*/
class LegacyIcon extends Model
{
public $timestamps = false;

protected $casts = ['display_on_posting' => 'boolean'];
protected $primaryKey = 'icons_id';
protected $table = 'phpbb_icons';
}
12 changes: 12 additions & 0 deletions app/Models/Forum/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,18 @@ public function isBeatmapsetPost()
}
}

public function legacyIcon(): ?LegacyIcon
{
// TODO: $this->icon_id shouldn't be null, but there are some cases
// where we make a new Post model and don't refresh it with the default
// attributes from database
if ($this->icon_id === null) {
return null;
}

return app('forum-legacy-icons')->byId($this->icon_id);
}

public function validationErrorsTranslationPrefix(): string
{
return 'forum.post';
Expand Down
5 changes: 5 additions & 0 deletions app/Models/Forum/Topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,11 @@ public function isActive()
return $this->topic_last_post_time > Carbon::now()->subMonths($GLOBALS['cfg']['osu']['forum']['necropost_months']);
}

public function legacyIcon(): ?LegacyIcon
{
return app('forum-legacy-icons')->byId($this->icon_id);
}

public function markRead($user, $markTime)
{
if ($user === null) {
Expand Down
1 change: 1 addition & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class AppServiceProvider extends ServiceProvider
const LOCAL_CACHE_SINGLETONS = [
'chat-filters' => Singletons\ChatFilters::class,
'countries' => Singletons\Countries::class,
'forum-legacy-icons' => Singletons\ForumLegacyIcons::class,
'groups' => Singletons\Groups::class,
'layout-cache' => Singletons\LayoutCache::class,
'medals' => Singletons\Medals::class,
Expand Down
33 changes: 33 additions & 0 deletions app/Singletons/ForumLegacyIcons.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

namespace App\Singletons;

use App\Models\Forum\LegacyIcon;
use App\Traits\Memoizes;
use Illuminate\Database\Eloquent\Collection;

class ForumLegacyIcons
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't seem it's used frequently enough to warrant this (and all the usage seems involve querying the post/topic)

{
use Memoizes;

/**
* Get a legacy forum icon by its ID.
*/
public function byId(int $id): ?LegacyIcon
{
return $this->allById()->get($id);
}

/**
* @return Collection<int, LegacyIcon>
*/
private function allById(): Collection
{
return $this->memoize(__FUNCTION__, fn () => LegacyIcon::all()->keyBy('icons_id'));
}
}
7 changes: 6 additions & 1 deletion app/Traits/Memoizes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ public function resetMemoized(): void
$this->memoized = [];
}

protected function memoize(string $key, callable $function)
/**
* @template TReturn
* @param callable(): TReturn $function
* @return TReturn
*/
protected function memoize(string $key, callable $function): mixed
{
if (!array_key_exists($key, $this->memoized)) {
$this->memoized[$key] = $function();
Expand Down
1 change: 1 addition & 0 deletions config/osu.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@
'bounty-form' => env('OS_BOUNTY_URL'),
'dev' => 'https://discord.gg/ppy',
'experimental_host' => presence(env('OSU_EXPERIMENTAL_HOST')),
'forum_legacy_icons' => 'https://old.ppy.sh/forum/images/icons',
'installer' => 'https://m1.ppy.sh/r/osu!install.exe',
'installer-mirror' => 'https://m2.ppy.sh/r/osu!install.exe',
'lazer_dl.android' => presence(env('OSU_URL_LAZER_ANDROID')) ?? 'https://github.com/ppy/osu/releases/latest/download/sh.ppy.osulazer.apk',
Expand Down
42 changes: 42 additions & 0 deletions database/migrations/2024_06_17_203000_create_phpbb_icons.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
if (Schema::hasTable('phpbb_icons')) {
return;
}

Schema::create('phpbb_icons', function (Blueprint $table) {
$table->mediumIncrements('icons_id');
$table->string('icons_url')->default('');
$table->tinyInteger('icons_width')->default(0);
$table->tinyInteger('icons_height')->default(0);
$table->unsignedMediumInteger('icons_order')->default(0);
$table->boolean('display_on_posting')->default(true);

$table->index(['display_on_posting'], 'display_on_posting');
Comment on lines +24 to +31
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could use a double-check for accuracy bc I just copied thsi from phpbb3.0

});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::drop('phpbb_icons');
}
};
1 change: 1 addition & 0 deletions resources/css/bem-index.less
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
@import "bem/forum-issue-icon";
@import "bem/forum-item";
@import "bem/forum-item-stripe";
@import "bem/forum-legacy-icon";
@import "bem/forum-list";
@import "bem/forum-poll";
@import "bem/forum-poll-container";
Expand Down
6 changes: 6 additions & 0 deletions resources/css/bem/forum-legacy-icon.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

.forum-legacy-icon {
margin: 0 5px;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can use gap on __icons instead

}
3 changes: 2 additions & 1 deletion resources/css/bem/forum-topic-entry.less
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@
}
}

&__issue-icons {
&__icons {
align-items: center;
flex: none;
display: flex;
padding: 5px 5px 0;
Expand Down
2 changes: 2 additions & 0 deletions resources/css/bem/search-forum-post.less
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
.search-forum-post {
@avatar-size: 50px;
@margin: 5px;

align-items: center;
display: flex;
flex-direction: row;
flex-wrap: wrap;
Expand Down
11 changes: 11 additions & 0 deletions resources/views/forum/_legacy_icon.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{--
Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
See the LICENCE file in the repository root for full licence text.
--}}
<img
alt=""
class="forum-legacy-icon"
src="{{ osu_url('forum_legacy_icons') }}/{{ $icon->icons_url }}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the url generation should be the icon's method

width="{{ $icon->icons_width }}"
height="{{ $icon->icons_height }}"
/>
6 changes: 5 additions & 1 deletion resources/views/forum/forums/_topic.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ class="
</div>
</div>

<div class="forum-topic-entry__issue-icons">
<div class="forum-topic-entry__icons">
@if ($topic->legacyIcon() !== null)
@include('forum._legacy_icon', ['icon' => $topic->legacyIcon()])
@endif

@foreach ($topic->issueTags() as $tag)
<div
title="{{ $tag }}"
Expand Down
6 changes: 6 additions & 0 deletions resources/views/forum/topics/_post.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ class="js-forum-post {{ $hidden ? 'js-forum-post--hidden' : '' }} forum-post"
{!! timeago($post->post_time) !!}
</a>
</div>

@if ($post->legacyIcon() !== null)
<div class="forum-post__header-content-item">
@include('forum._legacy_icon', ['icon' => $post->legacyIcon()])
</div>
@endif
</div>

@if (count($buttons) > 0)
Expand Down
3 changes: 3 additions & 0 deletions resources/views/home/_search_result_forum_post.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
--}}
{{-- more code than template in this view :best: --}}
@php
$posts = $search->posts()->select('post_id', 'icon_id')->get()->keyBy('post_id');
$users = $search->users()->select('user_id', 'username', 'user_avatar')->get()->keyBy('user_id');
$topics = $search->topics()->with('forum')->get()->keyBy('topic_id');
$skipTitle = $search->isTopicSpecificSearch();
Expand All @@ -12,6 +13,7 @@
@foreach ($search->data() as $entry)
@php
// $entry should be of type App\Libraries\Elasticsearch\Hit
$post = $posts[$entry->source('post_id')];
$postUrl = post_url($entry->source('topic_id'), $entry->source('post_id'));
$postId = $entry->source('post_id');
$topic = $topics[$entry->source('topic_id')] ?? new App\Models\Forum\Topic();
Expand All @@ -25,6 +27,7 @@
@endphp
<div class="{{ class_with_modifiers('search-entry', ['deleted' => $entry->source('is_deleted')]) }}">
@include('objects.search._forum_post', [
'post' => $post,
'user' => $user,
'title' => $title,
'link' => $postUrl,
Expand Down
5 changes: 5 additions & 0 deletions resources/views/objects/search/_forum_post.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
>
<img class="search-forum-post__avatar-image" src="{{ $user->user_avatar }}">
</a>

@if ($post->legacyIcon() !== null)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a good place to put the icon. It just looks wrong

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Icons should go before or after the title, or in the information lines at the bottom, imo. It should definitely not be shifting the layout of entire blocks.

@include('forum._legacy_icon', ['icon' => $post->legacyIcon()])
@endif

<div class="search-forum-post__content">
@if (isset($title))
<div class="search-forum-post__text search-forum-post__text--title">
Expand Down