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,19 +35,22 @@ 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()
contacts.forEach(function (contact) { if (channel) {
if(popup.channel.contains(contact.publicKey) || contacts.forEach(function (contact) {
!contact.isContact) { if(popup.channel.contains(contact.publicKey) ||
return; !contact.isContact) {
} return;
contactList.membersData.append(contact) }
}) contactList.membersData.append(contact)
})
}
} }
onClosed: { onClosed: {
@ -56,68 +59,73 @@ ModalPopup {
onOpened: { onOpened: {
addMembers = false; addMembers = false;
popup.isAdmin = popup.channel.isAdmin(popup.store.profileModelInst.profile.pubKey) if (popup.channel) {
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;
chatsModel.groups.addMembers(popup.channel.id, JSON.stringify(pubKeys)); if (popup.channel) {
chatsModel.groups.addMembers(popup.channel.id, JSON.stringify(pubKeys));
}
popup.close(); popup.close();
} }
header: Item { header: Item {
height: children[0].height height: children[0].height
width: parent.width width: parent.width
StatusQ.StatusLetterIdenticon { StatusQ.StatusLetterIdenticon {
id: letterIdenticon id: letterIdenticon
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")
anchors.top: parent.top : (popup.channel ? popup.channel.name : "")
anchors.topMargin: 2 anchors.top: parent.top
anchors.left: letterIdenticon.right anchors.topMargin: 2
anchors.leftMargin: Style.current.smallPadding anchors.left: letterIdenticon.right
font.bold: true anchors.leftMargin: Style.current.smallPadding
font.pixelSize: 14 font.bold: true
readOnly: true font.pixelSize: 14
wrapMode: Text.WordWrap readOnly: true
} wrapMode: Text.WordWrap
}
StyledText { StyledText {
text: { text: {
let cnt = memberCount; let cnt = memberCount;
if(addMembers){ if(addMembers){
//% "%1 / 10 members" //% "%1 / 10 members"
return qsTrId("%1-/-10-members").arg(cnt) return qsTrId("%1-/-10-members").arg(cnt)
} else { } else {
//% "%1 members" //% "%1 members"
if(cnt > 1) return qsTrId("%1-members").arg(cnt); if(cnt > 1) return qsTrId("%1-members").arg(cnt);
//% "1 member" //% "1 member"
return qsTrId("1-member"); return qsTrId("1-member");
}
} }
} width: 160
width: 160 anchors.left: letterIdenticon.right
anchors.left: letterIdenticon.right anchors.leftMargin: Style.current.smallPadding
anchors.leftMargin: Style.current.smallPadding anchors.top: groupNameTxt.bottom
anchors.top: groupNameTxt.bottom anchors.topMargin: 2
anchors.topMargin: 2 font.pixelSize: 14
font.pixelSize: 14 color: Style.current.secondaryText
color: Style.current.secondaryText }
}
Rectangle { Rectangle {
id: editGroupNameBtn id: editGroupNameBtn
visible: !addMembers && popup.isAdmin visible: !addMembers && popup.isAdmin
height: 24 height: 24
@ -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
@ -389,14 +397,14 @@ ModalPopup {
width: parent.width width: parent.width
height: children[0].height height: children[0].height
StatusQControls.StatusButton { StatusQControls.StatusButton {
visible: !addMembers visible: !addMembers
anchors.right: parent.right anchors.right: parent.right
//% "Add members" //% "Add members"
text: qsTrId("add-members") text: qsTrId("add-members")
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
onClicked: { onClicked: {
addMembers = true; addMembers = true;
} }
} }
StatusQControls.StatusRoundButton { StatusQControls.StatusRoundButton {
@ -415,14 +423,14 @@ ModalPopup {
} }
StatusQControls.StatusButton { StatusQControls.StatusButton {
id: btnSelectMembers id: btnSelectMembers
visible: addMembers visible: addMembers
enabled: memberCount >= currMemberCount enabled: memberCount >= currMemberCount
anchors.right: parent.right anchors.right: parent.right
//% "Add selected" //% "Add selected"
text: qsTrId("add-selected") text: qsTrId("add-selected")
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
onClicked: doAddMembers() onClicked: doAddMembers()
} }
} }