contactList: new messages make contact float to top #236
14
go/ui/gcd.go
14
go/ui/gcd.go
|
@ -28,13 +28,13 @@ type GrandCentralDispatcher struct {
|
|||
_ string `property:"buildDate"`
|
||||
|
||||
// contact list stuff
|
||||
_ func(handle, displayName, image, server string, badge, status int, blocked bool, loading bool) `signal:"AddContact"`
|
||||
_ func(handle, displayName string) `signal:"UpdateContactDisplayName"`
|
||||
_ func(handle string, status int, loading bool) `signal:"UpdateContactStatus"`
|
||||
_ func(handle string, blocked bool) `signal:"UpdateContactBlocked"`
|
||||
_ func(handle string) `signal:"IncContactUnreadCount"`
|
||||
_ func(handle string) `signal:"RemoveContact"`
|
||||
_ func(handle, key, value string) `signal:"UpdateContactAttribute"`
|
||||
_ func(handle, displayName, image, server string, badge, status int, blocked bool, loading bool, lastMsgTime int) `signal:"AddContact"`
|
||||
_ func(handle, displayName string) `signal:"UpdateContactDisplayName"`
|
||||
_ func(handle string, status int, loading bool) `signal:"UpdateContactStatus"`
|
||||
_ func(handle string, blocked bool) `signal:"UpdateContactBlocked"`
|
||||
_ func(handle string) `signal:"IncContactUnreadCount"`
|
||||
_ func(handle string) `signal:"RemoveContact"`
|
||||
_ func(handle, key, value string) `signal:"UpdateContactAttribute"`
|
||||
|
||||
// messages pane stuff
|
||||
_ func(handle, from, displayName, message, image string, mID string, fromMe bool, ts string, ackd bool, error bool) `signal:"AppendMessage"`
|
||||
|
|
|
@ -119,6 +119,14 @@ func (this *Manager) Acknowledge(mID string) {
|
|||
this.gcd.Acknowledged(mID)
|
||||
}
|
||||
|
||||
func getLastMessageTime(tl *model.Timeline) int {
|
||||
if len(tl.Messages) == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
return int(tl.Messages[len(tl.Messages)-1].Timestamp.Unix())
|
||||
}
|
||||
|
||||
func (this *Manager) AddContact(Handle string) {
|
||||
if isGroup(Handle) {
|
||||
group := the.Peer.GetGroup(Handle)
|
||||
|
@ -131,7 +139,7 @@ func (this *Manager) AddContact(Handle string) {
|
|||
nick = Handle
|
||||
}
|
||||
|
||||
this.gcd.AddContact(Handle, nick, picture, group.GroupServer, unread, int(connections.ConnectionStateToType[group.State]), false, false)
|
||||
this.gcd.AddContact(Handle, nick, picture, group.GroupServer, unread, int(connections.ConnectionStateToType[group.State]), false, false, getLastMessageTime(&group.Timeline))
|
||||
}
|
||||
return
|
||||
} else if !isPeer(Handle) {
|
||||
|
@ -150,7 +158,7 @@ func (this *Manager) AddContact(Handle string) {
|
|||
nick = Handle
|
||||
}
|
||||
|
||||
this.gcd.AddContact(Handle, nick, picture, "", unread, int(connections.ConnectionStateToType[contact.State]), contact.Blocked, false)
|
||||
this.gcd.AddContact(Handle, nick, picture, "", unread, int(connections.ConnectionStateToType[contact.State]), contact.Blocked, false, getLastMessageTime(&contact.Timeline))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,24 +47,36 @@ ColumnLayout {
|
|||
Connections { // ADD/REMOVE CONTACT ENTRIES
|
||||
target: gcd
|
||||
|
||||
onAddContact: function(handle, displayName, image, server, badge, status, blocked, loading) {
|
||||
onAddContact: function(handle, displayName, image, server, badge, status, blocked, loading, lastMsgTs) {
|
||||
|
||||
for (var i = 0; i < contactsModel.count; i++) {
|
||||
if (contactsModel.get(i)["_handle"] == handle) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
contactsModel.append({
|
||||
"_handle": handle,
|
||||
"_displayName": displayName + (blocked ? " (blocked)" : "" ),
|
||||
"_image": image,
|
||||
"_server": server,
|
||||
"_badge": badge,
|
||||
"_status": status,
|
||||
"_blocked": blocked,
|
||||
"_loading": loading,
|
||||
"_loading": loading
|
||||
})
|
||||
var index = contactsModel.count
|
||||
for (var i = 0; i < contactsModel.count; i++) {
|
||||
if (contactsModel.get(i)["_lastMsgTs"] < lastMsgTs) {
|
||||
index = i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
var newContact = {
|
||||
"_handle": handle,
|
||||
"_displayName": displayName + (blocked ? " (blocked)" : "" ),
|
||||
"_image": image,
|
||||
"_server": server,
|
||||
"_badge": badge,
|
||||
"_status": status,
|
||||
"_blocked": blocked,
|
||||
"_loading": loading,
|
||||
"_loading": loading,
|
||||
"_lastMsgTs": lastMsgTs
|
||||
}
|
||||
|
||||
contactsModel.insert(index, newContact)
|
||||
}
|
||||
|
||||
onRemoveContact: function(handle) {
|
||||
|
@ -74,6 +86,18 @@ ColumnLayout {
|
|||
contactsModel.remove(i)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onIncContactUnreadCount: function(handle) {
|
||||
var ts = Math.round((new Date()).getTime() / 1000);
|
||||
for(var i = 0; i < contactsModel.count; i++){
|
||||
if(contactsModel.get(i)["_handle"] == handle) {
|
||||
var contact = contactsModel.get(i)
|
||||
contact["_lastMsgTs"] = ts
|
||||
console.log("Found at " + i + " contact: " + contact)
|
||||
contactsModel.move(i, 0, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -95,6 +119,13 @@ ColumnLayout {
|
|||
loading: _loading
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Reference in New Issue