Follow Plugin 👨

OK I’ve tried to rationalise and fix at the same time … let’s see how this works for you:

https://github.com/paviliondev/discourse-follow/commit/d7261b7e6cdd58fcb99036e7dd35489c0eec85e1

2 Likes

btw let’s take this to PM for time being. Bit too noisy for public consumption I feel?

2 Likes

Can push notification and desktop notification be received when someone follows?
@merefield

1 Like

I believe this works. Email notifications almost certainly aren’t implemented.

You are welcome to PR some test cases.

3 Likes

I was trying the User Card Directory - theme - Discourse Meta and it failed to show all user card data because the /user-cards.json?user_ids=... endpoint returns an HTTP error 500.

Looking at the logs it is related to this plugin:

log

Message

StandardError (Attempted to access the non preloaded custom field ‘followers’. This is disallowed to prevent N+1 queries.)
app/models/concerns/has_custom_fields.rb:168:in []' lib/plugin/instance.rb:259:in public_send’
lib/plugin/instance.rb:259:in block (2 levels) in add_to_class' (eval):44:in _fast_attributes’
app/controllers/users_controller.rb:123:in cards' app/controllers/application_controller.rb:358:in block in with_resolved_locale’
app/controllers/application_controller.rb:358:in with_resolved_locale' lib/middleware/omniauth_bypass_middleware.rb:68:in call’
lib/content_security_policy/middleware.rb:12:in call' lib/middleware/anonymous_cache.rb:354:in call’
config/initializers/008-rack-cors.rb:25:in call' config/initializers/100-quiet_logger.rb:23:in call’
config/initializers/100-silence_logger.rb:31:in call' lib/middleware/enforce_hostname.rb:22:in call’
lib/middleware/request_tracker.rb:176:in `call’

Backtrace

app/models/concerns/has_custom_fields.rb:168:in []' plugins/discourse-follow/plugin.rb:57:in block (2 levels) in activate!’
lib/plugin/instance.rb:259:in public_send' lib/plugin/instance.rb:259:in block (2 levels) in add_to_class’
plugins/discourse-follow/plugin.rb:75:in block (2 levels) in activate!' (eval):44:in _fast_attributes’
active_model_serializers (0.8.4) lib/active_model/serializer.rb:456:in attributes' active_model_serializers (0.8.4) lib/active_model/serializer.rb:480:in _serializable_hash’
active_model_serializers (0.8.4) lib/active_model/serializer.rb:359:in serializable_hash' active_model_serializers (0.8.4) lib/active_model/array_serializer.rb:89:in block in _serializable_array’

Do you have any idea if is it possible to make them compatible?

Thanks.

1 Like

Oh a stealth change to the API to accommodate a Theme Component? Sneaky! I presume that route isn’t used if you don’t install this TC?

Generally we only test on/support vanilla Discourse, but I can see a case for getting this done, not sure when though.

PR welcome.

2 Likes

This route is only used by the theme component? That’s odd :smile:

I could try a PR but I don’t know exactly how to fix this.

The user#cards controller is the one preloading the custom fields:
https://github.com/discourse/discourse/blob/master/app/controllers/users_controller.rb#L119-L120

So followers is not preloaded, but it also is not used on user cards, is it? I know it doesn’t exist on card.json, which only has the following boolean. Both routes are using UserCardSerializer, but only user#cards is trying to access the followers custom field.

https://github.com/discourse/discourse/blob/master/app/models/concerns/has_custom_fields.rb#L163-L-169

3 Likes

Currently doing a house move but if you don’t get to it first I’ll look at in when new home office is set up :).

3 Likes

I’m probably late to the party, but I’ve just had this issue too.
If anyone has this issue simply add:

.follow-toggle{
flex:auto!important;
}

3 Likes

I can’t reproduce that with the out of the box light theme.

1 Like

I am using the Fakebook theme, I believe that’s what it’s called.
I believe the issue is because there’s a CSS flex on all those <li> in mobile, yet the CSS doesn’t take into consideration that there will be three listing items.

3 Likes

Ah, we can’t support every possible theme.

2 Likes

Absolutely. No need to get defensive, your plugin is great.
I was just providing this as an answer for those who may need it. I see it as my obligation as someone who uses this plugin :slight_smile:

3 Likes

Errors are popping up on our 2.7.0.beta1 Tests-Pass. Unsure of how to resolve aside from removing the follow plugin.

Here is the error log

app/models/concerns/has_custom_fields.rb:168:in []' plugins/discourse-follow/plugin.rb:57:in block (2 levels) in activate!’
lib/plugin/instance.rb:259:in public_send' lib/plugin/instance.rb:259:in block (2 levels) in add_to_class’
plugins/discourse-follow/plugin.rb:75:in block (2 levels) in activate!' (eval):45:in _fast_attributes’
active_model_serializers (0.8.4) lib/active_model/serializer.rb:456:in attributes' active_model_serializers (0.8.4) lib/active_model/serializer.rb:480:in _serializable_hash’
active_model_serializers (0.8.4) lib/active_model/serializer.rb:359:in serializable_hash' active_model_serializers (0.8.4) lib/active_model/array_serializer.rb:89:in block in _serializable_array’
active_model_serializers (0.8.4) lib/active_model/array_serializer.rb:79:in map' active_model_serializers (0.8.4) lib/active_model/array_serializer.rb:79:in _serializable_array’
active_model_serializers (0.8.4) lib/active_model/array_serializer.rb:73:in serializable_array' active_model_serializers (0.8.4) lib/active_model/array_serializer.rb:49:in as_json’
activesupport (6.0.3.3) lib/active_support/json/encoding.rb:22:in encode' activesupport (6.0.3.3) lib/active_support/json/encoding.rb:22:in encode’
activesupport (6.0.3.3) lib/active_support/core_ext/object/json.rb:42:in to_json' active_model_serializers (0.8.4) lib/active_model/array_serializer.rb:63:in to_json’
actionpack (6.0.3.3) lib/action_controller/metal/renderers.rb:157:in block in <module:Renderers>' active_model_serializers (0.8.4) lib/action_controller/serialization.rb:48:in block (2 levels) in module:Serialization
actionpack (6.0.3.3) lib/action_controller/metal/renderers.rb:150:in block in _render_to_body_with_renderer' /usr/local/lib/ruby/2.7.0/set.rb:328:in each_key’
/usr/local/lib/ruby/2.7.0/set.rb:328:in each' actionpack (6.0.3.3) lib/action_controller/metal/renderers.rb:146:in _render_to_body_with_renderer’
actionpack (6.0.3.3) lib/action_controller/metal/renderers.rb:142:in render_to_body' actionpack (6.0.3.3) lib/abstract_controller/rendering.rb:25:in render’
actionpack (6.0.3.3) lib/action_controller/metal/rendering.rb:36:in render' actionpack (6.0.3.3) lib/action_controller/metal/instrumentation.rb:44:in block (2 levels) in render’
activesupport (6.0.3.3) lib/active_support/core_ext/benchmark.rb:14:in block in ms' /usr/local/lib/ruby/2.7.0/benchmark.rb:308:in realtime’
activesupport (6.0.3.3) lib/active_support/core_ext/benchmark.rb:14:in ms' actionpack (6.0.3.3) lib/action_controller/metal/instrumentation.rb:44:in block in render’
actionpack (6.0.3.3) lib/action_controller/metal/instrumentation.rb:84:in cleanup_view_runtime' activerecord (6.0.3.3) lib/active_record/railties/controller_runtime.rb:34:in cleanup_view_runtime’
actionpack (6.0.3.3) lib/action_controller/metal/instrumentation.rb:43:in render' app/controllers/users_controller.rb:123:in cards’
actionpack (6.0.3.3) lib/action_controller/metal/basic_implicit_render.rb:6:in send_action' actionpack (6.0.3.3) lib/abstract_controller/base.rb:195:in process_action’
actionpack (6.0.3.3) lib/action_controller/metal/rendering.rb:30:in process_action' actionpack (6.0.3.3) lib/abstract_controller/callbacks.rb:42:in block in process_action’
activesupport (6.0.3.3) lib/active_support/callbacks.rb:112:in block in run_callbacks' app/controllers/application_controller.rb:358:in block in with_resolved_locale’
i18n (1.8.5) lib/i18n.rb:313:in with_locale' app/controllers/application_controller.rb:358:in with_resolved_locale’
activesupport (6.0.3.3) lib/active_support/callbacks.rb:121:in block in run_callbacks' activesupport (6.0.3.3) lib/active_support/callbacks.rb:139:in run_callbacks’
actionpack (6.0.3.3) lib/abstract_controller/callbacks.rb:41:in process_action' actionpack (6.0.3.3) lib/action_controller/metal/rescue.rb:22:in process_action’
actionpack (6.0.3.3) lib/action_controller/metal/instrumentation.rb:33:in block in process_action' activesupport (6.0.3.3) lib/active_support/notifications.rb:180:in block in instrument’
activesupport (6.0.3.3) lib/active_support/notifications/instrumenter.rb:24:in instrument' activesupport (6.0.3.3) lib/active_support/notifications.rb:180:in instrument’
actionpack (6.0.3.3) lib/action_controller/metal/instrumentation.rb:32:in process_action' actionpack (6.0.3.3) lib/action_controller/metal/params_wrapper.rb:245:in process_action’
activerecord (6.0.3.3) lib/active_record/railties/controller_runtime.rb:27:in process_action' actionpack (6.0.3.3) lib/abstract_controller/base.rb:136:in process’
actionview (6.0.3.3) lib/action_view/rendering.rb:39:in process' rack-mini-profiler (2.2.0) lib/mini_profiler/profiling_methods.rb:85:in block in profile_method’
actionpack (6.0.3.3) lib/action_controller/metal.rb:190:in dispatch' actionpack (6.0.3.3) lib/action_controller/metal.rb:254:in dispatch’
actionpack (6.0.3.3) lib/action_dispatch/routing/route_set.rb:50:in dispatch' actionpack (6.0.3.3) lib/action_dispatch/routing/route_set.rb:33:in serve’
actionpack (6.0.3.3) lib/action_dispatch/journey/router.rb:49:in block in serve' actionpack (6.0.3.3) lib/action_dispatch/journey/router.rb:32:in each’
actionpack (6.0.3.3) lib/action_dispatch/journey/router.rb:32:in serve' actionpack (6.0.3.3) lib/action_dispatch/routing/route_set.rb:834:in call’
lib/middleware/omniauth_bypass_middleware.rb:68:in call' rack (2.2.3) lib/rack/tempfile_reaper.rb:15:in call’
rack (2.2.3) lib/rack/conditional_get.rb:27:in call' rack (2.2.3) lib/rack/head.rb:12:in call’
lib/content_security_policy/middleware.rb:12:in call' lib/middleware/anonymous_cache.rb:354:in call’
rack (2.2.3) lib/rack/session/abstract/id.rb:266:in context' rack (2.2.3) lib/rack/session/abstract/id.rb:260:in call’
actionpack (6.0.3.3) lib/action_dispatch/middleware/cookies.rb:648:in call' actionpack (6.0.3.3) lib/action_dispatch/middleware/callbacks.rb:27:in block in call’
activesupport (6.0.3.3) lib/active_support/callbacks.rb:101:in run_callbacks' actionpack (6.0.3.3) lib/action_dispatch/middleware/callbacks.rb:26:in call’
actionpack (6.0.3.3) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in call' actionpack (6.0.3.3) lib/action_dispatch/middleware/debug_exceptions.rb:32:in call’
actionpack (6.0.3.3) lib/action_dispatch/middleware/show_exceptions.rb:33:in call' logster (2.9.4) lib/logster/middleware/reporter.rb:43:in call’
railties (6.0.3.3) lib/rails/rack/logger.rb:37:in call_app' railties (6.0.3.3) lib/rails/rack/logger.rb:28:in call’
config/initializers/100-quiet_logger.rb:23:in call' config/initializers/100-silence_logger.rb:31:in call’
actionpack (6.0.3.3) lib/action_dispatch/middleware/remote_ip.rb:81:in call' actionpack (6.0.3.3) lib/action_dispatch/middleware/request_id.rb:27:in call’
lib/middleware/enforce_hostname.rb:22:in call' rack (2.2.3) lib/rack/method_override.rb:24:in call’
actionpack (6.0.3.3) lib/action_dispatch/middleware/executor.rb:14:in call' rack (2.2.3) lib/rack/sendfile.rb:110:in call’
actionpack (6.0.3.3) lib/action_dispatch/middleware/host_authorization.rb:76:in call' plugins/discourse-prometheus/lib/middleware/metrics.rb:17:in call’
rack-mini-profiler (2.2.0) lib/mini_profiler/profiler.rb:246:in call' message_bus (3.3.4) lib/message_bus/rack/middleware.rb:61:in call’
lib/middleware/request_tracker.rb:176:in call' railties (6.0.3.3) lib/rails/engine.rb:527:in call’
railties (6.0.3.3) lib/rails/railtie.rb:190:in public_send' railties (6.0.3.3) lib/rails/railtie.rb:190:in method_missing’
rack (2.2.3) lib/rack/urlmap.rb:74:in block in call' rack (2.2.3) lib/rack/urlmap.rb:58:in each’
rack (2.2.3) lib/rack/urlmap.rb:58:in call' unicorn (5.7.0) lib/unicorn/http_server.rb:632:in process_client’
unicorn (5.7.0) lib/unicorn/http_server.rb:728:in worker_loop' unicorn (5.7.0) lib/unicorn/http_server.rb:548:in spawn_missing_workers’
unicorn (5.7.0) lib/unicorn/http_server.rb:144:in start' unicorn (5.7.0) bin/unicorn:128:in <top (required)>’
vendor/bundle/ruby/2.7.0/bin/unicorn:23:in load' vendor/bundle/ruby/2.7.0/bin/unicorn:23:in

3 Likes

Are you using the user cards directory Theme Component by any chance?

I will look at adding support as there are changes to core, but you can avoid those errors by using that Theme Component or Follow, but not both for the time being.

2 Likes

Yes I am. Got user card theme component.

2 Likes

Might be an idea to also discuss with User Card Theme Component as I believe someone in an above post. Posted a css fix?

I found the follow plugin is not overly friendly with Babble chat plugin as it pings chat messages to the follower of the person whom is followed.

Would need an option to exclude babblechat used categories to be muted.

1 Like

PR welcome on that, thanks.

2 Likes

Thanks will look into creating a github account to do things like this.

Thanks Robert for an awesome plugin btw!

2 Likes

You were quite correct. :+1:

Here’s the fix:

https://github.com/paviliondev/discourse-follow/commit/5db57d5ca08e9e7fdba393b9059199d8c80d4b97

You can now use the User Cards directory TC and Follow together without issue :slight_smile:

4 Likes