1
0
mirror of https://github.com/fazo96/telecommander.git synced 2025-01-09 11:29:51 +01:00

can now see who's online

This commit is contained in:
Enrico Fasoli 2015-09-04 17:49:10 +02:00
parent 3a45b31276
commit 8405ae9237
3 changed files with 54 additions and 16 deletions

View File

@ -194,6 +194,21 @@ module.exports = function(data){
data.chats.height = data.screen.height - data.cmdline.height
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.focusPush(data.chats)
})

View File

@ -1,4 +1,5 @@
var blessed = require('blessed')
var moment = require('moment')
module.exports = function(data){
// Contacts holds all the contacts data
@ -12,18 +13,29 @@ module.exports = function(data){
data.user = { } // holds data about current user
data.state = { } // keeps track of the telegram update state
data.updateLastKnownAction = function(){
data.lastKnownAction = moment()
data.user.offline = false
}
data.addUser = function(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')
data.unameToUid[name] = u.id
data.updateOnlineStatus(u.id,u.status)
data.rebuildChatList()
/*
if(!data.chats.getItem(name)){
data.chats.addItem(name)
data.screen.render()
//data.log(u.toPrintable())
}
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){
@ -38,6 +50,7 @@ module.exports = function(data){
return
}
}
data.log(group.toPrintable())
if(group.left === true) return;
if(group.title === undefined){
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.gnameToGid[group.title] = group.id
}
/*
if(!data.chats.getItem(group.title)){
data.chats.addItem(group.title)
data.screen.render()
}
*/
data.rebuildChatList()
}
@ -115,7 +122,7 @@ module.exports = function(data){
}
data.getName = function(id,type,forChatList){
var name,obj,toread
var name,obj,toread,online_expires
if(type === undefined) throw new Error('no type')
else if(id === data.user.id){
obj = data.user
@ -125,6 +132,7 @@ module.exports = function(data){
} else if(type === 'user' && data.contacts[id]) {
obj = data.contacts[id].user
toread = data.contacts[id].toread
online_expires = data.contacts[id].online_expires
} else data.log('Failed to find name for',type,id)
if(obj === undefined){
name = 'Unknown '+type+' '+id
@ -138,8 +146,13 @@ module.exports = function(data){
} else { // Group
name = obj.title
}
if(forChatList && toread > 0) return '* '+name
return name
if(forChatList){
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){

View File

@ -176,6 +176,7 @@ data.downloadData = function(){
data.client.contacts.getContacts('',function(cont){
//data.chats.clearItems()
//data.chats.add(data.statusWindow)
//data.log(cont.toPrintable())
cont.users.list.forEach(data.addUser)
data.loader.stop()
})
@ -191,7 +192,7 @@ data.downloadData = function(){
data.log(data.state.unreadCount,'unread messages')
//data.log('Started receiving updates')
// Can't use registerOnUpdates because it's apparently broken
//client.registerOnUpdates(onUpdate)
//data.client.registerOnUpdates(data.onUpdate)
setTimeout(data.downloadUpdates,1000)
})
}
@ -212,12 +213,21 @@ data.downloadUpdates = function(){
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()
}
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
// BROKEN, need to be rethinked
data.getMessages = function(name,box){