Changeset 82:276bc45eb40b in ralphm-patches


Ignore:
Timestamp:
Sep 21, 2016, 10:20:52 PM (3 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Move presence probe to session manager.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • c2s_stanza_handlers.patch

    r73 r82  
    11# HG changeset patch
    22# Parent 70ce9e97aa58780ac7f75a177fe8c0d2aaf1bfc6
     3# Parent  92b3f7089a61a8998999b67562917675732f8a4e
    34Add c2s protocol handlers for iq, message and presence stanzas.
    45
     
    4849 from wokkel.subprotocols import IQHandlerMixin
    4950 
    50 @@ -2031,3 +2031,418 @@
     51@@ -2031,3 +2031,411 @@
    5152         d = self.sessionManager.probePresence(user)
    5253         d.addCallback(cb)
     
    255256+    def __init__(self, *args, **kwargs):
    256257+        super(FakeUserSession, self).__init__(*args, **kwargs)
    257 +        self.probePresenceCalls = 0
    258258+        self.broadcastPresenceCalls = []
    259259+
    260260+
    261 +    def probePresence(self):
    262 +        self.probePresenceCalls += 1
    263 +
    264 +
    265 +    def broadcastPresence(self, presence, available):
    266 +        self.broadcastPresenceCalls.append((presence, available))
     261+    def broadcastPresence(self, presence):
     262+        self.broadcastPresenceCalls.append(presence)
    267263+
    268264+
     
    317313+
    318314+        self.assertTrue(self.protocol.availableReceived(stanza))
    319 +        self.assertEqual(1, self.session.probePresenceCalls)
    320315+        self.assertEqual(1, len(self.session.broadcastPresenceCalls))
    321 +        presence, available = self.session.broadcastPresenceCalls[-1]
     316+        presence = self.session.broadcastPresenceCalls[-1]
    322317+        self.assertIdentical(stanza, presence)
    323 +        self.assertTrue(available)
     318+        self.assertTrue(presence.available)
    324319+
    325320+
     
    345340+
    346341+        self.assertTrue(self.protocol.unavailableReceived(stanza))
    347 +        self.assertEqual(0, self.session.probePresenceCalls)
    348342+        self.assertEqual(1, len(self.session.broadcastPresenceCalls))
    349 +        presence, available = self.session.broadcastPresenceCalls[-1]
     343+        presence = self.session.broadcastPresenceCalls[-1]
    350344+        self.assertIdentical(stanza, presence)
    351 +        self.assertFalse(available)
     345+        self.assertFalse(presence.available)
    352346+
    353347+
     
    530524 
    531525     @asyncObserver
    532 @@ -1689,3 +1697,246 @@
     526@@ -1693,3 +1701,240 @@
    533527             presence = ProbePresence(recipient=entity,
    534528                                      sender=user.entity)
     
    720714+        else:
    721715+            session = self.xmlstream.avatar
    722 +            sendProbe = not session.presence
    723 +
    724 +            session.broadcastPresence(presence, available=True)
    725 +
    726 +            if sendProbe:
    727 +                session.probePresence()
    728 +
     716+            session.broadcastPresence(presence)
    729717+            return True
    730718+
     
    736724+        else:
    737725+            session = self.xmlstream.avatar
    738 +            session.broadcastPresence(presence, available=False)
     726+            session.broadcastPresence(presence)
    739727+            return True
    740728+
  • session_manager.patch

    r81 r82  
    687687     """
    688688     A message stanza.
    689 @@ -1175,3 +1244,448 @@
     689@@ -1175,3 +1244,452 @@
    690690 
    691691             self.onMessage(message.element)
     
    771771+
    772772+
    773 +    def probePresence(self):
    774 +        self.user.probePresence(self)
    775 +
    776 +
    777 +    def broadcastPresence(self, presence, available):
    778 +        if available:
     773+    def broadcastPresence(self, presence):
     774+        doProbe = presence.available and not self.presence
     775+
     776+        if presence.available:
    779777+            self.presence = presence
    780778+        else:
    781779+            self.presence = None
    782 +            # TODO: unset probeSent on user?
    783 +            # TODO: save last unavailable presence?
    784780+
    785781+        self.user.broadcastPresence(presence)
     782+
     783+        if doProbe:
     784+            self.user.probePresence(self)
    786785+
    787786+
     
    825824+
    826825+    def bindResource(self, session, resource):
     826+        if not self.sessions:
     827+            self.probeSent = False
     828+
    827829+        if resource is None:
    828830+            resource = randbytes.secureRandom(8).encode('hex')
     
    902904+    def deliverPresence(self, stanza):
    903905+        if not stanza.recipient.resource:
    904 +            # record
     906+            # TODO: record presence in self.contactPresences for future probes
    905907+
    906908+            for session in self.sessions.itervalues():
     
    933935+        Broadcast presence to all subscribed contacts and myself.
    934936+        """
     937+        # TODO: set probeSent to False when last session becomes unavailable
     938+        # TODO: save last unavailable presence?
    935939+        subscribers = yield self.roster.getSubscribers()
    936940+        self.realm.server.multicast(presence, subscribers)
Note: See TracChangeset for help on using the changeset viewer.