webXMPP

Check-in [973917fdd9]
Login

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

Overview
Comment:Add in any XMMP nickname, to make it easier to see who the sender is
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256: 973917fdd9f4ae41d09948f6ee606b91df6da072109a9602d71fa1ae6164f478
User & Date: web 2020-05-04 17:35:51
Context
2020-05-06
01:11
Tighten up display of nicknames, integrate in destination selection check-in: bbb9ef0e3a user: web tags: master, trunk
2020-05-04
17:35
Add in any XMMP nickname, to make it easier to see who the sender is check-in: 973917fdd9 user: web tags: master, trunk
2019-12-08
04:37
Make images scroll. Factor img creation, add code for image URL's from XMPP MMS delivery. check-in: 93d231185f user: web tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to acct_xmpp.py.

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
..
43
44
45
46
47
48
49







50
51
52
53
54
55
56
57
58
..
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
...
171
172
173
174
175
176
177






178
179
180
181
182
183
184
#  together for purposes of viewing.
#
# user - Back-reference to User instance we're serving
# acct/pw - Account name and its password
# conn - XMPP Client instance
# stopping - Bool flag to tell us to wrap up our service loop
# status - String, latest "show" status from peer
# TBD: move this to xmpp.py, and it'll then be xmpp.Account class
class Account(object):
    def __init__(self, user, acct, pw):
	self.user = user
	self.acct = acct
	self.pw = pw
	self.conn = None
	self.stopping = False


    # Send a message
    # (User exclusion is held.)
    def send(self, towhom, msg):
	self.conn.send( xmpp.Message(towhom, msg) )

    # Callback from XMPP stack when we get a message
................................................................................
	if m is None:
	    # No data; typing, paused, etc.
	    return
	body  = toascii(m)
	sys.stderr.write("Message received from %s for %s\n" %
	    (sender, self.acct))
	sys.stderr.write("  Body: %s\n" % (body,))







	u = self.user
	u.add(True, aname(sender), toascii(body), None, None)

	# Learn into roster?
	if sender not in u.roster:
	    email = str(sender.node) + '@' + str(sender.domain)
	    sys.stderr.write("Add XMPP roster: %s\n" % (email,))
	    u.roster[email] = self
	    u.rgen += 1
................................................................................
	self.stopping = True

    # Update to presence status of somebody
    def presence(self, conn, presence):
	user = self.user

	# Debug, log so we can break out all the stupid XMPP cases
	if False:
	    f = open("/tmp/xmpp_presence.log", "a")
	    cPickle.dump(presence, f)
	    f.write("\n\n")
	    f.close()

	# Decode who sent to us
	# Note it can be somebody we haven't heard about; presence
................................................................................
	for bud in r.getItems():
	    budstr = toascii(bud)
	    if '@' not in budstr:
		# Ignore aliases
		continue
	    if r[bud].get("subscription"):
		buds.add(budstr)






	self.buddies = frozenset(buds)
	user = self.user
	for bud in buds:
	    user.roster[bud] = self
	del buds

	# And dispatch incoming messages







|







>







 







>
>
>
>
>
>
>

|







 







|







 







>
>
>
>
>
>







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
..
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
..
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
...
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#  together for purposes of viewing.
#
# user - Back-reference to User instance we're serving
# acct/pw - Account name and its password
# conn - XMPP Client instance
# stopping - Bool flag to tell us to wrap up our service loop
# status - String, latest "show" status from peer
# nicks - Map from an ID to any known nickname
class Account(object):
    def __init__(self, user, acct, pw):
	self.user = user
	self.acct = acct
	self.pw = pw
	self.conn = None
	self.stopping = False
	self.nicks = {}

    # Send a message
    # (User exclusion is held.)
    def send(self, towhom, msg):
	self.conn.send( xmpp.Message(towhom, msg) )

    # Callback from XMPP stack when we get a message
................................................................................
	if m is None:
	    # No data; typing, paused, etc.
	    return
	body  = toascii(m)
	sys.stderr.write("Message received from %s for %s\n" %
	    (sender, self.acct))
	sys.stderr.write("  Body: %s\n" % (body,))

	# Clean up sender, note nickname if any
	snd = aname(sender)
	if snd in self.nicks:
	    body = ("(%s) " % (self.nicks[snd],)) + body

	# Add as a new message
	u = self.user
	u.add(True, snd, toascii(body), None, None)

	# Learn into roster?
	if sender not in u.roster:
	    email = str(sender.node) + '@' + str(sender.domain)
	    sys.stderr.write("Add XMPP roster: %s\n" % (email,))
	    u.roster[email] = self
	    u.rgen += 1
................................................................................
	self.stopping = True

    # Update to presence status of somebody
    def presence(self, conn, presence):
	user = self.user

	# Debug, log so we can break out all the stupid XMPP cases
	if True:
	    f = open("/tmp/xmpp_presence.log", "a")
	    cPickle.dump(presence, f)
	    f.write("\n\n")
	    f.close()

	# Decode who sent to us
	# Note it can be somebody we haven't heard about; presence
................................................................................
	for bud in r.getItems():
	    budstr = toascii(bud)
	    if '@' not in budstr:
		# Ignore aliases
		continue
	    if r[bud].get("subscription"):
		buds.add(budstr)

		# Learn any nickname
		n = r.getName(bud)
		if n and (n != bud):
		    sys.stderr.write("Nickname %s -> %s\n" % (bud, n))
		    self.nicks[bud] = n
	self.buddies = frozenset(buds)
	user = self.user
	for bud in buds:
	    user.roster[bud] = self
	del buds

	# And dispatch incoming messages