1
0
mirror of https://github.com/fazo96/telecommander.git synced 2025-01-10 11:34:20 +01:00

fixed a bug and added incomplete group data support (not tested!)

This commit is contained in:
Enrico Fasoli 2015-08-31 19:02:15 +02:00
parent 5b35b58e7e
commit 50d18b6dce
2 changed files with 28 additions and 8 deletions

View File

@ -19,15 +19,31 @@ module.exports = function(data){
}
data.addGroup = function(group){
if(data.groups[group.id]) return;
if(data.groups[group.id]){
if(group.title && group.title != data.groups[group.id].title){
// Update title
var old = data.groups[group.id].title
data.groups[group.id].title = group.title
data.chats.getItem(old).content = group.title
data.screen.render()
data.gnameToGid[old] = undefined
return
}
}
if(group.left === true) return;
if(group.title === undefined){
return data.log('Undefined group title in group ',group)
if(!isNaN(group)){ // Is ID
data.groups[group] = { id: group, title: group }
} else {
var t = group.toPrintable ? group.toPrintable() : group
data.log('Undefined group title in group ',group.toPrintable())
}
data.groups[group.id] = { id: group.id, title: group.title }
} else {
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)
}
}
// Updates the current state
data.updateState = function(newstate){
@ -44,6 +60,10 @@ module.exports = function(data){
}
data.nameForUser = function(u){
if(u.first_name === undefined && u.last_name === undefined && u.username === undefined){
data.log('Zombie User: '+u)
return 'undefined'
}
return u.first_name + ' ' + u.last_name + (u.username?' (@'+u.username+')':'')
}

View File

@ -200,9 +200,9 @@ data.downloadUpdates = function(){
data.updateState(res.state)
}
if(res.chats)
for(c in res.chats.list) data.addGroup(c)
for(c in res.chats.list) data.addGroup(res.chats.list[c])
if(res.users)
for(c in res.users.list) data.addUser(c)
for(c in res.users.list) data.addUser(res.users.list[c])
if(res.new_messages){
res.new_messages.list.forEach(function(msg){
data.appendMsg(msg,undefined,false,true)
@ -251,7 +251,7 @@ data.appendToUserBox = function(msg,context){
if(context.messages.list.length > 0){
if(context.messages.list[0].to_id.chat_id){
// Group message
data.log('Chose',data.getName(context.messages.list[0].to_id.chat_id,'group'))
//data.log('Chose',data.getName(context.messages.list[0].to_id.chat_id,'group'))
goesto = data.getMsgBox(data.getName(context.messages.list[0].to_id.chat_id))
}
}