Commit 0c39cac6 authored by Nico Alt's avatar Nico Alt

Add ability to send messages (to first contact)

parent 79036d82
......@@ -6,6 +6,7 @@ from briar.api.models.model import Model
from briar.api.models.socket_listener import SocketListener
from requests import get as _get
from requests import post as _post
from urllib.parse import urljoin
......@@ -21,3 +22,8 @@ class PrivateChat(Model):
socket_listener = SocketListener(self._api)
socket_listener.watch(callback, "ConversationMessageReceivedEvent",
contact_id=contact_id)
def send(self, contact_id, message):
headers = {'Authorization': 'Bearer ' + self._api.auth_token}
url = urljoin(self._constants.get_base_url(), 'messages/' + contact_id)
_post(url, headers=headers, json={'text': message})
......@@ -23,6 +23,8 @@ class ChatContainer(Container):
self.builder.add_from_resource("/app/briar/gtk/ui/chat.ui")
self.add(self.builder.get_object("main"))
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):
private_chat = PrivateChat(self._api)
......@@ -39,3 +41,11 @@ class ChatContainer(Container):
def _add_message_async(self, message):
GLib.idle_add(self._add_message, message)
def _key_pressed(self, widget, event):
if event.hardware_keycode != 36:
return
message = self.builder.get_object("chat_entry").get_text()
private_chat = PrivateChat(self._api)
private_chat.send("1", message)
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