Merge branch 'contact-sort' of dan/ui into master
the build was successful Details

This commit is contained in:
Sarah Jamie Lewis 2019-11-15 23:24:49 -08:00 committed by Gogs
commit 91f397d9e1
3 changed files with 60 additions and 21 deletions

View File

@ -28,13 +28,13 @@ 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"`
_ func(handle string) `signal:"IncContactUnreadCount"` _ func(handle string) `signal:"IncContactUnreadCount"`
_ func(handle string) `signal:"RemoveContact"` _ func(handle string) `signal:"RemoveContact"`
_ func(handle, key, value string) `signal:"UpdateContactAttribute"` _ func(handle, key, value string) `signal:"UpdateContactAttribute"`
// messages pane stuff // messages pane stuff
_ func(handle, from, displayName, message, image string, mID string, fromMe bool, ts string, ackd bool, error bool) `signal:"AppendMessage"` _ func(handle, from, displayName, message, image string, mID string, fromMe bool, ts string, ackd bool, error bool) `signal:"AppendMessage"`

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,24 +47,36 @@ 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
"_handle": handle, for (var i = 0; i < contactsModel.count; i++) {
"_displayName": displayName + (blocked ? " (blocked)" : "" ), if (contactsModel.get(i)["_lastMsgTs"] < lastMsgTs) {
"_image": image, index = i
"_server": server, break
"_badge": badge, }
"_status": status, }
"_blocked": blocked,
"_loading": loading, var newContact = {
"_loading": loading "_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) { 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
} }
} }
} }
} }
} }