Skip to content

Commit

Permalink
Autocompletion of usernames in comment boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
TildaDares committed Jun 10, 2021
1 parent 471e413 commit 6ca6da8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/assets/javascripts/atWhoAutoComplete.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
(function() {

// settings at https://github.com/ichord/At.js/wiki/Base-Document#settings

const displayName = (item) => item.username ? item.username : item.name;

var at_config = {
at: "@",
displayTpl: (item) => `<li>${displayName(item)}</li>`,
insertTpl: (item) => `@${displayName(item)}`,
data: '/users/active',
delay: 400,
callbacks: {
remoteFilter: debounce(function(query, callback) {
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,11 @@ def verify_email
redirect_to "/login", flash: { notice: action_msg }
end

def recently_active_users
active_users = User.recently_active_users
render json: active_users, root: false
end

private

def subscribe_multiple_tag(tag_list)
Expand Down
11 changes: 11 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,17 @@ def latest_location
recent_locations.last
end

def self.recently_active_users(limit = 5, order = 'last_updated DESC')
Rails.cache.fetch('users/active', expires_in: 24.hours) do
User.select('rusers.username, rusers.id, MAX(node_revisions.timestamp) AS last_updated')
.joins("INNER JOIN `node_revisions` ON `node_revisions`.`uid` = `rusers`.`id` ")
.where("node_revisions.status = 1")
.group('rusers.id')
.order(order)
.limit(limit)
end
end

private

def decrease_likes_banned
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
get 'signup' => 'users#new'
get 'home' => 'home#front'
get 'verify/:token' => 'users#verify_email'
get 'users/active' => 'users#recently_active_users'
resources :relationships, only: [:create, :destroy]

get '/wiki/:id/comments', to: 'wiki#comments'
Expand Down

0 comments on commit 6ca6da8

Please sign in to comment.