mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-15 23:03:51 +01:00
add instance_handles to pushers so we have a way to refer to them even if the push token changes.
This commit is contained in:
parent
2d2953cf5f
commit
afb714f7be
7 changed files with 39 additions and 27 deletions
|
@ -30,13 +30,14 @@ class Pusher(object):
|
||||||
MAX_BACKOFF = 60 * 60 * 1000
|
MAX_BACKOFF = 60 * 60 * 1000
|
||||||
GIVE_UP_AFTER = 24 * 60 * 60 * 1000
|
GIVE_UP_AFTER = 24 * 60 * 60 * 1000
|
||||||
|
|
||||||
def __init__(self, _hs, user_name, app_id,
|
def __init__(self, _hs, instance_handle, user_name, app_id,
|
||||||
app_display_name, device_display_name, pushkey, pushkey_ts,
|
app_display_name, device_display_name, pushkey, pushkey_ts,
|
||||||
data, last_token, last_success, failing_since):
|
data, last_token, last_success, failing_since):
|
||||||
self.hs = _hs
|
self.hs = _hs
|
||||||
self.evStreamHandler = self.hs.get_handlers().event_stream_handler
|
self.evStreamHandler = self.hs.get_handlers().event_stream_handler
|
||||||
self.store = self.hs.get_datastore()
|
self.store = self.hs.get_datastore()
|
||||||
self.clock = self.hs.get_clock()
|
self.clock = self.hs.get_clock()
|
||||||
|
self.instance_handle = instance_handle,
|
||||||
self.user_name = user_name
|
self.user_name = user_name
|
||||||
self.app_id = app_id
|
self.app_id = app_id
|
||||||
self.app_display_name = app_display_name
|
self.app_display_name = app_display_name
|
||||||
|
|
|
@ -24,11 +24,12 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class HttpPusher(Pusher):
|
class HttpPusher(Pusher):
|
||||||
def __init__(self, _hs, user_name, app_id,
|
def __init__(self, _hs, instance_handle, user_name, app_id,
|
||||||
app_display_name, device_display_name, pushkey, pushkey_ts,
|
app_display_name, device_display_name, pushkey, pushkey_ts,
|
||||||
data, last_token, last_success, failing_since):
|
data, last_token, last_success, failing_since):
|
||||||
super(HttpPusher, self).__init__(
|
super(HttpPusher, self).__init__(
|
||||||
_hs,
|
_hs,
|
||||||
|
instance_handle,
|
||||||
user_name,
|
user_name,
|
||||||
app_id,
|
app_id,
|
||||||
app_display_name,
|
app_display_name,
|
||||||
|
|
|
@ -40,7 +40,7 @@ class PusherPool:
|
||||||
self._start_pushers(pushers)
|
self._start_pushers(pushers)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def add_pusher(self, user_name, kind, app_id,
|
def add_pusher(self, user_name, instance_handle, kind, app_id,
|
||||||
app_display_name, device_display_name, pushkey, lang, data):
|
app_display_name, device_display_name, pushkey, lang, data):
|
||||||
# we try to create the pusher just to validate the config: it
|
# we try to create the pusher just to validate the config: it
|
||||||
# will then get pulled out of the database,
|
# will then get pulled out of the database,
|
||||||
|
@ -49,6 +49,7 @@ class PusherPool:
|
||||||
self._create_pusher({
|
self._create_pusher({
|
||||||
"user_name": user_name,
|
"user_name": user_name,
|
||||||
"kind": kind,
|
"kind": kind,
|
||||||
|
"instance_handle": instance_handle,
|
||||||
"app_id": app_id,
|
"app_id": app_id,
|
||||||
"app_display_name": app_display_name,
|
"app_display_name": app_display_name,
|
||||||
"device_display_name": device_display_name,
|
"device_display_name": device_display_name,
|
||||||
|
@ -61,17 +62,18 @@ class PusherPool:
|
||||||
"failing_since": None
|
"failing_since": None
|
||||||
})
|
})
|
||||||
yield self._add_pusher_to_store(
|
yield self._add_pusher_to_store(
|
||||||
user_name, kind, app_id,
|
user_name, instance_handle, kind, app_id,
|
||||||
app_display_name, device_display_name,
|
app_display_name, device_display_name,
|
||||||
pushkey, lang, data
|
pushkey, lang, data
|
||||||
)
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _add_pusher_to_store(self, user_name, kind, app_id,
|
def _add_pusher_to_store(self, user_name, instance_handle, kind, app_id,
|
||||||
app_display_name, device_display_name,
|
app_display_name, device_display_name,
|
||||||
pushkey, lang, data):
|
pushkey, lang, data):
|
||||||
yield self.store.add_pusher(
|
yield self.store.add_pusher(
|
||||||
user_name=user_name,
|
user_name=user_name,
|
||||||
|
instance_handle=instance_handle,
|
||||||
kind=kind,
|
kind=kind,
|
||||||
app_id=app_id,
|
app_id=app_id,
|
||||||
app_display_name=app_display_name,
|
app_display_name=app_display_name,
|
||||||
|
@ -87,6 +89,7 @@ class PusherPool:
|
||||||
if pusherdict['kind'] == 'http':
|
if pusherdict['kind'] == 'http':
|
||||||
return HttpPusher(
|
return HttpPusher(
|
||||||
self.hs,
|
self.hs,
|
||||||
|
instance_handle=pusherdict['instance_handle'],
|
||||||
user_name=pusherdict['user_name'],
|
user_name=pusherdict['user_name'],
|
||||||
app_id=pusherdict['app_id'],
|
app_id=pusherdict['app_id'],
|
||||||
app_display_name=pusherdict['app_display_name'],
|
app_display_name=pusherdict['app_display_name'],
|
||||||
|
|
|
@ -31,7 +31,7 @@ class PusherRestServlet(RestServlet):
|
||||||
|
|
||||||
content = _parse_json(request)
|
content = _parse_json(request)
|
||||||
|
|
||||||
reqd = ['kind', 'app_id', 'app_display_name',
|
reqd = ['instance_handle', 'kind', 'app_id', 'app_display_name',
|
||||||
'device_display_name', 'pushkey', 'lang', 'data']
|
'device_display_name', 'pushkey', 'lang', 'data']
|
||||||
missing = []
|
missing = []
|
||||||
for i in reqd:
|
for i in reqd:
|
||||||
|
@ -45,6 +45,7 @@ class PusherRestServlet(RestServlet):
|
||||||
try:
|
try:
|
||||||
yield pusher_pool.add_pusher(
|
yield pusher_pool.add_pusher(
|
||||||
user_name=user.to_string(),
|
user_name=user.to_string(),
|
||||||
|
instance_handle=content['instance_handle'],
|
||||||
kind=content['kind'],
|
kind=content['kind'],
|
||||||
app_id=content['app_id'],
|
app_id=content['app_id'],
|
||||||
app_display_name=content['app_display_name'],
|
app_display_name=content['app_display_name'],
|
||||||
|
|
|
@ -29,7 +29,7 @@ class PusherStore(SQLBaseStore):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def get_pushers_by_app_id_and_pushkey(self, app_id_and_pushkey):
|
def get_pushers_by_app_id_and_pushkey(self, app_id_and_pushkey):
|
||||||
sql = (
|
sql = (
|
||||||
"SELECT id, user_name, kind, app_id,"
|
"SELECT id, user_name, kind, instance_handle, app_id,"
|
||||||
"app_display_name, device_display_name, pushkey, ts, data, "
|
"app_display_name, device_display_name, pushkey, ts, data, "
|
||||||
"last_token, last_success, failing_since "
|
"last_token, last_success, failing_since "
|
||||||
"FROM pushers "
|
"FROM pushers "
|
||||||
|
@ -45,15 +45,16 @@ class PusherStore(SQLBaseStore):
|
||||||
"id": r[0],
|
"id": r[0],
|
||||||
"user_name": r[1],
|
"user_name": r[1],
|
||||||
"kind": r[2],
|
"kind": r[2],
|
||||||
"app_id": r[3],
|
"instance_handle": r[3],
|
||||||
"app_display_name": r[4],
|
"app_id": r[4],
|
||||||
"device_display_name": r[5],
|
"app_display_name": r[5],
|
||||||
"pushkey": r[6],
|
"device_display_name": r[6],
|
||||||
"pushkey_ts": r[7],
|
"pushkey": r[7],
|
||||||
"data": r[8],
|
"pushkey_ts": r[8],
|
||||||
"last_token": r[9],
|
"data": r[9],
|
||||||
"last_success": r[10],
|
"last_token": r[10],
|
||||||
"failing_since": r[11]
|
"last_success": r[11],
|
||||||
|
"failing_since": r[12]
|
||||||
}
|
}
|
||||||
for r in rows
|
for r in rows
|
||||||
]
|
]
|
||||||
|
@ -63,7 +64,7 @@ class PusherStore(SQLBaseStore):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def get_all_pushers(self):
|
def get_all_pushers(self):
|
||||||
sql = (
|
sql = (
|
||||||
"SELECT id, user_name, kind, app_id,"
|
"SELECT id, user_name, kind, instance_handle, app_id,"
|
||||||
"app_display_name, device_display_name, pushkey, ts, data, "
|
"app_display_name, device_display_name, pushkey, ts, data, "
|
||||||
"last_token, last_success, failing_since "
|
"last_token, last_success, failing_since "
|
||||||
"FROM pushers"
|
"FROM pushers"
|
||||||
|
@ -76,15 +77,16 @@ class PusherStore(SQLBaseStore):
|
||||||
"id": r[0],
|
"id": r[0],
|
||||||
"user_name": r[1],
|
"user_name": r[1],
|
||||||
"kind": r[2],
|
"kind": r[2],
|
||||||
"app_id": r[3],
|
"instance_handle": r[3],
|
||||||
"app_display_name": r[4],
|
"app_id": r[4],
|
||||||
"device_display_name": r[5],
|
"app_display_name": r[5],
|
||||||
"pushkey": r[6],
|
"device_display_name": r[6],
|
||||||
"pushkey_ts": r[7],
|
"pushkey": r[7],
|
||||||
"data": r[8],
|
"pushkey_ts": r[8],
|
||||||
"last_token": r[9],
|
"data": r[9],
|
||||||
"last_success": r[10],
|
"last_token": r[10],
|
||||||
"failing_since": r[11]
|
"last_success": r[11],
|
||||||
|
"failing_since": r[12]
|
||||||
}
|
}
|
||||||
for r in rows
|
for r in rows
|
||||||
]
|
]
|
||||||
|
@ -92,7 +94,7 @@ class PusherStore(SQLBaseStore):
|
||||||
defer.returnValue(ret)
|
defer.returnValue(ret)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def add_pusher(self, user_name, kind, app_id,
|
def add_pusher(self, user_name, instance_handle, kind, app_id,
|
||||||
app_display_name, device_display_name,
|
app_display_name, device_display_name,
|
||||||
pushkey, pushkey_ts, lang, data):
|
pushkey, pushkey_ts, lang, data):
|
||||||
try:
|
try:
|
||||||
|
@ -105,6 +107,7 @@ class PusherStore(SQLBaseStore):
|
||||||
dict(
|
dict(
|
||||||
user_name=user_name,
|
user_name=user_name,
|
||||||
kind=kind,
|
kind=kind,
|
||||||
|
instance_handle=instance_handle,
|
||||||
app_display_name=app_display_name,
|
app_display_name=app_display_name,
|
||||||
device_display_name=device_display_name,
|
device_display_name=device_display_name,
|
||||||
ts=pushkey_ts,
|
ts=pushkey_ts,
|
||||||
|
@ -155,6 +158,7 @@ class PushersTable(Table):
|
||||||
"id",
|
"id",
|
||||||
"user_name",
|
"user_name",
|
||||||
"kind",
|
"kind",
|
||||||
|
"instance_handle",
|
||||||
"app_id",
|
"app_id",
|
||||||
"app_display_name",
|
"app_display_name",
|
||||||
"device_display_name",
|
"device_display_name",
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
CREATE TABLE IF NOT EXISTS pushers (
|
CREATE TABLE IF NOT EXISTS pushers (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
user_name TEXT NOT NULL,
|
user_name TEXT NOT NULL,
|
||||||
|
instance_handle varchar(32) NOT NULL,
|
||||||
kind varchar(8) NOT NULL,
|
kind varchar(8) NOT NULL,
|
||||||
app_id varchar(64) NOT NULL,
|
app_id varchar(64) NOT NULL,
|
||||||
app_display_name varchar(64) NOT NULL,
|
app_display_name varchar(64) NOT NULL,
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
CREATE TABLE IF NOT EXISTS pushers (
|
CREATE TABLE IF NOT EXISTS pushers (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
user_name TEXT NOT NULL,
|
user_name TEXT NOT NULL,
|
||||||
|
instance_handle varchar(32) NOT NULL,
|
||||||
kind varchar(8) NOT NULL,
|
kind varchar(8) NOT NULL,
|
||||||
app_id varchar(64) NOT NULL,
|
app_id varchar(64) NOT NULL,
|
||||||
app_display_name varchar(64) NOT NULL,
|
app_display_name varchar(64) NOT NULL,
|
||||||
|
|
Loading…
Reference in a new issue