feat: add setting to not receive contact requests

This commit is contained in:
Jonathan Rainville 2021-05-17 16:05:29 -04:00
parent 1984ee89e0
commit ecf8b241f0
10 changed files with 50 additions and 7 deletions

View File

@ -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()

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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"})

View File

@ -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"

View File

@ -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]

View File

@ -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)

View File

@ -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)
}
}
}
}