fix(contacts): fix inconsistency when banning or unbanning contact
Fixes #10501 The problem was that didn't have access to the updated contact from status-go after banning or unbanning, so we just changed the banned property, but there is more that gets changed in the backend, like `removed` being set to `true` as well. With this fix, when you unban someone, you go back to a fresh start, as **non** contact, so you need to send a request again. That was the state you got if you restarted the app, so "re-sync" the state with status-go. Another issue was on the frontend (QML). When banned, and after restarting to get the right state, the unban button would be disabled and the Add contact request button would show, which is not good. We only want to send requests when unbanned.
This commit is contained in:
parent
088dd76257
commit
ceb810e63d
|
@ -516,12 +516,12 @@ QtObject:
|
||||||
var contact = self.getContactById(publicKey)
|
var contact = self.getContactById(publicKey)
|
||||||
|
|
||||||
let response = status_contacts.unblockContact(contact.id)
|
let response = status_contacts.unblockContact(contact.id)
|
||||||
|
# TODO there are chat updates too. We need to send them to the chat service
|
||||||
if not response.error.isNil:
|
if not response.error.isNil:
|
||||||
error "error unblocking contact ", msg = response.error.message
|
error "error unblocking contact ", msg = response.error.message
|
||||||
return
|
return
|
||||||
|
|
||||||
contact.blocked = false
|
self.parseContactsResponse(response)
|
||||||
self.saveContact(contact)
|
|
||||||
self.events.emit(SIGNAL_CONTACT_UNBLOCKED, ContactArgs(contactId: contact.id))
|
self.events.emit(SIGNAL_CONTACT_UNBLOCKED, ContactArgs(contactId: contact.id))
|
||||||
|
|
||||||
proc blockContact*(self: Service, publicKey: string) =
|
proc blockContact*(self: Service, publicKey: string) =
|
||||||
|
@ -532,8 +532,7 @@ QtObject:
|
||||||
error "error blocking contact ", msg = response.error.message
|
error "error blocking contact ", msg = response.error.message
|
||||||
return
|
return
|
||||||
|
|
||||||
contact.blocked = true
|
self.parseContactsResponse(response)
|
||||||
self.saveContact(contact)
|
|
||||||
self.events.emit(SIGNAL_CONTACT_BLOCKED, ContactArgs(contactId: contact.id))
|
self.events.emit(SIGNAL_CONTACT_BLOCKED, ContactArgs(contactId: contact.id))
|
||||||
|
|
||||||
proc removeContact*(self: Service, publicKey: string) =
|
proc removeContact*(self: Service, publicKey: string) =
|
||||||
|
|
|
@ -699,7 +699,7 @@ QtObject {
|
||||||
|
|
||||||
readonly property bool isUserAllowedToSendMessage: {
|
readonly property bool isUserAllowedToSendMessage: {
|
||||||
if (_d.activeChatType === Constants.chatType.oneToOne && _d.oneToOneChatContact) {
|
if (_d.activeChatType === Constants.chatType.oneToOne && _d.oneToOneChatContact) {
|
||||||
return _d.oneToOneChatContact.contactRequestState == Constants.ContactRequestState.Mutual
|
return _d.oneToOneChatContact.contactRequestState === Constants.ContactRequestState.Mutual
|
||||||
}
|
}
|
||||||
else if(_d.activeChatType === Constants.chatType.privateGroupChat) {
|
else if(_d.activeChatType === Constants.chatType.privateGroupChat) {
|
||||||
return _d.amIMember
|
return _d.amIMember
|
||||||
|
|
|
@ -77,6 +77,8 @@ ColumnLayout {
|
||||||
QtObject {
|
QtObject {
|
||||||
id: d
|
id: d
|
||||||
|
|
||||||
|
readonly property string blockedText: qsTr("This user has been blocked.")
|
||||||
|
|
||||||
function showReplyArea(messageId) {
|
function showReplyArea(messageId) {
|
||||||
let obj = messageStore.getMessageByIdAsJson(messageId)
|
let obj = messageStore.getMessageByIdAsJson(messageId)
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
|
@ -109,6 +111,7 @@ ColumnLayout {
|
||||||
stickersLoaded: root.stickersLoaded
|
stickersLoaded: root.stickersLoaded
|
||||||
chatId: root.chatId
|
chatId: root.chatId
|
||||||
isOneToOne: root.chatType === Constants.chatType.oneToOne
|
isOneToOne: root.chatType === Constants.chatType.oneToOne
|
||||||
|
isContactBlocked: root.isBlocked
|
||||||
isChatBlocked: root.isBlocked || !root.isUserAllowedToSendMessage
|
isChatBlocked: root.isBlocked || !root.isUserAllowedToSendMessage
|
||||||
channelEmoji: !chatContentModule ? "" : (chatContentModule.chatDetails.emoji || "")
|
channelEmoji: !chatContentModule ? "" : (chatContentModule.chatDetails.emoji || "")
|
||||||
isActiveChannel: root.isActiveChannel
|
isActiveChannel: root.isActiveChannel
|
||||||
|
@ -158,14 +161,17 @@ ColumnLayout {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: Style.current.smallPadding
|
anchors.margins: Style.current.smallPadding
|
||||||
|
|
||||||
enabled: root.rootStore.sectionDetails.joined && !root.rootStore.sectionDetails.amIBanned &&
|
// We enable the component if the contact is blocked, because if we disable it, the `Unban` button
|
||||||
root.isUserAllowedToSendMessage
|
// becomes disabled. All the local components inside already disable themselves when blocked
|
||||||
|
enabled: root.isBlocked ||
|
||||||
|
(root.rootStore.sectionDetails.joined && !root.rootStore.sectionDetails.amIBanned &&
|
||||||
|
root.isUserAllowedToSendMessage)
|
||||||
|
|
||||||
store: root.rootStore
|
store: root.rootStore
|
||||||
usersStore: root.usersStore
|
usersStore: root.usersStore
|
||||||
|
|
||||||
textInput.text: inputAreaLoader.preservedText
|
textInput.text: inputAreaLoader.preservedText
|
||||||
textInput.placeholderText: root.chatInputPlaceholder
|
textInput.placeholderText: root.isBlocked ? d.blockedText : root.chatInputPlaceholder
|
||||||
emojiPopup: root.emojiPopup
|
emojiPopup: root.emojiPopup
|
||||||
stickersPopup: root.stickersPopup
|
stickersPopup: root.stickersPopup
|
||||||
isContactBlocked: root.isBlocked
|
isContactBlocked: root.isBlocked
|
||||||
|
@ -176,7 +182,7 @@ ColumnLayout {
|
||||||
|
|
||||||
Binding on chatInputPlaceholder {
|
Binding on chatInputPlaceholder {
|
||||||
when: root.isBlocked
|
when: root.isBlocked
|
||||||
value: qsTr("This user has been blocked.")
|
value: d.blockedText
|
||||||
}
|
}
|
||||||
|
|
||||||
Binding on chatInputPlaceholder {
|
Binding on chatInputPlaceholder {
|
||||||
|
|
|
@ -36,6 +36,7 @@ Item {
|
||||||
property string chatId: ""
|
property string chatId: ""
|
||||||
property bool stickersLoaded: false
|
property bool stickersLoaded: false
|
||||||
property alias chatLogView: chatLogView
|
property alias chatLogView: chatLogView
|
||||||
|
property bool isContactBlocked: false
|
||||||
property bool isChatBlocked: false
|
property bool isChatBlocked: false
|
||||||
property bool isOneToOne: false
|
property bool isOneToOne: false
|
||||||
property bool isActiveChannel: false
|
property bool isActiveChannel: false
|
||||||
|
@ -329,7 +330,7 @@ Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
header: {
|
header: {
|
||||||
if (root.isOneToOne && root.rootStore.oneToOneChatContact) {
|
if (!root.isContactBlocked && root.isOneToOne && root.rootStore.oneToOneChatContact) {
|
||||||
switch (root.rootStore.oneToOneChatContact.contactRequestState) {
|
switch (root.rootStore.oneToOneChatContact.contactRequestState) {
|
||||||
case Constants.ContactRequestState.None: // no break
|
case Constants.ContactRequestState.None: // no break
|
||||||
case Constants.ContactRequestState.Dismissed:
|
case Constants.ContactRequestState.Dismissed:
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit a7df4ed388e4d78653326ed7a35e72221e23a5d9
|
Subproject commit 3f00869e1faed9fee17f6dfe500280c93d390284
|
Loading…
Reference in New Issue