contactList: new messages make contact float to top
the build was successful Details

This commit is contained in:
Dan Ballard 2019-11-14 17:13:42 -08:00
parent c77737be1d
commit 606f7c7eb6
3 changed files with 60 additions and 21 deletions

View File

@ -28,7 +28,7 @@ type GrandCentralDispatcher struct {
_ string `property:"buildDate"` _ string `property:"buildDate"`
// contact list stuff // contact list stuff
_ func(handle, displayName, image, server string, badge, status int, blocked bool, loading bool) `signal:"AddContact"` _ 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, displayName string) `signal:"UpdateContactDisplayName"`
_ func(handle string, status int, loading bool) `signal:"UpdateContactStatus"` _ func(handle string, status int, loading bool) `signal:"UpdateContactStatus"`
_ func(handle string, blocked bool) `signal:"UpdateContactBlocked"` _ func(handle string, blocked bool) `signal:"UpdateContactBlocked"`

View File

@ -119,6 +119,14 @@ func (this *Manager) Acknowledge(mID string) {
this.gcd.Acknowledged(mID) 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) { func (this *Manager) AddContact(Handle string) {
if isGroup(Handle) { if isGroup(Handle) {
group := the.Peer.GetGroup(Handle) group := the.Peer.GetGroup(Handle)
@ -131,7 +139,7 @@ func (this *Manager) AddContact(Handle string) {
nick = Handle 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 return
} else if !isPeer(Handle) { } else if !isPeer(Handle) {
@ -150,7 +158,7 @@ func (this *Manager) AddContact(Handle string) {
nick = Handle 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))
} }
} }

View File

@ -47,14 +47,23 @@ ColumnLayout {
Connections { // ADD/REMOVE CONTACT ENTRIES Connections { // ADD/REMOVE CONTACT ENTRIES
target: gcd 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++) { for (var i = 0; i < contactsModel.count; i++) {
if (contactsModel.get(i)["_handle"] == handle) { if (contactsModel.get(i)["_handle"] == handle) {
return return
} }
} }
contactsModel.append({ 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, "_handle": handle,
"_displayName": displayName + (blocked ? " (blocked)" : "" ), "_displayName": displayName + (blocked ? " (blocked)" : "" ),
"_image": image, "_image": image,
@ -63,8 +72,11 @@ ColumnLayout {
"_status": status, "_status": status,
"_blocked": blocked, "_blocked": blocked,
"_loading": loading, "_loading": loading,
"_loading": loading "_loading": loading,
}) "_lastMsgTs": lastMsgTs
}
contactsModel.insert(index, newContact)
} }
onRemoveContact: function(handle) { onRemoveContact: function(handle) {
@ -74,6 +86,18 @@ ColumnLayout {
contactsModel.remove(i) contactsModel.remove(i)
return 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 loading: _loading
} }
} }
} }
} }
} }