Commit c5946225 authored by Elizabeth Myers's avatar Elizabeth Myers 💬
Browse files

Saner behaviour for messaging

parent 93ab723d
#!/usr/bin/env python3
import sys
import shlex
......@@ -138,16 +140,17 @@ class NetworkConnection:
if frame.dst[0] == '@':
for group in frame.data.get('groups', []):
self.add_buf(group)
self.send(Frame.create(self.src, group, 'listmembers'))
elif t == 'listmembers':
if frame.dst not in self.member_bufs:
return
if 'members' in frame.data:
if self.window.current_buf == (self, frame.dst):
for member in frame.data['members']:
if member not in self.member_bufs[frame.dst]:
for member in frame.data['members']:
if member not in self.member_bufs[frame.dst]:
if self.window.current_buf == (self, frame.dst):
self.window.list_widget.addItem(member)
self.member_bufs[frame.dst].add(member)
self.member_bufs[frame.dst].add(member)
elif t == 'login':
self.src = frame.dst
self.send(Frame.create(self.src, self.src, 'listgroups'))
......@@ -156,11 +159,11 @@ class NetworkConnection:
return
if 'members' in frame.data:
if self.window.current_buf == (self, frame.dst):
for member in frame.data['members']:
if member not in self.member_bufs[frame.dst]:
for member in frame.data['members']:
if member not in self.member_bufs[frame.dst]:
if self.window.current_buf == (self, frame.dst):
self.window.list_widget.addItem(member)
self.member_bufs[frame.dst].add(member)
self.member_bufs[frame.dst].add(member)
else:
self.member_bufs[frame.dst].add(frame.src)
......@@ -229,12 +232,10 @@ class MainWindow(QMainWindow):
QCoreApplication.setOrganizationDomain("kittyproto.chat")
QCoreApplication.setApplicationName("Kitty demo client")
self.default_buf = QTextBrowser()
self.tree_widget = QTreeWidget()
self.vbox_layout = QVBoxLayout()
self.text_box = self.default_buf
self.text_box = QTextBrowser()
self.edit_box = QLineEdit()
self.vbox_layout.addWidget(self.text_box)
self.vbox_layout.addWidget(self.edit_box)
......@@ -252,18 +253,26 @@ class MainWindow(QMainWindow):
self.setCentralWidget(self.splitter)
self.edit_box.returnPressed.connect(self.send)
self.tree_widget.itemDoubleClicked.connect(self.on_tree_double_click)
self.tree_widget.itemActivated.connect(self.on_tree_activate)
self.connection = NetworkConnection(self, 'localhost', 'wss://localhost:8080/ws')
self.connection.switch_buf('')
def send(self):
text = self.edit_box.text()
frame = parse_input(text)
if text[0] == '/':
try:
frame = parse_input(text[1:])
except Exception:
pass
else:
dest = self.current_buf[1] if self.current_buf[1] else '$'
frame = Frame.create(self.current_buf[0].src, dest, 'message', data={'message': text})
self.connection.send(frame)
self.edit_box.clear()
def on_tree_double_click(self, item, column):
def on_tree_activate(self, item, column):
if item.parent() == None:
self.connection.switch_buf('')
else:
......
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