Release v0.1.54: scheduled location sessions and paged voice delivery history
This commit is contained in:
+8
-5
@@ -158,7 +158,7 @@ class Locations:
|
||||
viewerIds=[v['id'] for v in grant['viewers']],displayIds=[v['id'] for v in grant['displays']],
|
||||
phoneIds=[v['id'] for v in grant.get('phones',[])],receipt=grant['receipt'],
|
||||
intervalSeconds=grant.get('intervalSeconds',300),viewOnly=grant.get('viewOnly',False),
|
||||
sampleIntervalSeconds=grant.get('sampleIntervalSeconds',60),
|
||||
sampleIntervalSeconds=grant.get('sampleIntervalSeconds',60),sharingMode=grant.get('sharingMode','scheduled'),
|
||||
historyEnabled=grant.get('historyEnabled',False),historyDefault=grant.get('historyDefault',False) and 'historyEnabled' not in grant,
|
||||
history=self.a.HISTORY.own_status(row['member_id']))
|
||||
if action=='configure':
|
||||
@@ -168,22 +168,25 @@ class Locations:
|
||||
if not interval_valid(interval):raise a.Problem('上传周期可选 10 秒、1/5 分钟,或 1 至 720 小时(最多 30 天)')
|
||||
sample=body.get('sampleIntervalSeconds',60)
|
||||
if type(sample) is not int or not 10 <= sample <= 86400:raise a.Problem('采集间隔可自定义 10 秒至 1 天,不支持一周等更长间隔')
|
||||
mode=body.get('sharingMode','scheduled')
|
||||
if mode not in ('scheduled','realtime'):raise a.Problem('请选择定时采集或实时共享')
|
||||
if mode=='realtime':interval=sample=10
|
||||
if not any(chosen.values()):raise a.Problem('至少选择一位查看人;只查看家人无需开启自己的共享')
|
||||
history=body.get('historyEnabled',False)
|
||||
if type(history) is not bool or history and body.get('historyConsent') is not True:raise a.Problem('长期保存轨迹需要本人单独同意',403)
|
||||
self.sync.close(sid)
|
||||
grant.update(chosen,viewOnly=False,intervalSeconds=interval,sampleIntervalSeconds=sample,consentProtocol=3,historyEnabled=history)
|
||||
grant.update(chosen,viewOnly=False,intervalSeconds=interval,sampleIntervalSeconds=sample,sharingMode=mode,consentProtocol=3,historyEnabled=history)
|
||||
self.refresh_receipt(grant)
|
||||
a.DB.execute('UPDATE member_location_shares SET enabled=0,grant_json=? WHERE id=?',(json.dumps(grant),sid))
|
||||
self.latest.pop(sid,None)
|
||||
return dict(ok=True,receipt=grant['receipt'],intervalSeconds=interval,sampleIntervalSeconds=sample,historyEnabled=history,**chosen)
|
||||
return dict(ok=True,receipt=grant['receipt'],intervalSeconds=interval,sampleIntervalSeconds=sample,sharingMode=mode,historyEnabled=history,**chosen)
|
||||
if action=='start':
|
||||
if grant.get('viewOnly'):raise a.Problem('此手机仅用于查看家人,请先由本人设置共享对象',403)
|
||||
if body.get('consent') is not True or body.get('receipt')!=grant['receipt']:raise a.Problem('请本人核对姓名及查看人,并同意开启共享',403)
|
||||
a.DB.execute('UPDATE member_location_shares SET enabled=1 WHERE id=?',(sid,))
|
||||
self.latest[sid]=dict(seen=0,started=now,fix=None,signal='waiting')
|
||||
collection=self.sync.start(row,grant) if body.get('bufferedHistory') is True else {}
|
||||
return dict(ok=True,expires=row['expires'],intervalSeconds=grant.get('intervalSeconds',300),sampleIntervalSeconds=grant.get('sampleIntervalSeconds',60),**collection)
|
||||
return dict(ok=True,expires=row['expires'],intervalSeconds=grant.get('intervalSeconds',300),sampleIntervalSeconds=grant.get('sampleIntervalSeconds',60),sharingMode=grant.get('sharingMode','scheduled'),**collection)
|
||||
if action!='update' or not row['enabled']:raise a.Problem('位置共享尚未开启',403)
|
||||
old=self.latest.get(sid,dict(started=now,fix=None))
|
||||
if now-old.get('seen',0)<10:raise a.Problem('位置更新过于频繁',429)
|
||||
@@ -235,7 +238,7 @@ class Locations:
|
||||
position=fix if fix and state=='live' else None
|
||||
items.append(dict(id=row['member_id'],personId=valid[1]['id'],name=valid[1]['name'],status=state,
|
||||
signal=recent.get('signal','waiting'),lastSeen=seen or None,position=position,expires=row['expires'],
|
||||
intervalSeconds=upload,sampleIntervalSeconds=sample,scheduleReason='sampling' if sampling and sample>upload else 'upload',
|
||||
intervalSeconds=upload,sampleIntervalSeconds=sample,sharingMode=grant.get('sharingMode','scheduled'),scheduleReason='sampling' if sampling and sample>upload else 'upload',
|
||||
nextSampleAt=next_sample,nextUploadAt=next_upload))
|
||||
return items
|
||||
|
||||
|
||||
Reference in New Issue
Block a user