Skip to content

Commit

Permalink
Update for Flarum beta 15
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkwinkelmann committed Jan 12, 2021
1 parent 7804e33 commit d2dfa72
Show file tree
Hide file tree
Showing 18 changed files with 779 additions and 829 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Clark Winkelmann
Copyright (c) 2020-2021 Clark Winkelmann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ The list of tags shown in the modal can be customized.
By default, a button to access the modal is also added to the "Following" page.
This can be disabled in the settings.

Another mostly unrelated feature present in this extension is the ability to make the "Following" page display all discussions without filtering for guests instead of showing an empty page.
This is disabled by default.
The extension also contains two other unrelated features:

- Ability to make the "Following" page display all discussions without filtering for guests instead of showing an empty page.
- Ability to make the "Following" page the homepage (under Basics)

Those options are disabled by default.

## Installation

Expand All @@ -32,6 +36,8 @@ You can [contact me](https://clarkwinkelmann.com/flarum) to sponsor additional f

Support is offered on a "best effort" basis through the Flarum community thread.

**Sponsors**: [GitHub Sponsors](https://github.com/sponsors/clarkwinkelmann), [Andrew MacLean](https://andrewdmaclean.com/)

## Links

- [GitHub](https://github.com/clarkwinkelmann/flarum-ext-follow-tags-prompt)
Expand Down
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@
"type": "flarum-extension",
"license": "MIT",
"require": {
"flarum/core": ">=0.1.0-beta.13 <0.1.0-beta.14",
"flarum/core": ">=0.1.0-beta.15 <0.1.0-beta.16",
"flarum/tags": "*",
"fof/follow-tags": ">=0.4.4",
"ext-json": "*"
},
"authors": [
{
"name": "Clark Winkelmann",
"homepage": "https://clarkwinkelmann.com/",
"email": "[email protected]",
"role": "Developer"
}
],
"support": {
"source": "https://github.com/clarkwinkelmann/flarum-ext-follow-tags-prompt"
},
"autoload": {
"psr-4": {
"ClarkWinkelmann\\FollowTagsPrompt\\": "src/"
Expand All @@ -27,6 +31,7 @@
"extra": {
"flarum-extension": {
"title": "Follow Tags Prompt",
"category": "discussion",
"icon": {
"name": "fas fa-user-tag",
"backgroundColor": "#684ba6",
Expand Down
44 changes: 41 additions & 3 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

namespace ClarkWinkelmann\FollowTagsPrompt;

use Carbon\Carbon;
use Flarum\Api\Serializer\ForumSerializer;
use Flarum\Extend;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\Tags\Api\Serializer\TagSerializer;
use Flarum\Tags\Tag;
use Flarum\User\Event\Saving;
use Flarum\User\Exception\PermissionDeniedException;

return [
(new Extend\Frontend('forum'))
Expand All @@ -14,7 +21,38 @@

new Extend\Locales(__DIR__ . '/resources/locale'),

new Extenders\TagAttributes(),
new Extenders\SaveConfigured(),
new Extenders\ForumAttributes(),
(new Extend\ApiSerializer(ForumSerializer::class))
->mutate(function (ForumSerializer $serializer) {
/**
* @var $settings SettingsRepositoryInterface
*/
$settings = app(SettingsRepositoryInterface::class);

$actor = $serializer->getActor();

return [
'clarkwinkelmannFollowTagsPromptAllDiscussionsForGuests' => $settings->get('clarkwinkelmann-follow-tags-prompt.allDiscussionsOnFollowingPageForGuests') === '1',
'clarkwinkelmannFollowTagsPromptButton' => $settings->get('clarkwinkelmann-follow-tags-prompt.buttonOnFollowingPage') !== '0',
'clarkwinkelmannFollowTagsShouldPrompt' => $actor->exists && is_null($actor->clarkwinkelmann_follow_tags_configured_at),
];
}),

(new Extend\ApiSerializer(TagSerializer::class))
->attribute('clarkwinkelmannFollowTagsPromptAvailable', function (TagSerializer $serializer, Tag $tag) {
return AvailableTagsStrategy::isAvailable($tag);
}),

(new Extend\Event())
->listen(Saving::class, function (Saving $event) {
if (isset($event->data['attributes']['followTagsConfigured'])) {
// Not using a permission because we want this to work even for unconfirmed or suspended users
if ($event->actor->id !== $event->user->id) {
throw new PermissionDeniedException();
}

if (is_null($event->user->clarkwinkelmann_follow_tags_configured_at)) {
$event->user->clarkwinkelmann_follow_tags_configured_at = Carbon::now();
}
}
}),
];
2 changes: 1 addition & 1 deletion js/dist/admin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d2dfa72

Please sign in to comment.