Commit a417fad5 authored by Nico Alt's avatar Nico Alt

Add ability to chat with other contacts than the first one

Co-Authored-By: default avatarialokim <ialokim@t-online.de>
parent 0c39cac6
......@@ -14,7 +14,7 @@ class PrivateChat(Model):
def get(self, contact_id):
headers = {'Authorization': 'Bearer ' + self._api.auth_token}
url = urljoin(self._constants.get_base_url(), 'messages/' + contact_id)
url = urljoin(self._constants.get_base_url(), 'messages/%i' % contact_id)
r = _get(url, headers=headers)
return r.json()
......@@ -25,5 +25,5 @@ class PrivateChat(Model):
def send(self, contact_id, message):
headers = {'Authorization': 'Bearer ' + self._api.auth_token}
url = urljoin(self._constants.get_base_url(), 'messages/' + contact_id)
url = urljoin(self._constants.get_base_url(), 'messages/%s' % contact_id)
_post(url, headers=headers, json={'text': message})
......@@ -8,7 +8,7 @@ from briar.gtk.define import App
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import GLib, GObject, Gtk
from gi.repository import GLib, Gtk
class MainContainer(Container):
......@@ -16,15 +16,9 @@ class MainContainer(Container):
def __init__(self):
super().__init__()
self._api = App().api
self._register_signals()
self._setup_view()
self._load_content()
def _register_signals(self):
GObject.signal_new("briar_open_private_chat", Gtk.Overlay,
GObject.SignalFlags.RUN_LAST, GObject.TYPE_BOOLEAN,
(GObject.TYPE_STRING,))
def _setup_view(self):
self.builder.add_from_resource("/app/briar/gtk/ui/main.ui")
self.add(self.builder.get_object("contacts_list"))
......@@ -36,9 +30,10 @@ class MainContainer(Container):
contacts_list_box = self.builder.get_object("contacts_list")
for contact in contacts_list:
contact_label = Gtk.Button(contact["author"]["name"])
contact_label.connect("clicked", self._contact_clicked)
contact_label.connect("clicked", self._contact_clicked,
contact["contactId"])
contact_label.show()
contacts_list_box.add(contact_label)
def _contact_clicked(self, contact):
GLib.idle_add(self.emit, "briar_open_private_chat", (contact,))
def _contact_clicked(self, widget, contactId):
GLib.idle_add(App().window.open_private_chat, contactId)
......@@ -55,14 +55,12 @@ class Window(Gtk.ApplicationWindow):
def __setup_main_container(self):
self.__container = MainContainer()
self.__container.show()
self.__container.connect("briar_open_private_chat",
self.__open_private_chat)
self.__grid.add(self.__container)
def __open_private_chat(self, inst, obj):
def open_private_chat(self, contact_id):
self.__grid.destroy()
self.__setup_grid()
self.__setup_private_chat("1")
self.__setup_private_chat(contact_id)
def __setup_private_chat(self, contact_id):
self.__container = ChatContainer(contact_id)
......
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