Channel.add_message(server_rx=): add new arg
This commit is contained in:
parent
fe2dfc1a35
commit
d9ba55621b
|
@ -54,25 +54,25 @@ class Channel:
|
||||||
for ep in self._listeners:
|
for ep in self._listeners:
|
||||||
ep.send_rendezvous_event({"phase": phase, "body": body})
|
ep.send_rendezvous_event({"phase": phase, "body": body})
|
||||||
|
|
||||||
def _add_message(self, side, phase, body):
|
def _add_message(self, side, phase, body, server_rx):
|
||||||
db = self._db
|
db = self._db
|
||||||
db.execute("INSERT INTO `messages`"
|
db.execute("INSERT INTO `messages`"
|
||||||
" (`appid`, `channelid`, `side`, `phase`, `body`, `server_rx`)"
|
" (`appid`, `channelid`, `side`, `phase`, `body`, `server_rx`)"
|
||||||
" VALUES (?,?,?,?, ?,?)",
|
" VALUES (?,?,?,?, ?,?)",
|
||||||
(self._appid, self._channelid, side, phase,
|
(self._appid, self._channelid, side, phase,
|
||||||
body, time.time()))
|
body, server_rx))
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
def allocate(self, side):
|
def allocate(self, side):
|
||||||
self._add_message(side, ALLOCATE, None)
|
self._add_message(side, ALLOCATE, None, time.time())
|
||||||
|
|
||||||
def add_message(self, side, phase, body):
|
def add_message(self, side, phase, body, server_rx):
|
||||||
self._add_message(side, phase, body)
|
self._add_message(side, phase, body, server_rx)
|
||||||
self.broadcast_message(phase, body)
|
self.broadcast_message(phase, body)
|
||||||
return self.get_messages() # for rendezvous_web.py POST /add
|
return self.get_messages() # for rendezvous_web.py POST /add
|
||||||
|
|
||||||
def deallocate(self, side, mood):
|
def deallocate(self, side, mood):
|
||||||
self._add_message(side, DEALLOCATE, mood)
|
self._add_message(side, DEALLOCATE, mood, time.time())
|
||||||
db = self._db
|
db = self._db
|
||||||
seen = set([row["side"] for row in
|
seen = set([row["side"] for row in
|
||||||
db.execute("SELECT `side` FROM `messages`"
|
db.execute("SELECT `side` FROM `messages`"
|
||||||
|
|
|
@ -132,7 +132,7 @@ class Adder(RelayResource):
|
||||||
|
|
||||||
app = self._rendezvous.get_app(appid)
|
app = self._rendezvous.get_app(appid)
|
||||||
channel = app.get_channel(channelid)
|
channel = app.get_channel(channelid)
|
||||||
messages = channel.add_message(side, phase, body)
|
messages = channel.add_message(side, phase, body, time.time())
|
||||||
response = {"welcome": self._welcome, "messages": messages,
|
response = {"welcome": self._welcome, "messages": messages,
|
||||||
"sent": time.time()}
|
"sent": time.time()}
|
||||||
return json_response(request, response)
|
return json_response(request, response)
|
||||||
|
|
|
@ -152,7 +152,7 @@ class WebSocketRendezvous(websocket.WebSocketServerProtocol):
|
||||||
raise Error("missing 'phase'")
|
raise Error("missing 'phase'")
|
||||||
if "body" not in msg:
|
if "body" not in msg:
|
||||||
raise Error("missing 'body'")
|
raise Error("missing 'body'")
|
||||||
channel.add_message(self._side, msg["phase"], msg["body"])
|
channel.add_message(self._side, msg["phase"], msg["body"], time.time())
|
||||||
|
|
||||||
def handle_deallocate(self, channel, msg):
|
def handle_deallocate(self, channel, msg):
|
||||||
deleted = channel.deallocate(self._side, msg.get("mood"))
|
deleted = channel.deallocate(self._side, msg.get("mood"))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user