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:
parent
5b35b58e7e
commit
50d18b6dce
30
lib/util.js
30
lib/util.js
@ -19,14 +19,30 @@ module.exports = function(data){
|
|||||||
}
|
}
|
||||||
|
|
||||||
data.addGroup = function(group){
|
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.left === true) return;
|
||||||
if(group.title === undefined){
|
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())
|
||||||
|
}
|
||||||
|
} 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)
|
||||||
}
|
}
|
||||||
data.groups[group.id] = { id: group.id, title: group.title }
|
|
||||||
data.gnameToGid[group.title] = group.id
|
|
||||||
if(!data.chats.getItem(group.title)) data.chats.addItem(group.title)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates the current state
|
// Updates the current state
|
||||||
@ -44,6 +60,10 @@ module.exports = function(data){
|
|||||||
}
|
}
|
||||||
|
|
||||||
data.nameForUser = function(u){
|
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+')':'')
|
return u.first_name + ' ' + u.last_name + (u.username?' (@'+u.username+')':'')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,9 +200,9 @@ data.downloadUpdates = function(){
|
|||||||
data.updateState(res.state)
|
data.updateState(res.state)
|
||||||
}
|
}
|
||||||
if(res.chats)
|
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)
|
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){
|
if(res.new_messages){
|
||||||
res.new_messages.list.forEach(function(msg){
|
res.new_messages.list.forEach(function(msg){
|
||||||
data.appendMsg(msg,undefined,false,true)
|
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.length > 0){
|
||||||
if(context.messages.list[0].to_id.chat_id){
|
if(context.messages.list[0].to_id.chat_id){
|
||||||
// Group message
|
// 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))
|
goesto = data.getMsgBox(data.getName(context.messages.list[0].to_id.chat_id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user