Commit c1220069 authored by Nico Alt's avatar Nico Alt

Respect contact id when sending in private chat

Also listen on other enter button and empty entry after sending.
parent 7492ce5a
......@@ -2,7 +2,7 @@
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkGrid" id="main">
<object class="GtkGrid" id="chat">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
......
......@@ -23,5 +23,5 @@ class PrivateChat(Model):
contact_id=contact_id)
def send(self, contact_id, message):
url = urljoin(BASE_HTTP_URL, 'messages/%s' % contact_id)
url = urljoin(BASE_HTTP_URL, 'messages/%i' % contact_id)
_post(url, headers=self._headers, json={'text': message})
......@@ -16,36 +16,40 @@ class ChatContainer(Container):
def __init__(self, contact_id):
super().__init__()
self._api = App().api
self._contact_id = contact_id
self._setup_view()
self._load_content(contact_id)
self._load_content()
def _setup_view(self):
self.builder.add_from_resource("/app/briar/gtk/ui/chat.ui")
self.add(self.builder.get_object("main"))
self.add(self.builder.get_object("chat"))
self.builder.connect_signals(self)
chat_entry = self.builder.get_object("chat_entry")
chat_entry.connect("key-press-event", self._key_pressed)
def _load_content(self, contact_id):
def _load_content(self):
private_chat = PrivateChat(self._api)
messages_list = private_chat.get(contact_id)
messages_list = private_chat.get(self._contact_id)
self._messages_list_box = self.builder.get_object("messages_list")
for message in messages_list:
self._add_message(message)
private_chat.watch_messages(contact_id, self._add_message_async)
self._add_message(message["text"])
private_chat.watch_messages(self._contact_id, self._add_message_async)
def _add_message(self, message):
message_label = Gtk.Label(message["text"])
message_label = Gtk.Label(message)
message_label.show()
self._messages_list_box.add(message_label)
def _add_message_async(self, message):
GLib.idle_add(self._add_message, message)
GLib.idle_add(self._add_message, message["text"])
def _key_pressed(self, widget, event):
if event.hardware_keycode != 36:
if event.hardware_keycode != 36 and event.hardware_keycode != 104:
return
message = self.builder.get_object("chat_entry").get_text()
chat_entry = self.builder.get_object("chat_entry")
message = chat_entry.get_text()
private_chat = PrivateChat(self._api)
private_chat.send("1", message)
private_chat.send(self._contact_id, message)
self._add_message(message)
chat_entry.set_text("")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment