webXMPP

Check-in [7ff7888f34]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Bringup, actual notification delivery
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:7ff7888f34461f1e238e1435dfb19ad02f288ffa78fc19173b6cbaceb8195e10
User & Date: vandyswa@gmail.com 2017-06-29 18:09:49
Context
2017-06-29
18:29
Initial markups, actual phone notifications check-in: cea9e18da0 user: vandyswa@gmail.com tags: master, trunk
18:09
Bringup, actual notification delivery check-in: 7ff7888f34 user: vandyswa@gmail.com tags: master, trunk
2017-06-28
21:00
Bring up initial message notification get check-in: 4dd13877ea user: vandyswa@gmail.com tags: master, trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to notified.py.

    41     41   #  that it's an XMPP message from Joe.  At detail 0, you
    42     42   #  would only see that there were new events, but no other
    43     43   #  detail.
    44     44   #
    45     45   # TBD: roster & presence.
    46     46   #
    47     47   import sys, json, time, os
           48  +w = sys.stdout.write
    48     49   import notify2
    49     50   import pong
    50     51   import pdb
    51     52   
    52     53   # For DBus sniffing
    53     54   import dbus, dbus.exceptions, dbus.mainloop.glib
    54     55   import threading
................................................................................
   150    151       f = open(os.getenv("HOME") + "/.config/notify.json", "r")
   151    152       d = json.loads(f.read())
   152    153       f.close()
   153    154       cfg = DictOb(d)
   154    155   
   155    156   # New notifications contained in this packet
   156    157   def notify(pak):
   157         -    raise Exception("Notification: TBD")
          158  +    global gen, w
          159  +
          160  +    inner = pak.inner
          161  +    w("Notification: gen %d -> %d\n" % (gen, inner["gen"]))
          162  +    for tup in inner["msgs"]:
          163  +        w("%r\n" % (tup,))
   158    164   
   159    165   # Endless execution, notification client
   160    166   def run():
   161    167       global cfg, gen
   162    168   
   163    169       # Get a wrapper for our pong network connection
   164    170       conn = pong.Client(cfg.server, cfg.port, cfg.user, cfg.password)
................................................................................
   201    207   
   202    208           # Failure
   203    209           if resp is None:
   204    210               time.sleep(pong.WAITNET)
   205    211               continue
   206    212   
   207    213           # Nothing happened
   208         -        pdb.set_trace()
   209    214           if resp.inner["gen"] == gen:
   210    215               continue
   211    216   
   212    217           # New messages
   213    218           notify(resp)
   214         -        gen = resp["gen"]
          219  +        gen = resp.inner["gen"]
   215    220   
   216    221   if __name__ == "__main__":
   217    222       load_cfg()
   218    223   
   219    224       # No arg, just be a service daemon
   220    225       if len(sys.argv) == 1:
   221    226           run()

Changes to udp.py.

    57     57   	self.handler = handler
    58     58   	self.user = user
    59     59   	self.pak = pak
    60     60   
    61     61       # We've been kicked awake, either from timeout or due
    62     62       #  to new notifications.  Send back a response.
    63     63       def release(self):
    64         -	log(" resolve PONG to " + self.user.name)
           64  +	log(" resolve PONG to %s %r" %
           65  +	    (self.user.name, self.pak.who))
    65     66   	self.handler.notifications(self.user, self.pak)
    66     67   	# We're all done
    67     68   	self.handler = self.user = self.pak = None
    68     69   
    69     70   class UDP(object):
    70     71       def __init__(self, cfg, approot):
    71     72   	global TIMEOUT, accounts
................................................................................
    98     99   
    99    100       # Generate an answer packet with any new notifications
   100    101       def _notifications(self, user, inpak):
   101    102   	det = inpak.inner["detail"]
   102    103   	nmsg = inpak.inner["nmsg"]
   103    104   	msgs = []
   104    105   	resp = {"gen": user.gen, "msgs": msgs}
          106  +	gen = inpak.inner["gen"]
   105    107   	for tup in user.msgs:
   106    108   	    if len(msgs) > nmsg:
   107    109   		break
          110  +
          111  +	    # Already seen?
          112  +	    if tup[0] < gen:
          113  +		continue
   108    114   
   109    115   	    # Assemble specified amount of detail
   110    116   	    body = []
   111    117   	    if det > 0:
   112    118   		# Direction
   113    119   		body.append(tup[1])
   114    120   	    if det > 1:
................................................................................
   116    122   		body.append(tup[2])
   117    123   	    if det > 2:
   118    124   		body.append(tup[3])
   119    125   	    msgs.append(body)
   120    126   
   121    127   	# Build reply packet around this inner message,
   122    128   	#  and send
   123         -	pdb.set_trace()
   124    129   	outpak = self.conn.pong(inpak, "got", resp)
   125    130   	self.conn.reply(inpak, outpak)
   126    131   
   127    132       def notifications(self, user, pak):
   128    133   	try:
   129    134   	    self._notifications(user, pak)
   130    135   	except: