From 50d18b6dcefb2c8163b20c6f99fc1d4a95333a70 Mon Sep 17 00:00:00 2001 From: Enrico Fasoli Date: Mon, 31 Aug 2015 19:02:15 +0200 Subject: [PATCH] fixed a bug and added incomplete group data support (not tested!) --- lib/util.js | 30 +++++++++++++++++++++++++----- telecommander.js | 6 +++--- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/lib/util.js b/lib/util.js index 3acca43..396207f 100644 --- a/lib/util.js +++ b/lib/util.js @@ -19,14 +19,30 @@ 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()) + } + } 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 @@ -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+')':'') } diff --git a/telecommander.js b/telecommander.js index 6cbcfae..a721d3f 100755 --- a/telecommander.js +++ b/telecommander.js @@ -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)) } }