fix(GroupInfoPopup): check if channel exists

This happens because sometimes channel property in GroupInfoPopup is null.
This commit avoid crashes.

Closes: #3993
This commit is contained in:
B.Melnik 2021-11-03 15:06:10 +03:00 committed by Iuri Matias
parent 7416294513
commit a4ea767ab6
1 changed files with 80 additions and 72 deletions

View File

@ -35,12 +35,14 @@ ModalPopup {
function resetSelectedMembers(){ function resetSelectedMembers(){
pubKeys = []; pubKeys = [];
memberCount = channel.members.rowCount();
memberCount = channel ? channel.members.rowCount() : 0;
currMemberCount = memberCount; currMemberCount = memberCount;
contactList.membersData.clear(); contactList.membersData.clear();
const contacts = getContactListObject() const contacts = getContactListObject()
if (channel) {
contacts.forEach(function (contact) { contacts.forEach(function (contact) {
if(popup.channel.contains(contact.publicKey) || if(popup.channel.contains(contact.publicKey) ||
!contact.isContact) { !contact.isContact) {
@ -49,6 +51,7 @@ ModalPopup {
contactList.membersData.append(contact) contactList.membersData.append(contact)
}) })
} }
}
onClosed: { onClosed: {
popup.destroy(); popup.destroy();
@ -56,14 +59,18 @@ ModalPopup {
onOpened: { onOpened: {
addMembers = false; addMembers = false;
if (popup.channel) {
popup.isAdmin = popup.channel.isAdmin(popup.store.profileModelInst.profile.pubKey) popup.isAdmin = popup.channel.isAdmin(popup.store.profileModelInst.profile.pubKey)
}
btnSelectMembers.enabled = false; btnSelectMembers.enabled = false;
resetSelectedMembers(); resetSelectedMembers();
} }
function doAddMembers(){ function doAddMembers(){
if(pubKeys.length === 0) return; if(pubKeys.length === 0) return;
if (popup.channel) {
chatsModel.groups.addMembers(popup.channel.id, JSON.stringify(pubKeys)); chatsModel.groups.addMembers(popup.channel.id, JSON.stringify(pubKeys));
}
popup.close(); popup.close();
} }
@ -77,14 +84,15 @@ ModalPopup {
width: 36 width: 36
height: 36 height: 36
anchors.top: parent.top anchors.top: parent.top
color: popup.channel.color color: popup.channel ? popup.channel.color : "transparent"
name: popup.channel.name name: popup.channel ? popup.channel.name : ""
} }
StyledTextEdit { StyledTextEdit {
id: groupNameTxt id: groupNameTxt
//% "Add members" //% "Add members"
text: addMembers ? qsTrId("add-members") : popup.channel.name text: addMembers ? qsTrId("add-members")
: (popup.channel ? popup.channel.name : "")
anchors.top: parent.top anchors.top: parent.top
anchors.topMargin: 2 anchors.topMargin: 2
anchors.left: letterIdenticon.right anchors.left: letterIdenticon.right
@ -288,7 +296,7 @@ ModalPopup {
spacing: Style.current.padding spacing: Style.current.padding
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
model: popup.channel.members model: popup.channel? popup.channel.members : []
delegate: Item { delegate: Item {
id: contactRow id: contactRow
width: parent.width width: parent.width