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

many ui improvements, marking messages as read fully works now

This commit is contained in:
Enrico Fasoli 2015-09-01 14:12:28 +02:00
parent 53330ba4a7
commit d6ff917688
3 changed files with 63 additions and 19 deletions

View File

@ -24,14 +24,15 @@ module.exports = function(data){
if(data.selectedWindow && data.msgBox[data.selectedWindow]) if(data.selectedWindow && data.msgBox[data.selectedWindow])
data.msgBox[data.selectedWindow].hide() data.msgBox[data.selectedWindow].hide()
data.selectedWindow = boxname; data.selectedWindow = boxname;
if(data.selectedWindow != data.statusWindow) if(data.selectedWindow != data.statusWindow){
data.cmdline.setLabel('to '+data.selectedWindow) data.cmdline.setLabel('to '+data.selectedWindow)
else {
data.markAsRead(data.selectedWindow) data.markAsRead(data.selectedWindow)
} else {
data.cmdline.setLabel('Command for Telecommander') data.cmdline.setLabel('Command for Telecommander')
} }
var newb = data.getMsgBox(data.selectedWindow) var newb = data.getMsgBox(data.selectedWindow)
newb.show() newb.show()
newb.emit('scroll')
data.screen.render() data.screen.render()
} }
@ -81,6 +82,11 @@ module.exports = function(data){
invertSelected: false, invertSelected: false,
style: data.getDefaultStyle(), style: data.getDefaultStyle(),
}) })
data.chats.key('tab',function(){
if(data.msgBox[data.selectedWindow])
data.msgBox[data.selectedWindow].focus()
})
data.screen.append(data.chats)
// Function to create a log box // Function to create a log box
data.mkBox = function(txt){ data.mkBox = function(txt){
@ -106,10 +112,15 @@ module.exports = function(data){
style: data.getDefaultStyle() style: data.getDefaultStyle()
}) })
b.key('enter',function(){ b.key('enter',function(){
this.setScrollPerc(100)
data.cmdline.focus() data.cmdline.focus()
}) })
b.on('scroll',function(){ b.on('scroll',function(){
if(b.getScroll() === 0) data.getMessages(txt,b) // The functions might not yet exist if this is the first window
if(b.getScroll() === 100 && data.markAsRead)
data.markAsRead(data.selectedWindow)
else if(b.getScroll() === 0 && data.getMessages)
data.getMessages(txt,b)
}) })
return b return b
} }
@ -126,17 +137,29 @@ module.exports = function(data){
border: { type: 'line' }, border: { type: 'line' },
style: data.getDefaultStyle() style: data.getDefaultStyle()
}) })
// mgsBox holds the chat boxes for every list entry
data.msgBox = { }
data.msgBox[data.statusWindow] = data.mkBox(data.statusWindow)
// Add stuff to the screen
data.screen.append(data.chats);
data.screen.append(data.msgBox[data.statusWindow]);
data.screen.append(data.cmdline); data.screen.append(data.cmdline);
data.chats.addItem(data.msgBox[data.statusWindow])
// Widget used to show loading windows
data.loader = blessed.loading({
width: '30%',
height: 5,
left: 'center',
top: 'center',
align: 'center',
valign: 'center',
border: { type: 'line' },
style: data.getDefaultStyle()
})
data.screen.append(data.loader)
// mgsBox holds the chat window instance for every chat
data.msgBox = { }
// Add the status window and switch to it
data.msgBox[data.statusWindow] = data.mkBox(data.statusWindow)
data.screen.append(data.msgBox[data.statusWindow])
data.switchToBox(data.statusWindow) data.switchToBox(data.statusWindow)
data.screen.on('resize',function(){ data.screen.on('resize',function(){
for(i in data.msgBox){ for(i in data.msgBox){
item = data.msgBox[i] item = data.msgBox[i]

View File

@ -77,7 +77,10 @@ module.exports = function(data){
return cmpstr(a,b) return cmpstr(a,b)
}) })
data.chats.setItems(list.map(function(item){ data.chats.setItems(list.map(function(item){
return data.getName(item.id,item.title?'group':'user',true) var n = data.getName(item.id,item.title?'group':'user',true)
if(n === undefined || n === null || !n || (n.trim && !n.trim()))
data.log('Empty list item:',JSON.stringify(item))
return n
})) }))
if(!data.chats.focused == data.screen.focused) data.chats.setScrollPerc(0) if(!data.chats.focused == data.screen.focused) data.chats.setScrollPerc(0)
//data.chats.select(data.selectedWindow) //data.chats.select(data.selectedWindow)
@ -88,8 +91,18 @@ module.exports = function(data){
var obj = data.nameToObj(name) var obj = data.nameToObj(name)
if(obj === undefined) return if(obj === undefined) return
obj.toread = 0 obj.toread = 0
data.client.messages.readHistory(data.idToPeer(obj.id,obj.title?'group':'user'),0,0,true)
data.rebuildChatList() data.rebuildChatList()
if(data.markingAsRead){
return // we don't want 2339238 requests
}
var maxid = obj.latest_message || 0
if(obj.latest_read_message > maxid) return // already read them messages
data.latest_read_message = maxid
data.markingAsRead = true
data.client.messages.readHistory(data.idToPeer(obj.id,obj.title?'group':'user'),maxid,0,true,function(res){
data.log('Done reading history:',res.toPrintable())
data.markingAsRead = false
})
} }
// Updates the current state // Updates the current state

View File

@ -133,10 +133,12 @@ data.sendMsg = function(name,str){
} }
var obj = data.nameToObj(name) var obj = data.nameToObj(name)
var peer = data.idToPeer(obj.id,obj.title?'group':'user') var peer = data.idToPeer(obj.id,obj.title?'group':'user')
var randid = parseInt(Math.random() * 1000000000) var randid = parseInt(Math.random() * 999999999)
//log('Sending Message to:',peer.toPrintable()) // Fix bug in telegram.link that doesn't send strings with accented letters
str = str.replace('è',"e'").replace('ù',"u'").replace('à',"a'").replace('ò',"o'").replace('ì',"i'")
//data.log('Sending Message to:',peer.toPrintable())
data.client.messages.sendMessage(peer,str,randid,function(sent){ data.client.messages.sendMessage(peer,str,randid,function(sent){
//log('Sent message:','"'+str+'"','to:',selectedWindow+':',sent.toPrintable()) data.log('Sent message:','"'+str+'"','to:',data.selectedWindow+':',sent.toPrintable())
}) })
} }
@ -170,11 +172,13 @@ data.whenReady = function(){
// Downloads stuff // Downloads stuff
data.downloadData = function(){ data.downloadData = function(){
data.log('Downloading data...') data.loader.load('Downloading data')
data.screen.render()
data.client.contacts.getContacts('',function(cont){ data.client.contacts.getContacts('',function(cont){
//data.chats.clearItems() //data.chats.clearItems()
//data.chats.add(data.statusWindow) //data.chats.add(data.statusWindow)
cont.users.list.forEach(data.addUser) cont.users.list.forEach(data.addUser)
data.loader.stop()
}) })
data.client.messages.getDialogs(0,0,10,function(dialogs){ data.client.messages.getDialogs(0,0,10,function(dialogs){
@ -293,9 +297,11 @@ data.appendMsg = function(msg,toBoxId,bare,prepend){
if(!obj.toread) obj.toread = 1 if(!obj.toread) obj.toread = 1
else obj.toread++ else obj.toread++
} }
// Update oldest message reference // Update oldest and latest message reference
if(!obj.oldest_message || parseInt(obj.oldest_message) > parseInt(msg.id)) if(!obj.oldest_message || parseInt(obj.oldest_message) > parseInt(msg.id))
obj.oldest_message = parseInt(msg.id) obj.oldest_message = parseInt(msg.id)
if(!obj.latest_message || parseInt(obj.latest_message) < parseInt(msg.id))
obj.latest_message = parseInt(msg.id)
box = data.getMsgBox(param) box = data.getMsgBox(param)
} }
if(bare) if(bare)
@ -317,6 +323,8 @@ data.appendMsg = function(msg,toBoxId,bare,prepend){
if(prepend) box.prepend(txt) if(prepend) box.prepend(txt)
else box.add(txt) else box.add(txt)
} }
// Mark messages as read if needed
if(param === data.selectedWindow) data.markAsRead(param)
return box return box
} }