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

fixed unintended auto-switch on new message

This commit is contained in:
Enrico Fasoli 2015-08-30 10:38:02 +00:00
parent c0712c1277
commit b9d66b3130

View File

@ -36,7 +36,7 @@ var defaultStyle = {
// Function to create a log box
function mkBox(){
return blessed.log({
var box = blessed.log({
right: 0,
width: '80%',
height: screen.height-3,
@ -45,6 +45,8 @@ function mkBox(){
draggable: true,
style: defaultStyle
})
box.hide()
return box
}
// Contact list window
@ -170,19 +172,24 @@ function command(cmd){
}
}
chats.addItem(msgBox[statusWindow])
switchToBox(statusWindow)
screen.render();
// What happens when a different window is selected
chats.on('select',function(selected){
log('SELECT:',selected.content)
msgBox[selectedWindow].hide()
selectedWindow = selected.content;
var newb = getMsgBox(selectedWindow)
newb.show()
switchToBox(selected.content)
})
function switchToBox(boxname){
msgBox[selectedWindow].hide()
selectedWindow = boxname;
var newb = getMsgBox(selectedWindow)
newb.show()
}
// Get msgBox for given chat, create if not exists
function getMsgBox(chat){
function getMsgBox(chat,switchto){
// Automatically convert ids to names
//if(contacts[chat]) chat = contacts[chat].user.id
//if(groups[chat]); // To be implemented
@ -200,6 +207,9 @@ function getMsgBox(chat){
getMessages(uid,msgBox[chat])
}
} else log('Getting window','"'+chat+'"')
if(switchto === true){
switchToBox(chat)
}
return msgBox[chat]
}
@ -290,7 +300,6 @@ function whenReady(){
// Downloads stuff
function downloadData(){
log('Downloading data...')
client.contacts.getContacts('',function(cont){
chats.clearItems()
chats.add(statusWindow)
@ -353,7 +362,7 @@ function downloadUpdates(){
res.new_messages.list.forEach(function(msg){
if(!msg.message) return log('Empty message!',msg)
//log('Scheduling message: '+msg.message)
appendMsg(msg)
appendMsg(msg,undefined,false,true)
})
}
setTimeout(downloadUpdates,1000)
@ -416,20 +425,26 @@ function appendToUserBox(msg,context){
}
// Writes given telegram.link "message" object to given boxId
function appendMsg(msg,toBoxId,bare){
var box
function appendMsg(msg,toBoxId,bare,smartmode){
var box,param
if(toBoxId != undefined){
box = toBoxId
} else {
if(msg.from_id === msg.to_id.user_id || msg.from_id != user.id){
box = getMsgBox(getName(msg.from_id))
param = getName(msg.from_id)
} else if(msg.to_id != user.id) {
// don't forget dat .user_id! don't need it in from_id...
box = getMsgBox(getName(msg.to_id.user_id))
param = getName(msg.to_id.user_id)
} else {
// Wtf ? maybe a group
log('Unknown message: from',msg.from_id,'to',msg.to_id)
return log('Unknown message: from',msg.from_id,'to',msg.to_id)
}
if(smartmode && !bare){
// Smart mode doesn't append the message to the box if it doesn't exist
// because when created, the box will download message history
if(msgBox[param] === undefined) return;
}
box = getMsgBox(param)
}
if(bare)
box.add(msg)