From 2d30d912cd013d05993560a6c8f8e5807ff16327 Mon Sep 17 00:00:00 2001 From: Ian Morland Date: Wed, 26 May 2021 22:06:37 +0100 Subject: [PATCH] Flarum 1.0 (#4) * Update for 1.0 * Rename filterer to better reflect its purpose * Apply fixes from StyleCI * Add is:followeduser gambit, integrate filter into fof/user-directory * Apply fixes from StyleCI * Correct negate query * Apply fixes from StyleCI * Add screenshot for user-directory integration Co-authored-by: Ian Morland --- LICENSE.md | 2 +- README.md | 11 ++- composer.json | 9 ++- extend.php | 12 ++- js/package-lock.json | 51 +++++++----- js/package.json | 2 +- js/src/admin/index.js | 2 +- js/src/forum/addFollowingUsers.js | 31 ++++++++ js/webpack.config.js | 2 +- ..._00_000000_create_user_followers_table.php | 2 +- ...0_00_00_000001_set_default_permissions.php | 2 +- resources/locale/en.yml | 3 + src/Access/UserPolicy.php | 2 +- src/Events/Following.php | 2 +- src/Events/Unfollowing.php | 2 +- ...endNotificationWhenDiscussionIsStarted.php | 2 +- .../SendNotificationWhenFollowerPosted.php | 2 +- .../SendNotificationWhenUserIsFollowed.php | 2 +- .../SendNotificationWhenUserIsUnfollowed.php | 2 +- ...icationWhenDiscussionIsHiddenOrDeleted.php | 2 +- src/Listeners/QueueNotificationJobs.php | 8 +- ...reNotificationWhenDiscussionIsRestored.php | 2 +- src/Listeners/SaveFollowedToDatabase.php | 2 +- src/Notifications/NewDiscussionBlueprint.php | 2 +- src/Notifications/NewFollowerBlueprint.php | 2 +- src/Notifications/NewPostByUserBlueprint.php | 2 +- src/Notifications/NewUnfollowerBlueprint.php | 2 +- ...er.php => FollowUsersDiscussionFilter.php} | 4 +- src/Query/FollowedUsersFilterGambit.php | 79 +++++++++++++++++++ 29 files changed, 192 insertions(+), 56 deletions(-) rename src/Query/{FollowUsersFilter.php => FollowUsersDiscussionFilter.php} (93%) create mode 100644 src/Query/FollowedUsersFilterGambit.php diff --git a/LICENSE.md b/LICENSE.md index 5b64105..9789c79 100755 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Ian Morland +Copyright (c) 2021 Ian Morland Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/README.md b/README.md index affd391..31b7aea 100755 --- a/README.md +++ b/README.md @@ -7,12 +7,14 @@ A [Flarum](http://flarum.org) extension. Follow users and be notified of new dis Building on top of `fof/follow-tags`, this extension allows for following of individual users. ### Features -- Requires Flarum beta 15 or above - Adds a 'Followed User' badge to users that _you_ follow, forum wide - Adds A 'Followed Users' filter to the following filter - Permission for which groups can be followed - User preference to block followers - Notifications for 'Followed', 'Unfollowed', 'Followed User Started Discussion' and 'Followed User Posted' +- Integration with `fof/user-directory` +- Provides a search gambit `is:followeduser` +- [Developers] events dispatched for `Following` and `Unfollowing` ##### Discussion list ![image](https://user-images.githubusercontent.com/16573496/102770472-2161df00-437c-11eb-8274-6f73d58b1042.png) @@ -20,6 +22,9 @@ Building on top of `fof/follow-tags`, this extension allows for following of ind ##### Following dropdown ![image](https://user-images.githubusercontent.com/16573496/102770549-40f90780-437c-11eb-801e-a7fb9e08e704.png) +##### `fof/user-directory` integration +![image](https://user-images.githubusercontent.com/16573496/119695069-ba25ea80-be45-11eb-9f0e-ff7545f29261.png) + ##### Notification preferences ![image](https://user-images.githubusercontent.com/16573496/102770611-55d59b00-437c-11eb-8d57-408770c34d69.png) @@ -28,10 +33,10 @@ Building on top of `fof/follow-tags`, this extension allows for following of ind ### Installation -Install manually with composer: +Install with composer: ```sh -composer require ianm/follow-users +composer require ianm/follow-users:"*" ``` `fof/follow-tags` *must* be enabled *before* this extension is enabled. diff --git a/composer.json b/composer.json index 575e7ec..2a36dfb 100755 --- a/composer.json +++ b/composer.json @@ -12,8 +12,8 @@ "forum": "https://discuss.flarum.org/d/25701" }, "require": { - "flarum/core": "^0.1.0-beta.16", - "fof/follow-tags": "^0.7.1" + "flarum/core": "^1.0.0", + "fof/follow-tags": "^1.0.0" }, "authors": [ { @@ -29,7 +29,7 @@ }, "extra": { "flarum-extension": { - "title": "IM Follow Users", + "title": "Follow Users", "category": "feature", "icon": { "name": "fas fa-user-friends", @@ -37,7 +37,8 @@ "color": "#fff" }, "optional-dependencies": [ - "fof/follow-tags" + "fof/follow-tags", + "fof/user-directory" ] }, "flagrow": { diff --git a/extend.php b/extend.php index bbad8c0..d10ec08 100755 --- a/extend.php +++ b/extend.php @@ -3,7 +3,7 @@ /* * This file is part of ianm/follow-users * - * Copyright (c) 2020 Ian Morland. + * Copyright (c) Ian Morland. * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. @@ -23,6 +23,8 @@ use Flarum\Discussion\Filter\DiscussionFilterer; use Flarum\Extend; use Flarum\User\Event\Saving; +use Flarum\User\Filter\UserFilterer; +use Flarum\User\Search\UserSearcher; use Flarum\User\User; return [ @@ -62,7 +64,13 @@ ->subscribe(Listeners\QueueNotificationJobs::class), (new Extend\Filter(DiscussionFilterer::class)) - ->addFilter(Query\FollowUsersFilter::class), + ->addFilter(Query\FollowUsersDiscussionFilter::class), + + (new Extend\Filter(UserFilterer::class)) + ->addFilter(Query\FollowedUsersFilterGambit::class), + + (new Extend\SimpleFlarumSearch(UserSearcher::class)) + ->addGambit(Query\FollowedUsersFilterGambit::class), (new Extend\User()) ->registerPreference('blocksFollow', 'boolval', false), diff --git a/js/package-lock.json b/js/package-lock.json index 0812a3c..2a4b728 100755 --- a/js/package-lock.json +++ b/js/package-lock.json @@ -1387,13 +1387,15 @@ } }, "browserslist": { - "version": "4.6.3", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.6.3.tgz", - "integrity": "sha512-CNBqTCq22RKM8wKJNowcqihHJ4SkI8CGeK7KOR9tPboXUuS5Zk5lQgzzTbs4oxD8x+6HUshZUa2OyNI9lR93bQ==", + "version": "4.16.6", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.16.6.tgz", + "integrity": "sha512-Wspk/PqO+4W9qp5iUTJsa1B/QrYn1keNCcEP5OvP7WBwT4KaDly0uONYmC6Xa3Z5IqnUgS0KcgLYu1l74x0ZXQ==", "requires": { - "caniuse-lite": "^1.0.30000975", - "electron-to-chromium": "^1.3.164", - "node-releases": "^1.1.23" + "caniuse-lite": "^1.0.30001219", + "colorette": "^1.2.2", + "electron-to-chromium": "^1.3.723", + "escalade": "^3.1.1", + "node-releases": "^1.1.71" } }, "buffer": { @@ -1465,9 +1467,9 @@ "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==" }, "caniuse-lite": { - "version": "1.0.30000975", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000975.tgz", - "integrity": "sha512-ZsXA9YWQX6ATu5MNg+Vx/cMQ+hM6vBBSqDeJs8ruk9z0ky4yIHML15MoxcFt088ST2uyjgqyUGRJButkptWf0w==" + "version": "1.0.30001230", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001230.tgz", + "integrity": "sha512-5yBd5nWCBS+jWKTcHOzXwo5xzcj4ePE/yjtkZyUV1BTUmrBaA9MRGC+e7mxnqXSA90CmCA8L3eKLaSUkt099IQ==" }, "chalk": { "version": "2.4.2", @@ -1605,6 +1607,11 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" }, + "colorette": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/colorette/-/colorette-1.2.2.tgz", + "integrity": "sha512-MKGMzyfeuutC/ZJ1cba9NqcNpfeqMUcYmyF1ZFY6/Cn7CNSAKx6a+s48sqLqyAiZuaP2TcqMhoo+dlwFnVxT9w==" + }, "commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", @@ -1878,9 +1885,9 @@ } }, "electron-to-chromium": { - "version": "1.3.165", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.165.tgz", - "integrity": "sha512-iIS8axR524EAnvUtWUNnREnYjQrS0zUvutIKYgTVuN3MzcjrV31EuJYKw7DGOtFO9DQw+JiXeaVDPQWMskG1wQ==" + "version": "1.3.739", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.739.tgz", + "integrity": "sha512-+LPJVRsN7hGZ9EIUUiWCpO7l4E3qBYHNadazlucBfsXBbccDFNKUBAgzE68FnkWGJPwD/AfKhSzL+G+Iqb8A4A==" }, "elliptic": { "version": "6.5.4", @@ -1950,6 +1957,11 @@ "prr": "~1.0.1" } }, + "escalade": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", + "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==" + }, "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", @@ -2964,12 +2976,9 @@ } }, "node-releases": { - "version": "1.1.23", - "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.23.tgz", - "integrity": "sha512-uq1iL79YjfYC0WXoHbC/z28q/9pOl8kSHaXdWmAAc8No+bDwqkZbzIJz55g/MUsPgSGm9LZ7QSUbzTcH5tz47w==", - "requires": { - "semver": "^5.3.0" - } + "version": "1.1.72", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.72.tgz", + "integrity": "sha512-LLUo+PpH3dU6XizX3iVoubUNheF/owjXCZZ5yACDxNnPtgFuludV1ZL3ayK1kVep42Rmm0+R9/Y60NQbZ2bifw==" }, "normalize-path": { "version": "3.0.0", @@ -3165,9 +3174,9 @@ "integrity": "sha1-AerA/jta9xoqbAL+q7jB/vfgDqs=" }, "prettier": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.2.1.tgz", - "integrity": "sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.3.0.tgz", + "integrity": "sha512-kXtO4s0Lz/DW/IJ9QdWhAf7/NmPWQXkFr/r/WkR3vyI+0v8amTDxiaQSLzs8NBlytfLWX/7uQUMIW677yLKl4w==", "dev": true }, "private": { diff --git a/js/package.json b/js/package.json index 3f4d6f7..79f8b41 100755 --- a/js/package.json +++ b/js/package.json @@ -14,6 +14,6 @@ }, "devDependencies": { "flarum": "0.1.0-beta.16", - "prettier": "^2.2.1" + "prettier": "^2.3.0" } } diff --git a/js/src/admin/index.js b/js/src/admin/index.js index 076fb99..bb637f7 100755 --- a/js/src/admin/index.js +++ b/js/src/admin/index.js @@ -1,4 +1,4 @@ -import app from 'flarum/app'; +import app from 'flarum/common/app'; import * as follow_tags from '@fof-follow-tags'; import followingPageOptions from '../common/helpers/followingPageOptions'; diff --git a/js/src/forum/addFollowingUsers.js b/js/src/forum/addFollowingUsers.js index e0710be..ffc8983 100644 --- a/js/src/forum/addFollowingUsers.js +++ b/js/src/forum/addFollowingUsers.js @@ -1,7 +1,9 @@ import { extend } from 'flarum/common/extend'; import * as follow_tags from '@fof-follow-tags'; +import * as user_directory from '@fof-user-directory'; import DiscussionListState from 'flarum/common/states/DiscussionListState'; import followingPageOptions from '../common/helpers/followingPageOptions'; +import Separator from 'flarum/common/components/Separator'; export default function () { if (app.initializers.has('fof/follow-tags')) { @@ -26,4 +28,33 @@ export default function () { } }); } + + if (app.initializers.has('fof-user-directory')) { + extend(user_directory.UserDirectoryPage.prototype, 'groupItems', function (items) { + items.add( + 'follow-users', + user_directory.CheckableButton.component( + { + className: 'GroupFilterButton', + icon: 'fas fa-user-friends', + checked: this.enabledSpecialGroupFilters['ianm-follow-users'] === 'is:followeduser', + onclick: () => { + const id = 'ianm-follow-users'; + if (this.enabledSpecialGroupFilters[id] === 'is:followeduser') { + this.enabledSpecialGroupFilters[id] = ''; + } else { + this.enabledSpecialGroupFilters[id] = 'is:followeduser'; + } + + this.changeParams(this.params().sort); + }, + }, + app.translator.trans('ianm-follow-users.forum.filter.following') + ), + 65 + ); + + items.add('seperator', Separator.component(), 50); + }); + } } diff --git a/js/webpack.config.js b/js/webpack.config.js index 79275df..754d74a 100755 --- a/js/webpack.config.js +++ b/js/webpack.config.js @@ -1,5 +1,5 @@ const config = require('flarum-webpack-config')({ - useExtensions: ['fof-follow-tags'] + useExtensions: ['fof-follow-tags', 'fof-user-directory'] }); module.exports = config; diff --git a/migrations/0000_00_00_000000_create_user_followers_table.php b/migrations/0000_00_00_000000_create_user_followers_table.php index 46e0b88..5f71fec 100755 --- a/migrations/0000_00_00_000000_create_user_followers_table.php +++ b/migrations/0000_00_00_000000_create_user_followers_table.php @@ -3,7 +3,7 @@ /* * This file is part of ianm/follow-users * - * Copyright (c) 2020 Ian Morland. + * Copyright (c) Ian Morland. * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. diff --git a/migrations/0000_00_00_000001_set_default_permissions.php b/migrations/0000_00_00_000001_set_default_permissions.php index 39d7f4a..311031a 100755 --- a/migrations/0000_00_00_000001_set_default_permissions.php +++ b/migrations/0000_00_00_000001_set_default_permissions.php @@ -3,7 +3,7 @@ /* * This file is part of ianm/follow-users * - * Copyright (c) 2020 Ian Morland. + * Copyright (c) Ian Morland. * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. diff --git a/resources/locale/en.yml b/resources/locale/en.yml index 1c912a7..8bf6037 100755 --- a/resources/locale/en.yml +++ b/resources/locale/en.yml @@ -32,6 +32,9 @@ ianm-follow-users: badge: label: Followed user + filter: + following: Followed users + email: new_discussion_by_user_subject: "[Follow User] {title}" new_follower_subject: "[Follow User] You have a new follower!" diff --git a/src/Access/UserPolicy.php b/src/Access/UserPolicy.php index 37c8321..be171b5 100755 --- a/src/Access/UserPolicy.php +++ b/src/Access/UserPolicy.php @@ -3,7 +3,7 @@ /* * This file is part of ianm/follow-users * - * Copyright (c) 2020 Ian Morland. + * Copyright (c) Ian Morland. * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. diff --git a/src/Events/Following.php b/src/Events/Following.php index 42ec06d..724bb33 100755 --- a/src/Events/Following.php +++ b/src/Events/Following.php @@ -3,7 +3,7 @@ /* * This file is part of ianm/follow-users * - * Copyright (c) 2020 Ian Morland. + * Copyright (c) Ian Morland. * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. diff --git a/src/Events/Unfollowing.php b/src/Events/Unfollowing.php index c522435..79ef387 100755 --- a/src/Events/Unfollowing.php +++ b/src/Events/Unfollowing.php @@ -3,7 +3,7 @@ /* * This file is part of ianm/follow-users * - * Copyright (c) 2020 Ian Morland. + * Copyright (c) Ian Morland. * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. diff --git a/src/Jobs/SendNotificationWhenDiscussionIsStarted.php b/src/Jobs/SendNotificationWhenDiscussionIsStarted.php index 2f20d79..6bc0e00 100755 --- a/src/Jobs/SendNotificationWhenDiscussionIsStarted.php +++ b/src/Jobs/SendNotificationWhenDiscussionIsStarted.php @@ -3,7 +3,7 @@ /* * This file is part of ianm/follow-users * - * Copyright (c) 2020 Ian Morland. + * Copyright (c) Ian Morland. * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. diff --git a/src/Jobs/SendNotificationWhenFollowerPosted.php b/src/Jobs/SendNotificationWhenFollowerPosted.php index e2ee01a..79a588b 100755 --- a/src/Jobs/SendNotificationWhenFollowerPosted.php +++ b/src/Jobs/SendNotificationWhenFollowerPosted.php @@ -3,7 +3,7 @@ /* * This file is part of ianm/follow-users * - * Copyright (c) 2020 Ian Morland. + * Copyright (c) Ian Morland. * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. diff --git a/src/Jobs/SendNotificationWhenUserIsFollowed.php b/src/Jobs/SendNotificationWhenUserIsFollowed.php index b17b448..5d5fe20 100755 --- a/src/Jobs/SendNotificationWhenUserIsFollowed.php +++ b/src/Jobs/SendNotificationWhenUserIsFollowed.php @@ -3,7 +3,7 @@ /* * This file is part of ianm/follow-users * - * Copyright (c) 2020 Ian Morland. + * Copyright (c) Ian Morland. * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. diff --git a/src/Jobs/SendNotificationWhenUserIsUnfollowed.php b/src/Jobs/SendNotificationWhenUserIsUnfollowed.php index ebbad7d..7c94610 100755 --- a/src/Jobs/SendNotificationWhenUserIsUnfollowed.php +++ b/src/Jobs/SendNotificationWhenUserIsUnfollowed.php @@ -3,7 +3,7 @@ /* * This file is part of ianm/follow-users * - * Copyright (c) 2020 Ian Morland. + * Copyright (c) Ian Morland. * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. diff --git a/src/Listeners/DeleteNotificationWhenDiscussionIsHiddenOrDeleted.php b/src/Listeners/DeleteNotificationWhenDiscussionIsHiddenOrDeleted.php index f722e3f..fcd6d14 100755 --- a/src/Listeners/DeleteNotificationWhenDiscussionIsHiddenOrDeleted.php +++ b/src/Listeners/DeleteNotificationWhenDiscussionIsHiddenOrDeleted.php @@ -3,7 +3,7 @@ /* * This file is part of ianm/follow-users * - * Copyright (c) 2020 Ian Morland. + * Copyright (c) Ian Morland. * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. diff --git a/src/Listeners/QueueNotificationJobs.php b/src/Listeners/QueueNotificationJobs.php index 775c62f..71a823b 100755 --- a/src/Listeners/QueueNotificationJobs.php +++ b/src/Listeners/QueueNotificationJobs.php @@ -3,7 +3,7 @@ /* * This file is part of ianm/follow-users * - * Copyright (c) 2020 Ian Morland. + * Copyright (c) Ian Morland. * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. @@ -15,7 +15,7 @@ use Flarum\Approval\Event\PostWasApproved; use Flarum\Discussion\Discussion; use Flarum\Discussion\Event\Started; -use Flarum\Post\Event\Posted; +use Flarum\Post\Event\Saving as PostSaving; use Flarum\Post\Post; use IanM\FollowUsers\Events\Following; use IanM\FollowUsers\Events\Unfollowing; @@ -29,7 +29,7 @@ public function subscribe(Dispatcher $events) $events->listen(Following::class, [$this, 'whenFollowed']); $events->listen(Unfollowing::class, [$this, 'whenUnfollowed']); $events->listen(Started::class, [$this, 'whenDiscussionStarted']); - $events->listen(Posted::class, [$this, 'whenPostCreated']); + $events->listen(PostSaving::class, [$this, 'whenPostCreated']); //$events->listen(PostWasApproved::class, [$this, 'whenPostApproved']); } @@ -56,7 +56,7 @@ public function whenDiscussionStarted(Started $event) }); } - public function whenPostCreated(Posted $event) + public function whenPostCreated(PostSaving $event) { $event->post->afterSave(function (Post $post) { if (!$post->exists || !$post->discussion->exists || $post->number == 1) { diff --git a/src/Listeners/RestoreNotificationWhenDiscussionIsRestored.php b/src/Listeners/RestoreNotificationWhenDiscussionIsRestored.php index 838c886..a3ffa3c 100755 --- a/src/Listeners/RestoreNotificationWhenDiscussionIsRestored.php +++ b/src/Listeners/RestoreNotificationWhenDiscussionIsRestored.php @@ -3,7 +3,7 @@ /* * This file is part of ianm/follow-users * - * Copyright (c) 2020 Ian Morland. + * Copyright (c) Ian Morland. * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. diff --git a/src/Listeners/SaveFollowedToDatabase.php b/src/Listeners/SaveFollowedToDatabase.php index 9493904..3f7357b 100755 --- a/src/Listeners/SaveFollowedToDatabase.php +++ b/src/Listeners/SaveFollowedToDatabase.php @@ -3,7 +3,7 @@ /* * This file is part of ianm/follow-users * - * Copyright (c) 2020 Ian Morland. + * Copyright (c) Ian Morland. * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. diff --git a/src/Notifications/NewDiscussionBlueprint.php b/src/Notifications/NewDiscussionBlueprint.php index 249063e..2a4a7db 100755 --- a/src/Notifications/NewDiscussionBlueprint.php +++ b/src/Notifications/NewDiscussionBlueprint.php @@ -3,7 +3,7 @@ /* * This file is part of ianm/follow-users * - * Copyright (c) 2020 Ian Morland. + * Copyright (c) Ian Morland. * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. diff --git a/src/Notifications/NewFollowerBlueprint.php b/src/Notifications/NewFollowerBlueprint.php index 01cc425..c6fa833 100755 --- a/src/Notifications/NewFollowerBlueprint.php +++ b/src/Notifications/NewFollowerBlueprint.php @@ -3,7 +3,7 @@ /* * This file is part of ianm/follow-users * - * Copyright (c) 2020 Ian Morland. + * Copyright (c) Ian Morland. * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. diff --git a/src/Notifications/NewPostByUserBlueprint.php b/src/Notifications/NewPostByUserBlueprint.php index ea60edc..7cb766d 100755 --- a/src/Notifications/NewPostByUserBlueprint.php +++ b/src/Notifications/NewPostByUserBlueprint.php @@ -3,7 +3,7 @@ /* * This file is part of ianm/follow-users * - * Copyright (c) 2020 Ian Morland. + * Copyright (c) Ian Morland. * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. diff --git a/src/Notifications/NewUnfollowerBlueprint.php b/src/Notifications/NewUnfollowerBlueprint.php index a0af372..1d9a99e 100755 --- a/src/Notifications/NewUnfollowerBlueprint.php +++ b/src/Notifications/NewUnfollowerBlueprint.php @@ -3,7 +3,7 @@ /* * This file is part of ianm/follow-users * - * Copyright (c) 2020 Ian Morland. + * Copyright (c) Ian Morland. * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. diff --git a/src/Query/FollowUsersFilter.php b/src/Query/FollowUsersDiscussionFilter.php similarity index 93% rename from src/Query/FollowUsersFilter.php rename to src/Query/FollowUsersDiscussionFilter.php index 7c9fc35..40963d9 100755 --- a/src/Query/FollowUsersFilter.php +++ b/src/Query/FollowUsersDiscussionFilter.php @@ -3,7 +3,7 @@ /* * This file is part of ianm/follow-users * - * Copyright (c) 2020 Ian Morland. + * Copyright (c) Ian Morland. * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. @@ -18,7 +18,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Query\Builder; -class FollowUsersFilter implements FilterInterface +class FollowUsersDiscussionFilter implements FilterInterface { public function getFilterKey(): string { diff --git a/src/Query/FollowedUsersFilterGambit.php b/src/Query/FollowedUsersFilterGambit.php new file mode 100644 index 0000000..eae76fa --- /dev/null +++ b/src/Query/FollowedUsersFilterGambit.php @@ -0,0 +1,79 @@ +users = $users; + } + + protected function getGambitPattern() + { + return 'is:followeduser'; + } + + /** + * {@inheritdoc} + */ + public function apply(SearchState $search, $bit) + { + return parent::apply($search, $bit); + } + + /** + * {@inheritdoc} + */ + protected function conditions(SearchState $search, array $matches, $negate) + { + $this->constrain($search->getQuery(), $search->getActor(), $negate); + } + + public function getFilterKey(): string + { + return 'followeduser'; + } + + public function filter(FilterState $filterState, string $filterValue, bool $negate) + { + $this->constrain($filterState->getQuery(), $filterState->getActor(), $negate); + } + + protected function constrain(Builder $query, User $actor, bool $negate) + { + $query->where(function ($query) use ($actor, $negate) { + if ($negate) { + $query->whereNotIn('id', $actor->followedUsers()->pluck('id')); + } else { + $query->whereIn('id', $actor->followedUsers()->pluck('id')); + } + }); + } +}