Surf Studio commited on
Commit
fd704a9
·
1 Parent(s): 9c7430b

tg: 30s dialog poll, session list

Browse files
Files changed (3) hide show
  1. lib/scheduler.js +1 -1
  2. lib/tg/index.js +16 -0
  3. routes/api.js +1 -0
lib/scheduler.js CHANGED
@@ -46,7 +46,7 @@ function start() {
46
  every('x-search', 60000, () => xscan.searchTick(), 12000)
47
  every('x-profiles', 180000, () => xscan.profileTick(), 40000)
48
  every('tg-watchdog', 60000, () => tg.watchdog(), 60000)
49
- every('tg-poll', 60000, () => tg.pollDialogs(), 95000)
50
  every('tg-catchup', 120000, () => tg.catchup(), 100000)
51
  every('tg-global', 180000, () => tg.globalSearch(), 130000)
52
  every('keepalive', 20 * 60000, keepAlive, 60000)
 
46
  every('x-search', 60000, () => xscan.searchTick(), 12000)
47
  every('x-profiles', 180000, () => xscan.profileTick(), 40000)
48
  every('tg-watchdog', 60000, () => tg.watchdog(), 60000)
49
+ every('tg-poll', 30000, () => tg.pollDialogs(), 60000)
50
  every('tg-catchup', 120000, () => tg.catchup(), 100000)
51
  every('tg-global', 180000, () => tg.globalSearch(), 130000)
52
  every('keepalive', 20 * 60000, keepAlive, 60000)
lib/tg/index.js CHANGED
@@ -654,6 +654,21 @@ async function reconnect() {
654
  return status()
655
  }
656
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
657
  /* ------------------------------------------------------------ chat list -- */
658
 
659
  function requireLive() {
@@ -777,6 +792,7 @@ module.exports = {
777
  logout,
778
  reconnect,
779
  dialogs,
 
780
  addRows,
781
  addByLink,
782
  removeChat,
 
654
  return status()
655
  }
656
 
657
+ /** Logged-in devices on this account (helps spot a duplicate copy stealing realtime updates). */
658
+ async function sessions() {
659
+ requireLive()
660
+ const res = await client.invoke(new Api.account.GetAuthorizations())
661
+ return (res.authorizations || []).map((a) => ({
662
+ current: Boolean(a.current),
663
+ device: a.deviceModel,
664
+ app: `${a.appName || ''} ${a.appVersion || ''}`.trim(),
665
+ platform: a.platform,
666
+ country: a.country,
667
+ created: a.dateCreated,
668
+ active: a.dateActive,
669
+ }))
670
+ }
671
+
672
  /* ------------------------------------------------------------ chat list -- */
673
 
674
  function requireLive() {
 
792
  logout,
793
  reconnect,
794
  dialogs,
795
+ sessions,
796
  addRows,
797
  addByLink,
798
  removeChat,
routes/api.js CHANGED
@@ -173,6 +173,7 @@ router.post('/tg/login/code', requireKey, wrap((req) => tg.submitCode(req.body |
173
  router.post('/tg/logout', requireKey, wrap(() => tg.logout()))
174
  router.post('/tg/reconnect', requireKey, wrap(() => tg.reconnect()))
175
  router.get('/tg/dialogs', requireKey, wrap(() => tg.dialogs()))
 
176
  router.post(
177
  '/tg/chats',
178
  requireKey,
 
173
  router.post('/tg/logout', requireKey, wrap(() => tg.logout()))
174
  router.post('/tg/reconnect', requireKey, wrap(() => tg.reconnect()))
175
  router.get('/tg/dialogs', requireKey, wrap(() => tg.dialogs()))
176
+ router.get('/tg/sessions', requireKey, wrap(() => tg.sessions()))
177
  router.post(
178
  '/tg/chats',
179
  requireKey,