diff --git a/sms.py b/sms.py index 90bd5a0..b50ca4a 100755 --- a/sms.py +++ b/sms.py @@ -266,9 +266,37 @@ class Web_Service (BaseHTTPRequestHandler): self.end_headers () self.wfile.write (( html_header (title = 'Termux WebSMS') + - html_iframe ('/list', height = '100%', width = '30%', name = 'list') + html_iframe ('about:blank', height = '100%', width = '70%', name = 'messages') + + html_iframe ('/list', height = '100%', width = '30%', name = 'list') + html_iframe ('about:blank', height = '100%', width = '70%', name = 'thread') + html_footer () ).encode ('utf-8')) + elif self.path == '/up.svg': + self.send_response (200) + self.send_header ('Content-type', 'image/svg+xml; charset=UTF-8') + self.end_headers () + self.wfile.write (( + '\n' + + '\t\n' + + '\t\t\n' + + '\t\n' + + '' + ).encode ('utf-8')) + elif self.path == '/down.svg': + self.send_response (200) + self.send_header ('Content-type', 'image/svg+xml; charset=UTF-8') + self.end_headers () + self.wfile.write (( + '\n' + + '\t\n' + + '\t\t\n' + + '\t\n' + + '' + ).encode ('utf-8')) elif self.path == '/list': self.send_response (200) self.send_header ('Content-type', 'text/html; charset=UTF-8') @@ -279,11 +307,11 @@ class Web_Service (BaseHTTPRequestHandler): s = ls [i] [0] + ' (' + str (ls [i] [3]) + ')' if len (ls [i]) == 5: s = ls [i] [4] + ' (' + str (ls [i] [3]) + ')' - lst.append (html_link ('/?thread=' + str (i), text = s, target = 'messages')) + lst.append (html_link ('/?thread=' + str (i), text = s, target = 'thread')) self.wfile.write (( html_header (title = 'Conversations list') + html_title ('Conversation') + - html_paragraph (html_link ('/new', text = 'New conversation', target = 'messages')) + + html_paragraph (html_link ('/new', text = 'New conversation', target = 'thread')) + html_paragraph (html_link ('/list', text = 'Refresh list')) + html_paragraph ('List of conversations follows:') + html_list (lst) + @@ -349,13 +377,6 @@ class Web_Service (BaseHTTPRequestHandler): self.send_response (200) self.send_header ('Content-type', 'text/html; charset=UTF-8') self.end_headers () - msgs = '' - for i in sorted (conv, key = lambda item: item [0], reverse = True) [0:2000]: - msgs += html_message (i [2], not i [1], i [0], '↓' if i [1] else '↑') - if name is None: - name = number - else: - name = name + ' (' + number + ')' self.wfile.write (( html_header (title = 'Conversation with ' + name) + html_title (name) + @@ -365,6 +386,39 @@ class Web_Service (BaseHTTPRequestHandler): html_form_submit ('Send'), '/send' ) + + html_iframe ('/messages?thread=' + str (id), , height = '100%', width = '100%', name = 'messages') + html_footer () + ).encode ('utf-8')) + elif self.path [0:17] == '/messages?thread=': + try: + id = self.path [17:] + number, name, conv = sms.get_thread (id) + if number is None: + raise (IndexError) + except (ValueError, IndexError): + self.send_response (404) + self.send_header ('Content-type', 'text/html') + self.end_headers () + self.wfile.write (( + html_header (title = 'Page not found') + + html_title ('Not found') + + html_paragraph ('This page does not exist. You cas return to the ' + html_link ('/', text = 'home') + '.') + + html_footer () + ).encode ('utf-8')) + return () + self.send_response (200) + self.send_header ('Content-type', 'text/html; charset=UTF-8') + self.send_header ('Refresh', '10') + self.end_headers () + msgs = '' + for i in sorted (conv, key = lambda item: item [0], reverse = True) [0:2000]: + msgs += html_message (i [2], not i [1], i [0], '↓' if i [1] else '↑', avatar = 'down.svg' if i [1] else 'up.svg') + if name is None: + name = number + else: + name = name + ' (' + number + ')' + self.wfile.write (( + html_header (title = 'Conversation with ' + name) + html_link (self.path, text = 'Refresh') + msgs + html_footer ()