feat: add setting to not receive contact requests
This commit is contained in:
parent
1984ee89e0
commit
ecf8b241f0
|
@ -35,9 +35,10 @@ proc init*(self: ChatController) =
|
|||
self.handleSignals()
|
||||
|
||||
let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
|
||||
let messagesFromContactsOnly = status_settings.getSetting[bool](Setting.MessagesFromContactsOnly, false, true)
|
||||
|
||||
self.view.pubKey = pubKey
|
||||
self.status.chat.init(pubKey)
|
||||
self.status.chat.init(pubKey, messagesFromContactsOnly)
|
||||
self.status.stickers.init()
|
||||
self.view.reactions.init()
|
||||
|
||||
|
|
|
@ -40,9 +40,11 @@ proc init*(self: ProfileController, account: Account) =
|
|||
let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
|
||||
let network = status_settings.getSetting[string](Setting.Networks_CurrentNetwork, constants.DEFAULT_NETWORK_NAME)
|
||||
let appearance = status_settings.getSetting[int](Setting.Appearance)
|
||||
let messagesFromContactsOnly = status_settings.getSetting[bool](Setting.MessagesFromContactsOnly)
|
||||
profile.appearance = appearance
|
||||
profile.id = pubKey
|
||||
profile.address = account.keyUid
|
||||
profile.messagesFromContactsOnly = messagesFromContactsOnly
|
||||
|
||||
let identityImage = self.status.profile.getIdentityImage(profile.address)
|
||||
|
||||
|
|
|
@ -134,6 +134,13 @@ QtObject:
|
|||
self.profile.setAppearance(theme)
|
||||
self.status.saveSetting(Setting.Appearance, $theme)
|
||||
|
||||
proc setMessagesFromContactsOnly*(self: ProfileView, messagesFromContactsOnly: bool) {.slot.} =
|
||||
if (messagesFromContactsOnly == self.profile.messagesFromContactsOnly):
|
||||
return
|
||||
self.profile.setMessagesFromContactsOnly(messagesFromContactsOnly)
|
||||
self.status.saveSetting(Setting.MessagesFromContactsOnly, messagesFromContactsOnly)
|
||||
# TODO cleanup chats after activating this
|
||||
|
||||
proc getDappList(self: ProfileView): QVariant {.slot.} =
|
||||
return newQVariant(self.dappList)
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ QtObject:
|
|||
pubKey*: string
|
||||
appearance*: int
|
||||
ensVerified*: bool
|
||||
messagesFromContactsOnly*: bool
|
||||
|
||||
proc setup(self: ProfileInfoView) =
|
||||
self.QObject.setup
|
||||
|
@ -29,6 +30,7 @@ QtObject:
|
|||
result.appearance = 0
|
||||
result.identityImage = IdentityImage()
|
||||
result.ensVerified = false
|
||||
result.messagesFromContactsOnly = false
|
||||
result.setup
|
||||
|
||||
proc profileChanged*(self: ProfileInfoView) {.signal.}
|
||||
|
@ -43,6 +45,7 @@ QtObject:
|
|||
self.address = profile.address
|
||||
self.ensVerified = profile.ensVerified
|
||||
self.identityImage = profile.identityImage
|
||||
self.messagesFromContactsOnly = profile.messagesFromContactsOnly
|
||||
self.profileChanged()
|
||||
|
||||
proc setIdentityImage*(self: ProfileInfoView, identityImage: IdentityImage) =
|
||||
|
@ -69,6 +72,18 @@ QtObject:
|
|||
write = setAppearance
|
||||
notify = profileChanged
|
||||
|
||||
proc messagesFromContactsOnly*(self: ProfileInfoView): bool {.slot.} = result = self.messagesFromContactsOnly
|
||||
proc setMessagesFromContactsOnly*(self: ProfileInfoView, messagesFromContactsOnly: bool) {.slot.} =
|
||||
if self.messagesFromContactsOnly == messagesFromContactsOnly:
|
||||
return
|
||||
self.messagesFromContactsOnly = messagesFromContactsOnly
|
||||
self.profileChanged()
|
||||
QtProperty[bool] messagesFromContactsOnly:
|
||||
read = messagesFromContactsOnly
|
||||
write = setMessagesFromContactsOnly
|
||||
notify = profileChanged
|
||||
|
||||
|
||||
proc identicon*(self: ProfileInfoView): string {.slot.} = result = self.identicon
|
||||
QtProperty[string] identicon:
|
||||
read = identicon
|
||||
|
|
|
@ -51,6 +51,7 @@ type
|
|||
|
||||
ChatModel* = ref object
|
||||
publicKey*: string
|
||||
messagesFromContactsOnly*: bool
|
||||
events*: EventEmitter
|
||||
communitiesToFetch*: seq[string]
|
||||
mailserverReady*: bool
|
||||
|
@ -69,6 +70,7 @@ include chat/utils
|
|||
|
||||
proc newChatModel*(events: EventEmitter): ChatModel =
|
||||
result = ChatModel()
|
||||
result.messagesFromContactsOnly = false
|
||||
result.events = events
|
||||
result.mailserverReady = false
|
||||
result.communitiesToFetch = @[]
|
||||
|
@ -105,8 +107,10 @@ proc cleanSpamChatGroups(self: ChatModel, chats: seq[Chat], contacts: seq[Profil
|
|||
proc update*(self: ChatModel, chats: seq[Chat], messages: seq[Message], emojiReactions: seq[Reaction], communities: seq[Community], communityMembershipRequests: seq[CommunityMembershipRequest], pinnedMessages: seq[Message]) =
|
||||
var contacts = getAddedContacts()
|
||||
|
||||
var chatList = chats
|
||||
if (self.messagesFromContactsOnly):
|
||||
# Automatically decline chat group invitations if admin is not a contact
|
||||
var chatList = self.cleanSpamChatGroups(chats, contacts)
|
||||
chatList = self.cleanSpamChatGroups(chats, contacts)
|
||||
|
||||
for chat in chatList:
|
||||
if chat.isActive:
|
||||
|
@ -172,12 +176,15 @@ proc requestMissingCommunityInfos*(self: ChatModel) =
|
|||
for communityId in self.communitiesToFetch:
|
||||
status_chat.requestCommunityInfo(communityId)
|
||||
|
||||
proc init*(self: ChatModel, pubKey: string) =
|
||||
proc init*(self: ChatModel, pubKey: string, messagesFromContactsOnly: bool) =
|
||||
self.publicKey = pubKey
|
||||
self.messagesFromContactsOnly = messagesFromContactsOnly
|
||||
|
||||
var contacts = getAddedContacts()
|
||||
var chatList = status_chat.loadChats()
|
||||
|
||||
var chatList = self.cleanSpamChatGroups(status_chat.loadChats(), contacts)
|
||||
if (messagesFromContactsOnly):
|
||||
chatList = self.cleanSpamChatGroups(chatList, contacts)
|
||||
|
||||
let profileUpdatesChatIds = chatList.filter(c => c.chatType == ChatType.Profile).map(c => c.id)
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ var
|
|||
dirty.store(true)
|
||||
settings = %* {}
|
||||
|
||||
proc saveSetting*(key: Setting, value: string | JsonNode): StatusGoError =
|
||||
proc saveSetting*(key: Setting, value: string | JsonNode | bool): StatusGoError =
|
||||
try:
|
||||
let response = callPrivateRPC("settings_saveSetting", %* [key, value])
|
||||
let responseResult = $(response.parseJSON(){"result"})
|
||||
|
|
|
@ -171,6 +171,7 @@ type
|
|||
Currency = "currency"
|
||||
EtherscanLink = "etherscan-link"
|
||||
InstallationId = "installation-id"
|
||||
MessagesFromContactsOnly = "messages-from-contacts-only"
|
||||
Mnemonic = "mnemonic"
|
||||
Networks_Networks = "networks/networks"
|
||||
Networks_CurrentNetwork = "networks/current-network"
|
||||
|
|
|
@ -4,6 +4,7 @@ import ../libstatus/types
|
|||
type Profile* = ref object
|
||||
id*, alias*, username*, identicon*, address*, ensName*, localNickname*: string
|
||||
ensVerified*: bool
|
||||
messagesFromContactsOnly*: bool
|
||||
identityImage*: IdentityImage
|
||||
appearance*: int
|
||||
systemTags*: seq[string]
|
||||
|
|
|
@ -62,5 +62,5 @@ proc reset*(self: Status) =
|
|||
proc getNodeVersion*(self: Status): string =
|
||||
libstatus_settings.getWeb3ClientVersion()
|
||||
|
||||
proc saveSetting*(self: Status, setting: Setting, value: string) =
|
||||
proc saveSetting*(self: Status, setting: Setting, value: string | bool) =
|
||||
discard libstatus_settings.saveSetting(setting, value)
|
||||
|
|
|
@ -109,6 +109,15 @@ Item {
|
|||
currentValue: appSettings.openLinksInStatus ? "Status" : qsTrId("my-default-browser")
|
||||
onClicked: openPopup(openLinksWithModal)
|
||||
}
|
||||
|
||||
StatusSettingsLineButton {
|
||||
text: qsTr("Allow new contact requests")
|
||||
isSwitch: true
|
||||
switchChecked: !profileModel.profile.messagesFromContactsOnly
|
||||
onClicked: function (checked) {
|
||||
profileModel.setMessagesFromContactsOnly(!checked)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue