Commit b025d709 authored by Adrian Georgescu's avatar Adrian Georgescu

Session fixes

parent 944cdf89
...@@ -2210,7 +2210,7 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -2210,7 +2210,7 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
if message.content_type.startswith('image/'): if message.content_type.startswith('image/'):
content = '''<img src="data:{};base64,{}" class="scaled-to-fit" />'''.format(message.content_type, message.content.decode('base64').rstrip()) content = '''<img src="data:{};base64,{}" class="scaled-to-fit" />'''.format(message.content_type, message.content.decode('base64').rstrip())
elif message.content_type.startswith('text/'): elif message.content_type.startswith('text/'):
content = message.content.decode() content = message.content
content = HtmlProcessor.autolink(content if message.content_type == 'text/html' else QTextDocument(content).toHtml()) content = HtmlProcessor.autolink(content if message.content_type == 'text/html' else QTextDocument(content).toHtml())
else: else:
return return
...@@ -2410,9 +2410,10 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -2410,9 +2410,10 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
self.close() self.close()
self.no_sessions_label.show() self.no_sessions_label.show()
elif not self.session_list.isVisibleTo(self): elif not self.session_list.isVisibleTo(self):
self.session_list.animation.setDirection(QPropertyAnimation.Forward) if self.session_list.animation:
self.session_list.animation.setStartValue(self.session_widget.geometry()) self.session_list.animation.setDirection(QPropertyAnimation.Forward)
self.session_list.animation.setEndValue(self.session_panel.rect()) self.session_list.animation.setStartValue(self.session_widget.geometry())
self.session_list.animation.setEndValue(self.session_panel.rect())
self.session_list.show() self.session_list.show()
self.session_list.animation.start() self.session_list.animation.start()
......
...@@ -1301,8 +1301,8 @@ class Contact(object): ...@@ -1301,8 +1301,8 @@ class Contact(object):
@property @property
def info(self): def info(self):
try: try:
return self.note or ('@' + self.uri.uri.host if self.type == 'bonjour' else self.uri.uri) return self.note or (self.uri.uri.split('@')[1] if self.type == 'bonjour' else self.uri.uri)
except AttributeError: except (AttributeError, TypeError):
return '' return ''
@property @property
...@@ -4684,11 +4684,11 @@ class URIUtils(object): ...@@ -4684,11 +4684,11 @@ class URIUtils(object):
@classmethod @classmethod
def is_number(cls, token): def is_number(cls, token):
return cls.number_re.match(token.decode()) is not None return cls.number_re.match(token) is not None
@classmethod @classmethod
def trim_number(cls, token): def trim_number(cls, token):
return cls.number_trim_re.sub('', token.decode()).encode() return cls.number_trim_re.sub('', token)
@classmethod @classmethod
def find_contact(cls, uri, display_name=None, exact=True): def find_contact(cls, uri, display_name=None, exact=True):
...@@ -4701,8 +4701,9 @@ class URIUtils(object): ...@@ -4701,8 +4701,9 @@ class URIUtils(object):
if not uri.startswith(('sip:', 'sips:')): if not uri.startswith(('sip:', 'sips:')):
uri = 'sip:' + uri uri = 'sip:' + uri
uri = SIPURI.parse(str(uri).translate(translation_table)) uri = SIPURI.parse(str(uri).translate(translation_table))
if cls.is_number(uri.user):
uri.user = cls.trim_number(uri.user) if cls.is_number(uri.user.decode()):
uri.user = cls.trim_number(uri.user.decode()).encode()
is_number = True is_number = True
else: else:
is_number = False is_number = False
...@@ -4714,7 +4715,7 @@ class URIUtils(object): ...@@ -4714,7 +4715,7 @@ class URIUtils(object):
return contact, contact_uri return contact, contact_uri
if not exact and is_number: if not exact and is_number:
number = uri.user.lstrip('0') number = uri.user.decode().lstrip('0')
counter = count() counter = count()
matched_numbers = [] matched_numbers = []
for contact in (contact for contact in contact_model.iter_contacts() if contact.group.virtual): for contact in (contact for contact in contact_model.iter_contacts() if contact.group.virtual):
...@@ -4732,7 +4733,7 @@ class URIUtils(object): ...@@ -4732,7 +4733,7 @@ class URIUtils(object):
if matched_numbers: if matched_numbers:
return matched_numbers[0][2:] # ratio, index, contact, uri return matched_numbers[0][2:] # ratio, index, contact, uri
display_name = display_name or "%s@%s" % (uri.user, uri.host) display_name = display_name or "%s@%s" % (uri.user.decode(), uri.host.decode())
contact = Contact(DummyContact(display_name, [DummyContactURI(str(uri).partition(':')[2], default=True)]), None) contact = Contact(DummyContact(display_name, [DummyContactURI(str(uri).partition(':')[2], default=True)]), None)
return contact, contact.uri return contact, contact.uri
......
...@@ -19,6 +19,7 @@ from sipsimple.util import ISOTimestamp ...@@ -19,6 +19,7 @@ from sipsimple.util import ISOTimestamp
from blink.resources import ApplicationData, Resources from blink.resources import ApplicationData, Resources
from blink.util import run_in_gui_thread from blink.util import run_in_gui_thread
import traceback
__all__ = ['HistoryManager'] __all__ = ['HistoryManager']
...@@ -31,10 +32,11 @@ class HistoryManager(object, metaclass=Singleton): ...@@ -31,10 +32,11 @@ class HistoryManager(object, metaclass=Singleton):
def __init__(self): def __init__(self):
try: try:
data = pickle.load(open(ApplicationData.get('calls_history'))) data = pickle.load(open(ApplicationData.get('calls_history'), "rb"))
if not isinstance(data, list) or not all(isinstance(item, HistoryEntry) and item.text and isinstance(item.call_time, ISOTimestamp) for item in data): if not isinstance(data, list) or not all(isinstance(item, HistoryEntry) and item.text and isinstance(item.call_time, ISOTimestamp) for item in data):
raise ValueError("invalid save data") raise ValueError("invalid save data")
except Exception: except Exception as e:
traceback.print_exc()
self.calls = [] self.calls = []
else: else:
self.calls = data[-self.history_size:] self.calls = data[-self.history_size:]
...@@ -66,6 +68,7 @@ class HistoryManager(object, metaclass=Singleton): ...@@ -66,6 +68,7 @@ class HistoryManager(object, metaclass=Singleton):
return return
session = notification.sender session = notification.sender
entry = HistoryEntry.from_session(session) entry = HistoryEntry.from_session(session)
if session.direction == 'incoming': if session.direction == 'incoming':
if notification.data.code != 487 or notification.data.failure_reason != 'Call completed elsewhere': if notification.data.code != 487 or notification.data.failure_reason != 'Call completed elsewhere':
entry.failed = True entry.failed = True
...@@ -184,7 +187,13 @@ class HistoryEntry(object): ...@@ -184,7 +187,13 @@ class HistoryEntry(object):
duration = session.end_time - session.start_time duration = session.end_time - session.start_time
else: else:
duration = None duration = None
remote_uri = '%s@%s' % (session.remote_identity.uri.user, session.remote_identity.uri.host) user = session.remote_identity.uri.user
domain = session.remote_identity.uri.host
user = user.decode() if isinstance(user, bytes) else user
domain = domain.decode() if isinstance(domain, bytes) else domain
remote_uri = '%s@%s' % (user, domain)
match = cls.phone_number_re.match(remote_uri) match = cls.phone_number_re.match(remote_uri)
if match: if match:
remote_uri = match.group('number') remote_uri = match.group('number')
...@@ -195,5 +204,3 @@ class HistoryEntry(object): ...@@ -195,5 +204,3 @@ class HistoryEntry(object):
else: else:
display_name = contact.name display_name = contact.name
return cls(session.direction, display_name, remote_uri, str(session.account.id), call_time, duration) return cls(session.direction, display_name, remote_uri, str(session.account.id), call_time, duration)
...@@ -497,6 +497,7 @@ class BlinkSession(BlinkSessionBase): ...@@ -497,6 +497,7 @@ class BlinkSession(BlinkSessionBase):
self._sibling = None self._sibling = None
self._smp_handler = Null self._smp_handler = Null
self.routes = None
def _get_state(self): def _get_state(self):
return self.__dict__['state'] return self.__dict__['state']
...@@ -713,7 +714,7 @@ class BlinkSession(BlinkSessionBase): ...@@ -713,7 +714,7 @@ class BlinkSession(BlinkSessionBase):
self.stream_descriptions = None self.stream_descriptions = None
self.state = 'connecting' self.state = 'initializing'
notification_center.post_notification('BlinkSessionConnectionProgress', sender=self, data=NotificationData(stage='connecting')) notification_center.post_notification('BlinkSessionConnectionProgress', sender=self, data=NotificationData(stage='connecting'))
def connect(self): def connect(self):
...@@ -737,6 +738,7 @@ class BlinkSession(BlinkSessionBase): ...@@ -737,6 +738,7 @@ class BlinkSession(BlinkSessionBase):
uri = self.uri uri = self.uri
else: else:
uri = self.uri uri = self.uri
self.lookup = DNSLookup() self.lookup = DNSLookup()
notification_center.add_observer(self, sender=self.lookup) notification_center.add_observer(self, sender=self.lookup)
self.lookup.lookup_sip_proxy(uri, settings.sip.transport_list) self.lookup.lookup_sip_proxy(uri, settings.sip.transport_list)
...@@ -912,13 +914,14 @@ class BlinkSession(BlinkSessionBase): ...@@ -912,13 +914,14 @@ class BlinkSession(BlinkSessionBase):
uri = 'sip:' + uri uri = 'sip:' + uri
uri = SIPURI.parse(str(uri).translate(translation_table)) uri = SIPURI.parse(str(uri).translate(translation_table))
if URIUtils.is_number(uri.user): if URIUtils.is_number(uri.user.decode()):
uri.user = URIUtils.trim_number(uri.user) user = URIUtils.trim_number(uri.user.decode())
if isinstance(self.account, Account): if isinstance(self.account, Account):
if self.account.pstn.idd_prefix is not None: if self.account.pstn.idd_prefix is not None:
uri.user = re.sub(r'^\+', self.account.pstn.idd_prefix, uri.user) user = re.sub(r'^\+', self.account.pstn.idd_prefix, user)
if self.account.pstn.prefix is not None: if self.account.pstn.prefix is not None:
uri.user = self.account.pstn.prefix + uri.user user = self.account.pstn.prefix + user
uri.user = user.encode()
return uri return uri
def _sync_chat_peer_name(self): def _sync_chat_peer_name(self):
...@@ -943,9 +946,13 @@ class BlinkSession(BlinkSessionBase): ...@@ -943,9 +946,13 @@ class BlinkSession(BlinkSessionBase):
if notification.sender is self.lookup: if notification.sender is self.lookup:
routes = notification.data.result routes = notification.data.result
if routes: if routes:
self.routes = routes
self.state = 'connection/dns_lookup_succeeded'
self.info.update(self)
self.sip_session = Session(self.account) self.sip_session = Session(self.account)
self.sip_session.connect(ToHeader(self.uri), routes, list(self.streams)) self.sip_session.connect(ToHeader(self.uri), routes, list(self.streams))
else: else:
self.routes = None
self._terminate(reason='Destination not found', error=True) self._terminate(reason='Destination not found', error=True)
def _NH_DNSLookupDidFail(self, notification): def _NH_DNSLookupDidFail(self, notification):
...@@ -1659,7 +1666,7 @@ class AudioSessionWidget(base_class, ui_class): ...@@ -1659,7 +1666,7 @@ class AudioSessionWidget(base_class, ui_class):
session.zrtp_widget.hide() session.zrtp_widget.hide()
session.zrtp_widget.peer_name = stream_info.zrtp_peer_name session.zrtp_widget.peer_name = stream_info.zrtp_peer_name
session.zrtp_widget.peer_verified = stream_info.zrtp_verified session.zrtp_widget.peer_verified = stream_info.zrtp_verified
session.zrtp_widget.sas = stream_info.zrtp_sas.decode() session.zrtp_widget.sas = stream_info.zrtp_sas
session.zrtp_widget.setGeometry(rect) session.zrtp_widget.setGeometry(rect)
session.zrtp_widget.show() session.zrtp_widget.show()
session.zrtp_widget.peer_name_value.setFocus(Qt.OtherFocusReason) session.zrtp_widget.peer_name_value.setFocus(Qt.OtherFocusReason)
...@@ -2083,11 +2090,15 @@ class AudioSessionItem(object): ...@@ -2083,11 +2090,15 @@ class AudioSessionItem(object):
def _NH_BlinkSessionConnectionProgress(self, notification): def _NH_BlinkSessionConnectionProgress(self, notification):
stage = notification.data.stage stage = notification.data.stage
if stage == 'dns_lookup': if stage == 'initializing':
self.status = Status('Initializing...')
elif stage == 'connecting/dns_lookup':
self.status = Status('Looking up destination...') self.status = Status('Looking up destination...')
elif stage == 'connecting': elif stage == 'connecting' and self.blink_session.routes:
self.tls = self.blink_session.transport == 'tls' self.tls = self.blink_session.transport == 'tls'
self.status = Status('Connecting...') uri = self.blink_session.routes[0].uri
destination = '%s:%s' % (self.blink_session.transport, uri.host.decode())
self.status = Status('Trying %s' % destination)
elif stage == 'ringing': elif stage == 'ringing':
self.status = Status('Ringing...') self.status = Status('Ringing...')
elif stage == 'starting': elif stage == 'starting':
...@@ -2677,7 +2688,7 @@ class AudioSessionListView(QListView): ...@@ -2677,7 +2688,7 @@ class AudioSessionListView(QListView):
def keyPressEvent(self, event): def keyPressEvent(self, event):
char = event.text().upper() char = event.text().upper()
if char and char in string.digits+string.uppercase+'#*': if char and char in string.digits + string.ascii_uppercase + '#*':
digit_map = {'2': 'ABC', '3': 'DEF', '4': 'GHI', '5': 'JKL', '6': 'MNO', '7': 'PQRS', '8': 'TUV', '9': 'WXYZ'} digit_map = {'2': 'ABC', '3': 'DEF', '4': 'GHI', '5': 'JKL', '6': 'MNO', '7': 'PQRS', '8': 'TUV', '9': 'WXYZ'}
letter_map = {letter: digit for digit, letter_group in digit_map.items() for letter in letter_group} letter_map = {letter: digit for digit, letter_group in digit_map.items() for letter in letter_group}
for session in (s for s in self.model().sessions if s.active): for session in (s for s in self.model().sessions if s.active):
...@@ -3150,10 +3161,12 @@ class ChatSessionItem(object): ...@@ -3150,10 +3161,12 @@ class ChatSessionItem(object):
elif data.state == 'idle': elif data.state == 'idle':
self.remote_composing = False self.remote_composing = False
self.remote_composing_timer.stop() self.remote_composing_timer.stop()
self.widget.update_content(self)
def _SH_RemoteComposingTimerTimeout(self): def _SH_RemoteComposingTimerTimeout(self):
self.remote_composing_timer.stop() self.remote_composing_timer.stop()
self.remote_composing = False self.remote_composing = False
self.widget.update_content(self)
def handle_notification(self, notification): def handle_notification(self, notification):
handler = getattr(self, '_NH_%s' % notification.name, Null) handler = getattr(self, '_NH_%s' % notification.name, Null)
...@@ -4036,10 +4049,13 @@ class BlinkFileTransfer(BlinkSessionBase): ...@@ -4036,10 +4049,13 @@ class BlinkFileTransfer(BlinkSessionBase):
notification.center.remove_observer(self, sender=notification.sender) notification.center.remove_observer(self, sender=notification.sender)
if self.state in ('ending', 'ended'): if self.state in ('ending', 'ended'):
return return
self.state = 'connecting'
routes = notification.data.result routes = notification.data.result
if not routes: if not routes:
self._terminate(failure_reason='Destination not found') self._terminate(failure_reason='Destination not found')
self.routes = None
return return
self.routes = routes
self.sip_session = Session(self.account) self.sip_session = Session(self.account)
self.stream = MediaStreamRegistry.FileTransferStream(self.file_selector, 'sendonly', transfer_id=self.id) self.stream = MediaStreamRegistry.FileTransferStream(self.file_selector, 'sendonly', transfer_id=self.id)
self.handler = self.stream.handler self.handler = self.stream.handler
...@@ -4052,7 +4068,7 @@ class BlinkFileTransfer(BlinkSessionBase): ...@@ -4052,7 +4068,7 @@ class BlinkFileTransfer(BlinkSessionBase):
self._terminate(failure_reason='DNS Lookup failed') self._terminate(failure_reason='DNS Lookup failed')
def _NH_SIPSessionNewOutgoing(self, notification): def _NH_SIPSessionNewOutgoing(self, notification):
self.state = 'connecting' self.state = 'initializing'
def _NH_SIPSessionGotProvisionalResponse(self, notification): def _NH_SIPSessionGotProvisionalResponse(self, notification):
if notification.data.code == 180: if notification.data.code == 180:
......
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