Browse Source

Merge branch 'contact-sort' of dan/ui into master

pull/238/head
Sarah Jamie Lewis 3 weeks ago
parent
commit
91f397d9e1
3 changed files with 60 additions and 21 deletions
  1. 7
    7
      go/ui/gcd.go
  2. 10
    2
      go/ui/manager.go
  3. 43
    12
      qml/widgets/ContactList.qml

+ 7
- 7
go/ui/gcd.go View File

@@ -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"`

+ 10
- 2
go/ui/manager.go View File

@@ -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))
}
}


+ 43
- 12
qml/widgets/ContactList.qml View File

@@ -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) {
@@ -76,6 +88,18 @@ ColumnLayout {
}
}
}

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)
}
}
}
}

ListModel { // CONTACT OBJECTS ARE STORED HERE ...
@@ -95,6 +119,13 @@ ColumnLayout {
loading: _loading
}
}


}
}


}




Loading…
Cancel
Save