mirror of
https://github.com/fazo96/telecommander.git
synced 2025-01-10 11:34:20 +01:00
can now see who's online
This commit is contained in:
parent
3a45b31276
commit
8405ae9237
15
lib/ui.js
15
lib/ui.js
@ -194,6 +194,21 @@ module.exports = function(data){
|
|||||||
data.chats.height = data.screen.height - data.cmdline.height
|
data.chats.height = data.screen.height - data.cmdline.height
|
||||||
data.screen.render()
|
data.screen.render()
|
||||||
})
|
})
|
||||||
|
data.screen.enableMouse()
|
||||||
|
data.screen.on('mouse',function(){
|
||||||
|
data.updateLastKnownAction()
|
||||||
|
})
|
||||||
|
data.screen.on('keypress',function(){
|
||||||
|
data.updateLastKnownAction()
|
||||||
|
})
|
||||||
|
/* // Commented out cause doens't work on most terminals
|
||||||
|
data.screen.on('focus',function(){
|
||||||
|
data.log('Screen Focus')
|
||||||
|
})
|
||||||
|
data.screen.on('blur',function(){
|
||||||
|
data.log('Screen blur')
|
||||||
|
})
|
||||||
|
*/
|
||||||
data.screen.key('tab',function(){
|
data.screen.key('tab',function(){
|
||||||
data.screen.focusPush(data.chats)
|
data.screen.focusPush(data.chats)
|
||||||
})
|
})
|
||||||
|
43
lib/util.js
43
lib/util.js
@ -1,4 +1,5 @@
|
|||||||
var blessed = require('blessed')
|
var blessed = require('blessed')
|
||||||
|
var moment = require('moment')
|
||||||
|
|
||||||
module.exports = function(data){
|
module.exports = function(data){
|
||||||
// Contacts holds all the contacts data
|
// Contacts holds all the contacts data
|
||||||
@ -12,18 +13,29 @@ module.exports = function(data){
|
|||||||
data.user = { } // holds data about current user
|
data.user = { } // holds data about current user
|
||||||
data.state = { } // keeps track of the telegram update state
|
data.state = { } // keeps track of the telegram update state
|
||||||
|
|
||||||
|
data.updateLastKnownAction = function(){
|
||||||
|
data.lastKnownAction = moment()
|
||||||
|
data.user.offline = false
|
||||||
|
}
|
||||||
|
|
||||||
data.addUser = function(u){
|
data.addUser = function(u){
|
||||||
if(!data.user || !data.user.id) return log("Can't add invalid user object to contacts",u)
|
if(!data.user || !data.user.id) return log("Can't add invalid user object to contacts",u)
|
||||||
data.contacts[u.id] = { user: u, id: u.id}
|
var wasOnline,online = false
|
||||||
|
data.contacts[u.id] = { user: u, id: u.id, online: online }
|
||||||
var name = data.getName(u.id,'user')
|
var name = data.getName(u.id,'user')
|
||||||
data.unameToUid[name] = u.id
|
data.unameToUid[name] = u.id
|
||||||
|
data.updateOnlineStatus(u.id,u.status)
|
||||||
data.rebuildChatList()
|
data.rebuildChatList()
|
||||||
/*
|
//data.log(u.toPrintable())
|
||||||
if(!data.chats.getItem(name)){
|
}
|
||||||
data.chats.addItem(name)
|
|
||||||
data.screen.render()
|
data.updateOnlineStatus = function(id,s){
|
||||||
|
if(s.instanceOf('api.type.UserStatusOffline')){
|
||||||
|
data.contacts[id].online_expires = moment.unix(s.was_online)
|
||||||
|
} else if(s.instanceOf('api.type.UserStatusOnline')){
|
||||||
|
data.contacts[id].online_expires = moment.unix(s.expires)
|
||||||
|
data.log('Online status for',data.getName(id,'user'),'expires',data.contacts[id].online_expires.fromNow())
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data.addGroup = function(group){
|
data.addGroup = function(group){
|
||||||
@ -38,6 +50,7 @@ module.exports = function(data){
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
data.log(group.toPrintable())
|
||||||
if(group.left === true) return;
|
if(group.left === true) return;
|
||||||
if(group.title === undefined){
|
if(group.title === undefined){
|
||||||
if(!isNaN(group)){ // Is ID
|
if(!isNaN(group)){ // Is ID
|
||||||
@ -50,12 +63,6 @@ module.exports = function(data){
|
|||||||
data.groups[group.id] = { id: group.id, title: group.title, group: group }
|
data.groups[group.id] = { id: group.id, title: group.title, group: group }
|
||||||
data.gnameToGid[group.title] = group.id
|
data.gnameToGid[group.title] = group.id
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
if(!data.chats.getItem(group.title)){
|
|
||||||
data.chats.addItem(group.title)
|
|
||||||
data.screen.render()
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
data.rebuildChatList()
|
data.rebuildChatList()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +122,7 @@ module.exports = function(data){
|
|||||||
}
|
}
|
||||||
|
|
||||||
data.getName = function(id,type,forChatList){
|
data.getName = function(id,type,forChatList){
|
||||||
var name,obj,toread
|
var name,obj,toread,online_expires
|
||||||
if(type === undefined) throw new Error('no type')
|
if(type === undefined) throw new Error('no type')
|
||||||
else if(id === data.user.id){
|
else if(id === data.user.id){
|
||||||
obj = data.user
|
obj = data.user
|
||||||
@ -125,6 +132,7 @@ module.exports = function(data){
|
|||||||
} else if(type === 'user' && data.contacts[id]) {
|
} else if(type === 'user' && data.contacts[id]) {
|
||||||
obj = data.contacts[id].user
|
obj = data.contacts[id].user
|
||||||
toread = data.contacts[id].toread
|
toread = data.contacts[id].toread
|
||||||
|
online_expires = data.contacts[id].online_expires
|
||||||
} else data.log('Failed to find name for',type,id)
|
} else data.log('Failed to find name for',type,id)
|
||||||
if(obj === undefined){
|
if(obj === undefined){
|
||||||
name = 'Unknown '+type+' '+id
|
name = 'Unknown '+type+' '+id
|
||||||
@ -138,8 +146,13 @@ module.exports = function(data){
|
|||||||
} else { // Group
|
} else { // Group
|
||||||
name = obj.title
|
name = obj.title
|
||||||
}
|
}
|
||||||
if(forChatList && toread > 0) return '* '+name
|
if(forChatList){
|
||||||
return name
|
if(toread > 0) name = '* '+name
|
||||||
|
if(online_expires && moment().isBefore(online_expires))
|
||||||
|
name = '{green-fg}'+name+'{/green-fg}'
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
return blessed.cleanTags(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
data.escapeFromList = function(txt){
|
data.escapeFromList = function(txt){
|
||||||
|
@ -176,6 +176,7 @@ data.downloadData = function(){
|
|||||||
data.client.contacts.getContacts('',function(cont){
|
data.client.contacts.getContacts('',function(cont){
|
||||||
//data.chats.clearItems()
|
//data.chats.clearItems()
|
||||||
//data.chats.add(data.statusWindow)
|
//data.chats.add(data.statusWindow)
|
||||||
|
//data.log(cont.toPrintable())
|
||||||
cont.users.list.forEach(data.addUser)
|
cont.users.list.forEach(data.addUser)
|
||||||
data.loader.stop()
|
data.loader.stop()
|
||||||
})
|
})
|
||||||
@ -191,7 +192,7 @@ data.downloadData = function(){
|
|||||||
data.log(data.state.unreadCount,'unread messages')
|
data.log(data.state.unreadCount,'unread messages')
|
||||||
//data.log('Started receiving updates')
|
//data.log('Started receiving updates')
|
||||||
// Can't use registerOnUpdates because it's apparently broken
|
// Can't use registerOnUpdates because it's apparently broken
|
||||||
//client.registerOnUpdates(onUpdate)
|
//data.client.registerOnUpdates(data.onUpdate)
|
||||||
setTimeout(data.downloadUpdates,1000)
|
setTimeout(data.downloadUpdates,1000)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -212,12 +213,21 @@ data.downloadUpdates = function(){
|
|||||||
data.appendMsg(msg,undefined,false,false)
|
data.appendMsg(msg,undefined,false,false)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if(res.other_updates){
|
||||||
|
for(c in res.other_updates.list) data.onUpdate(res.other_updates.list[c])
|
||||||
|
}
|
||||||
data.rebuildChatList()
|
data.rebuildChatList()
|
||||||
}
|
}
|
||||||
setTimeout(data.downloadUpdates,1000)
|
setTimeout(data.downloadUpdates,1000)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.onUpdate = function(o){
|
||||||
|
if(o.instanceOf('api.type.UpdateUserStatus')){
|
||||||
|
data.updateOnlineStatus(o.user_id,o.status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get message history with given name in the given box
|
// Get message history with given name in the given box
|
||||||
// BROKEN, need to be rethinked
|
// BROKEN, need to be rethinked
|
||||||
data.getMessages = function(name,box){
|
data.getMessages = function(name,box){
|
||||||
|
Loading…
Reference in New Issue
Block a user