From 606f7c7eb672db0f1fd5f7f0531f0f01b5c8532a Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Thu, 14 Nov 2019 17:13:42 -0800 Subject: [PATCH] contactList: new messages make contact float to top --- go/ui/gcd.go | 14 +++++----- go/ui/manager.go | 12 ++++++-- qml/widgets/ContactList.qml | 55 +++++++++++++++++++++++++++++-------- 3 files changed, 60 insertions(+), 21 deletions(-) diff --git a/go/ui/gcd.go b/go/ui/gcd.go index af42c749..3ff20789 100644 --- a/go/ui/gcd.go +++ b/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"` diff --git a/go/ui/manager.go b/go/ui/manager.go index bf4ee769..11423539 100644 --- a/go/ui/manager.go +++ b/go/ui/manager.go @@ -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)) } } diff --git a/qml/widgets/ContactList.qml b/qml/widgets/ContactList.qml index 5b88d033..bcacf3be 100644 --- a/qml/widgets/ContactList.qml +++ b/qml/widgets/ContactList.qml @@ -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 } } + + } } + + } + + +