From 4fcf9ece3ac20b21f2c8c7d69538948e4f4aaf48 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 14 Dec 2017 16:52:54 -0500 Subject: [PATCH] Allow plugins to customize the columns returned by user_actions This is useful if they have a different mechanism for rendering an avatar and want to include custom columns via the `custom_avatar_column` plugin function. --- app/models/user_action.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/models/user_action.rb b/app/models/user_action.rb index 997f2b69165..02123a1d444 100644 --- a/app/models/user_action.rb +++ b/app/models/user_action.rb @@ -167,6 +167,18 @@ SQL offset = opts[:offset] || 0 limit = opts[:limit] || 60 + # Acting user columns. Can be extended by plugins to include custom avatar + # columns + acting_cols = [ + 'u.id AS acting_user_id', + 'u.name AS acting_name' + ] + + AvatarLookup.lookup_columns.each do |c| + next if c == :id || c['.'] + acting_cols << "u.#{c} AS acting_#{c}" + end + # The weird thing is that target_post_id can be null, so it makes everything # ever so more complex. Should we allow this, not sure. builder = SqlBuilder.new <<-SQL @@ -179,8 +191,7 @@ SQL p.reply_to_post_number, pu.username, pu.name, pu.id user_id, pu.uploaded_avatar_id, - u.username acting_username, u.name acting_name, u.id acting_user_id, - u.uploaded_avatar_id acting_uploaded_avatar_id, + #{acting_cols.join(', ')}, coalesce(p.cooked, p2.cooked) cooked, CASE WHEN coalesce(p.deleted_at, p2.deleted_at, t.deleted_at) IS NULL THEN false ELSE true END deleted, p.hidden,