status-desktop/ui/app/AppLayouts/Chat/ContactsColumn/ChannelList.qml

66 lines
2.0 KiB
QML
Raw Normal View History

2020-06-17 19:18:31 +00:00
import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13
2020-05-28 11:06:17 +00:00
import "../../../../shared"
import "../../../../imports"
import "../components"
Item {
property alias channelListCount: chatGroupsListView.count
property string searchStr: ""
2020-05-28 11:06:17 +00:00
id: chatGroupsContainer
Layout.fillHeight: true
Layout.fillWidth: true
ListView {
id: chatGroupsListView
anchors.fill: parent
model: chatsModel.chats
delegate: Channel {
name: model.name
lastMessage: model.lastMessage
timestamp: model.timestamp
chatType: model.chatType
unviewedMessagesCount: model.unviewedMessagesCount
searchStr: chatGroupsContainer.searchStr
}
2020-05-28 14:58:25 +00:00
onCountChanged: {
if (count > 0 && chatsModel.activeChannelIndex > -1) {
// If a chat is added or removed, we set the current index to the first value
chatsModel.activeChannelIndex = 0;
currentIndex = 0;
} else {
if(chatsModel.activeChannelIndex > -1){
chatGroupsListView.currentIndex = 0;
} else {
// Initial state. No chat has been selected yet
chatGroupsListView.currentIndex = -1;
}
}
}
}
Connections {
target: chatsModel.chats
onDataChanged: {
// If the current active channel receives messages and changes its position,
// refresh the currentIndex accordingly
if(chatsModel.activeChannelIndex !== chatGroupsListView.currentIndex){
chatGroupsListView.currentIndex = chatsModel.activeChannelIndex
2020-05-28 14:58:25 +00:00
}
}
2020-05-28 11:06:17 +00:00
}
Connections {
target: chatsModel
onActiveChannelChanged: {
chatGroupsListView.currentIndex = chatsModel.activeChannelIndex
}
}
2020-06-17 19:18:31 +00:00
}
/*##^##
Designer {
D{i:0;autoSize:true;height:480;width:640}
}
##^##*/