1
0
mirror of https://github.com/fazo96/telecommander.git synced 2025-01-26 14:04:18 +01:00

add groups and users to contacts from updates

This commit is contained in:
Enrico Fasoli 2015-08-31 01:08:44 +00:00
parent 09e51675bb
commit 2fd2e737fc

View File

@ -368,7 +368,7 @@ function addUser(u){
contacts[u.id] = { user: u, id: u.id} contacts[u.id] = { user: u, id: u.id}
var name = getName(u.id,'user') var name = getName(u.id,'user')
unameToUid[name] = u.id unameToUid[name] = u.id
chats.addItem(name) if(!chats.getItem(name)) chats.addItem(name)
} }
function addGroup(group){ function addGroup(group){
@ -376,8 +376,7 @@ function addGroup(group){
if(group.left === true) return; if(group.left === true) return;
groups[group.id] = { id: group.id, title: group.title } groups[group.id] = { id: group.id, title: group.title }
gnameToGid[group.title] = group.id gnameToGid[group.title] = group.id
chats.addItem(group.title) if(!chats.getItem(group.title)) chats.addItem(group.title)
log('Added group:',group.title)
} }
// Updates the current state // Updates the current state
@ -397,7 +396,7 @@ function onUpdate(upd){
function downloadUpdates(){ function downloadUpdates(){
client.updates.getDifference(state.pts,state.date,state.qts,function(res){ client.updates.getDifference(state.pts,state.date,state.qts,function(res){
if(!res.instanceOf('api.type.updates.DifferenceEmpty')){ if(!res.instanceOf('api.type.updates.DifferenceEmpty')){
log('Got Diff: ',res.toPrintable()) //log('Got Diff: ',res.toPrintable())
if(res.state){ if(res.state){
updateState(res.state) updateState(res.state)
} }
@ -406,13 +405,8 @@ function downloadUpdates(){
appendMsg(msg,undefined,false,true) appendMsg(msg,undefined,false,true)
}) })
} }
if(res.chats){ if(res.chats) res.chats.list.forEach(addGroup)
res.chats.list.forEach(function(c){ if(res.users) res.users.list.forEach(addUser)
if(!groups[c.id]){
groups[c.id] = { id: c.id, title: c.title }
}
})
}
} }
setTimeout(downloadUpdates,1000) setTimeout(downloadUpdates,1000)
}) })