Skip to content

Commit

Permalink
Timestamps on channel chat. Who list on web chat.
Browse files Browse the repository at this point in the history
  • Loading branch information
lynnfaraday committed Mar 25, 2018
1 parent 5107a3d commit b9e72a6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
14 changes: 14 additions & 0 deletions install/upgrades/036-0.9_upgrade.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module AresMUSH

puts "======================================================================="
puts "Add timestamps to channel history. "
puts "======================================================================="


Channel.all.each do |c|
messages = c.messages
new_messages = c.messages.map { |m| { message: m, timestamp: DateTime.now }}
c.update(messages: new_messages)
end
puts "Upgrade complete!"
end
6 changes: 3 additions & 3 deletions plugins/channels/commands/channel_recall_cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def handle
Channels.with_an_enabled_channel(self.name, client, enactor) do |channel|
total_messages = channel.messages.count
start_message = [ (total_messages - self.num_messages), 0 ].max
messages = channel.messages[start_message, total_messages].map { |m| " #{channel.display_name} #{m}" }

template = BorderedListTemplate.new messages, t('channels.recall_history', :name => channel.display_name(false))
messages = channel.messages[start_message, total_messages]
list = messages.map { |m| " [#{OOCTime.local_long_timestr(enactor, m['timestamp'])}] #{channel.display_name} #{m['message']}"}
template = BorderedListTemplate.new list, t('channels.recall_history', :name => channel.display_name(false))
client.emit template.render
end
end
Expand Down
5 changes: 3 additions & 2 deletions plugins/channels/commands/channel_report_cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ def required_args

def handle
Channels.with_an_enabled_channel(self.name, client, enactor) do |channel|
total_messages = channel.messages.count
messages = channel.messages.map { |m| " [#{OOCTime.local_long_timestr(enactor, m['timestamp'])}] #{channel.display_name} #{m['message']}"}.join("%R")

body = t('channels.channel_reported_body', :name => channel.name, :reporter => enactor_name)
body << self.reason
body << "%R-------%R"
body << channel.messages.map { |m| " #{m}" }.join('%R')
body << messages

Jobs.create_job(Jobs.trouble_category, t('channels.channel_reported_title'), body, Game.master.system_character)
client.emit_success t('channels.channel_reported')

Expand Down
2 changes: 1 addition & 1 deletion plugins/channels/public/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def display_name(include_markers = true)

def add_to_history(msg)
return if !self.recall_enabled
new_messages = (self.messages << msg)
new_messages = (self.messages << { message: msg, timestamp: DateTime.now })
if (new_messages.count > 25)
new_messages.shift
end
Expand Down
10 changes: 9 additions & 1 deletion plugins/channels/web/chat_request_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ def handle(request)
name: c.name,
enabled: Channels.is_on_channel?(enactor, c),
allowed: Channels.can_use_channel(enactor, c),
messages: Channels.is_on_channel?(enactor, c) ? c.messages.map { |m| WebHelpers.format_markdown_for_html(m) } : nil
who: Channels.channel_who(c).map { |w| {
name: w.name,
ooc_name: w.ooc_name,
icon: WebHelpers.icon_for_char(w),
muted: Channels.is_muted?(w, c)
}},
messages: Channels.is_on_channel?(enactor, c) ? c.messages.map { |m| {
message: WebHelpers.format_markdown_for_html(m['message']),
timestamp: OOCTime.local_long_timestr(enactor, m['timestamp']) }} : nil
}}

{
Expand Down

0 comments on commit b9e72a6

Please sign in to comment.