Skip to content

Commit

Permalink
fix: user preference not retrieved correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Sep 9, 2024
1 parent 08dd53b commit 20f63bb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace FoF\GeoIP;

use Flarum\Api\Controller;
use Flarum\Api\Serializer\BasicUserSerializer;
use Flarum\Api\Serializer\PostSerializer;
use Flarum\Extend;
use Flarum\Frontend\Document;
Expand Down Expand Up @@ -70,6 +71,11 @@
(new Extend\User())
->registerPreference('showIPCountry', 'boolval', false),

(new Extend\ApiSerializer(BasicUserSerializer::class))
->attribute('showIPCountry', function (BasicUserSerializer $serializer, $user) {
return (bool) $user->getPreference('showIPCountry');
}),

(new Extend\Conditional())
->whenExtensionEnabled('fof-default-user-preferences', fn () => [
(new \FoF\DefaultUserPreferences\Extend\RegisterUserPreferenceDefault())
Expand Down
4 changes: 4 additions & 0 deletions js/src/forum/extend.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import Extend from 'flarum/common/extenders';
import IPInfo from './models/IPInfo';
import Post from 'flarum/common/models/Post';
import User from 'flarum/common/models/User';

export default [
new Extend.Store() //
.add('ip_info', IPInfo),

new Extend.Model(Post) //
.hasOne('ip_info'),

new Extend.Model(User) //
.attribute('showIPCountry'),
];
2 changes: 1 addition & 1 deletion js/src/forum/extenders/extendCommentPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function extendCommentPost() {
if (app.forum.attribute<boolean>('fof-geoip.showFlag')) {
const ipInfo = this.attrs.post.ip_info?.();
const postUser = this.attrs.post.user();
if (postUser && postUser?.preferences?.().showIPCountry && ipInfo) {
if (postUser && postUser.showIPCountry() && ipInfo) {
const { image } = getIPData(ipInfo);
if (image) {
items.add('country', image, 100);
Expand Down

0 comments on commit 20f63bb

Please sign in to comment.