From 0ac5950f8c50bfcb6ce6cd89c0e80d982513cd15 Mon Sep 17 00:00:00 2001 From: David Gay Date: Tue, 6 Jul 2021 20:11:20 -0400 Subject: Increase chat message area chat message limit from 100 to 200, and add a chat history page that shows the last 2,000 messages --- CHANGELOG.md | 4 ++++ app/controllers/chat_messages_controller.rb | 7 +++++-- app/javascript/controllers/chat_controller.js | 2 +- app/views/application/_chat.html.erb | 21 ++++++++++++++------- app/views/chat_messages/index.html.erb | 9 +++++++++ config/routes.rb | 6 +++++- 6 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 app/views/chat_messages/index.html.erb diff --git a/CHANGELOG.md b/CHANGELOG.md index a08e57c..91ea977 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,10 @@ All notable changes to this project will be documented in this file. - Synthsever rusted lockbox base duration reduced from 180 to 120. - Adjusted wealdreap drop tables at Twil Woods and Twil Grove to accommodate pluma moss and laris strand. +### Chat +- Chat area now shows most recent 200 messages, instead of 100. +- New "History" link shows a chat history of the last 2,000 messages. + ## [0.1.12] - 2021-06-23 ### General diff --git a/app/controllers/chat_messages_controller.rb b/app/controllers/chat_messages_controller.rb index 9112bb7..a299379 100644 --- a/app/controllers/chat_messages_controller.rb +++ b/app/controllers/chat_messages_controller.rb @@ -1,7 +1,10 @@ class ChatMessagesController < ApplicationController def index - # TODO: Let's rename this method to #list - @chat_messages = ChatMessage.order(created_at: :desc).limit(100).reverse + @chat_messages = ChatMessage.order(created_at: :desc).limit(2000) + end + + def list + @chat_messages = ChatMessage.order(created_at: :asc).limit(200) render partial: "chat_messages/list" end diff --git a/app/javascript/controllers/chat_controller.js b/app/javascript/controllers/chat_controller.js index 95b61c5..0605b3a 100644 --- a/app/javascript/controllers/chat_controller.js +++ b/app/javascript/controllers/chat_controller.js @@ -18,7 +18,7 @@ export default class extends Controller { load() { this.scrollToBottom(); if (this.outputTarget.innerHTML.trim() === "") { - fetch("/chat_messages") + fetch("/chat_messages/list") .then(response => response.text()) .then(html => { this.outputTarget.innerHTML = html; diff --git a/app/views/application/_chat.html.erb b/app/views/application/_chat.html.erb index b656ed7..1ba6f8f 100644 --- a/app/views/application/_chat.html.erb +++ b/app/views/application/_chat.html.erb @@ -3,13 +3,20 @@
- <%= form_with model: ChatMessage.new, html: { autocomplete: "off" }, local: false, - data: { action: "chat#send" }, class: "flex" do |f| %> - <%= f.collection_select :chat_room_id, ChatRoom.accessible_to(current_char.user), - :id, :short_name, class: "flex-none" %> - <%= f.text_field :body, size: "1", maxlength: 255, required: true, - data: { chat_target: "message" }, class: "flex-grow inline-flex" %> - <% end %> +
+
+ <%= form_with model: ChatMessage.new, html: { autocomplete: "off" }, local: false, + data: { action: "chat#send" }, class: "flex" do |f| %> + <%= f.collection_select :chat_room_id, ChatRoom.accessible_to(current_char.user), + :id, :short_name, class: "flex-none" %> + <%= f.text_field :body, size: "1", maxlength: 255, required: true, + data: { chat_target: "message" }, class: "flex-grow inline-flex" %> + <% end %> +
+
+ <%= link_to "History", chat_messages_path %> +
+
<% end %> diff --git a/app/views/chat_messages/index.html.erb b/app/views/chat_messages/index.html.erb new file mode 100644 index 0000000..8791e7b --- /dev/null +++ b/app/views/chat_messages/index.html.erb @@ -0,0 +1,9 @@ +

+ Chat History +

+ +

Last 2,000 messages listed from newest to oldest.

+ +
+ <%= render "chat_messages/list" %> +
diff --git a/config/routes.rb b/config/routes.rb index 26e6666..ce39562 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,7 +13,11 @@ Rails.application.routes.draw do get :look, to: "look#look" - resources :chat_messages, only: [:index, :create] + resources :chat_messages, only: [:index, :create] do + collection do + get :list + end + end resources :activities, only: [:index, :show] do get :costs_and_requirements, on: :member end -- cgit v1.2.3