Archived
1
0
Fork 0

Implement message sending

This commit is contained in:
Braiden Vasco 2017-07-26 08:07:36 +00:00
parent ad31d7f808
commit c683df1fa2
6 changed files with 46 additions and 0 deletions

View file

@ -7,6 +7,8 @@ module Events
end
module Text
class Enter; end
class Left; end
class Right; end
class Up; end

View file

@ -252,6 +252,38 @@ private
).freeze
end
def on_new_message_enter
return if state[:active_friend_index].nil?
friend_number = state[:friends].keys[state[:active_friend_index]]
return if friend_number.nil?
text = state[:friends][friend_number][:new_message][:text].strip.freeze
return if text.empty?
@tox_client.friend(friend_number).send_message text
@state = state.merge(
friends: state[:friends].merge(
friend_number => state[:friends][friend_number].merge(
new_message: state[:friends][friend_number][:new_message].merge(
text: '',
cursor_pos: 0,
),
history: (state[:friends][friend_number][:history] + [
out: true,
time: Time.now.utc.freeze,
name: @tox_client.name.freeze,
text: text,
]).freeze,
).freeze,
).freeze,
).freeze
end
def on_new_message_putc(char)
return if state[:active_friend_index].nil?
@ -455,6 +487,8 @@ private
on_menu_up: method(:on_menu_up),
on_menu_down: method(:on_menu_down),
on_new_message_enter: method(:on_new_message_enter),
on_new_message_putc: method(:on_new_message_putc),
on_new_message_left: method(:on_new_message_left),

View file

@ -70,6 +70,9 @@ private
when Curses::Key::SRIGHT
Events::Window::Right.new
when "\n".ord
Events::Text::Enter.new
when Curses::Key::LEFT
Events::Text::Left.new
when Curses::Key::RIGHT

View file

@ -25,6 +25,8 @@ module Widgets
).freeze
@message.props = props[:new_message].merge(
on_enter: props[:on_new_message_enter],
on_putc: props[:on_new_message_putc],
on_left: props[:on_new_message_left],

View file

@ -22,6 +22,8 @@ module Widgets
).freeze
@chat.props = props[:chat].merge(
on_new_message_enter: props[:on_new_message_enter],
on_new_message_putc: props[:on_new_message_putc],
on_new_message_left: props[:on_new_message_left],

View file

@ -4,6 +4,9 @@ module Widgets
class Text < Base
def trigger(event)
case event
when Events::Text::Enter
props[:on_enter].call
when Events::Text::Putc
props[:on_putc].call event.char