-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve country flag display feature (#46)
* improve country flag display feature * Apply fixes from StyleCI --------- Co-authored-by: StyleCI Bot <[email protected]>
- Loading branch information
1 parent
aa8c44a
commit 28145c2
Showing
9 changed files
with
117 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import IPInfo from '../forum/models/IPInfo'; | ||
|
||
declare module 'flarum/common/models/Post' { | ||
export default interface Post { | ||
ip_info: () => IPInfo; | ||
} | ||
} | ||
|
||
declare module 'flarum/common/models/User' { | ||
export default interface User { | ||
showIPCountry: () => boolean; | ||
canSeeCountry: () => boolean; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fof/geoip. | ||
* | ||
* Copyright (c) FriendsOfFlarum. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FoF\GeoIP\Api; | ||
|
||
use Flarum\Api\Serializer\BasicUserSerializer; | ||
use Flarum\Settings\SettingsRepositoryInterface; | ||
use Flarum\User\User; | ||
|
||
class BasicUserAttributes | ||
{ | ||
public function __construct( | ||
protected SettingsRepositoryInterface $settings | ||
) { | ||
} | ||
|
||
public function __invoke(BasicUserSerializer $serializer, User $user, array $attributes): array | ||
{ | ||
if ($this->settings->get('fof-geoip.showFlag')) { | ||
$attributes['showIPCountry'] = (bool) $user->getPreference('showIPCountry'); | ||
} | ||
|
||
return $attributes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fof/geoip. | ||
* | ||
* Copyright (c) FriendsOfFlarum. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FoF\GeoIP\Api; | ||
|
||
use Flarum\Api\Serializer\CurrentUserSerializer; | ||
use Flarum\User\User; | ||
|
||
class CurrentUserAttributes | ||
{ | ||
public function __invoke(CurrentUserSerializer $serializer, User $user, array $attributes): array | ||
{ | ||
if ($serializer->getActor()->can('fof-geoip.canSeeCountry')) { | ||
$attributes['canSeeCountry'] = true; | ||
} | ||
|
||
return $attributes; | ||
} | ||
} |