Use YowLayerEvent instead of Prop
We cannot use Prop in the __init__ of a YowLayer, since Prop is initialised only after all the YowLayers are initialized. Instead, we send a YowLayerEvent containing the values.
This commit is contained in:
parent
74a09ad07f
commit
ae826b1341
30
session.py
30
session.py
|
@ -91,9 +91,14 @@ class Session():
|
||||||
YowNetworkLayer
|
YowNetworkLayer
|
||||||
)
|
)
|
||||||
self.stack = YowStack(layers)
|
self.stack = YowStack(layers)
|
||||||
self.stack.setProp(SpectrumLayer.PROP_BACKEND, self.backend)
|
self.stack.broadcastEvent(
|
||||||
self.stack.setProp(SpectrumLayer.PROP_USER, self.user)
|
YowLayerEvent(SpectrumLayer.EVENT_START,
|
||||||
self.stack.setProp(SpectrumLayer.PROP_DB, self.db)
|
backend = self.backend,
|
||||||
|
user = self.user,
|
||||||
|
db = self.db,
|
||||||
|
legacyName = self.legacyName
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def __del__(self): # handleLogoutRequest
|
def __del__(self): # handleLogoutRequest
|
||||||
self.logout()
|
self.logout()
|
||||||
|
@ -406,18 +411,17 @@ class Session():
|
||||||
if receiptRequested: self.call("notification_ack", (jid, messageId))
|
if receiptRequested: self.call("notification_ack", (jid, messageId))
|
||||||
|
|
||||||
class SpectrumLayer(YowInterfaceLayer):
|
class SpectrumLayer(YowInterfaceLayer):
|
||||||
PROP_BACKEND = "yowsup.prop.SpectrumLayer.backend"
|
EVENT_START = "transwhat.event.SpectrumLayer.start"
|
||||||
PROP_USER = "yowsup.prop.SpectrumLayer.user"
|
|
||||||
PROP_DB = "yowsup.prop.SpectrumLayer.db"
|
def onEvent(self, layerEvent):
|
||||||
PROP_LEGACYNAME = "yowsup.prop.SpectrumLayer.legacyName"
|
# We cannot use __init__, since it can take no arguments
|
||||||
|
if layerEvent.name == SpectrumLayer.EVENT_START:
|
||||||
|
self.backend = layerEvent.getArg("backend")
|
||||||
|
self.user = layerEvent.getArg("user")
|
||||||
|
self.legacyName = layerEvent.getArg("legacyName")
|
||||||
|
db = layerEvent.getArg("db")
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
super(SpectrumLayer, self).__init__()
|
|
||||||
self.backend = self.getProp(SpectrumLayer.PROP_BACKEND)
|
|
||||||
self.user = self.getProp(SpectrumLayer.PROP_USER)
|
|
||||||
db = self.getProp(SpectrumLayer.PROP_DB)
|
|
||||||
self.buddies = BuddyList(legacyName, db)
|
self.buddies = BuddyList(legacyName, db)
|
||||||
self.legacyName(self.getProp(SpectrumLayer.PROP_LEGACYNAME))
|
|
||||||
self.bot = Bot(self)
|
self.bot = Bot(self)
|
||||||
|
|
||||||
@ProtocolEntityCallback("success")
|
@ProtocolEntityCallback("success")
|
||||||
|
|
Loading…
Reference in a new issue