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() self.handleSignals()
let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0") let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
let messagesFromContactsOnly = status_settings.getSetting[bool](Setting.MessagesFromContactsOnly, false, true)
self.view.pubKey = pubKey self.view.pubKey = pubKey
self.status.chat.init(pubKey) self.status.chat.init(pubKey, messagesFromContactsOnly)
self.status.stickers.init() self.status.stickers.init()
self.view.reactions.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 pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
let network = status_settings.getSetting[string](Setting.Networks_CurrentNetwork, constants.DEFAULT_NETWORK_NAME) let network = status_settings.getSetting[string](Setting.Networks_CurrentNetwork, constants.DEFAULT_NETWORK_NAME)
let appearance = status_settings.getSetting[int](Setting.Appearance) let appearance = status_settings.getSetting[int](Setting.Appearance)
let messagesFromContactsOnly = status_settings.getSetting[bool](Setting.MessagesFromContactsOnly)
profile.appearance = appearance profile.appearance = appearance
profile.id = pubKey profile.id = pubKey
profile.address = account.keyUid profile.address = account.keyUid
profile.messagesFromContactsOnly = messagesFromContactsOnly
let identityImage = self.status.profile.getIdentityImage(profile.address) let identityImage = self.status.profile.getIdentityImage(profile.address)

View File

@ -134,6 +134,13 @@ QtObject:
self.profile.setAppearance(theme) self.profile.setAppearance(theme)
self.status.saveSetting(Setting.Appearance, $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.} = proc getDappList(self: ProfileView): QVariant {.slot.} =
return newQVariant(self.dappList) return newQVariant(self.dappList)

View File

@ -13,6 +13,7 @@ QtObject:
pubKey*: string pubKey*: string
appearance*: int appearance*: int
ensVerified*: bool ensVerified*: bool
messagesFromContactsOnly*: bool
proc setup(self: ProfileInfoView) = proc setup(self: ProfileInfoView) =
self.QObject.setup self.QObject.setup
@ -29,6 +30,7 @@ QtObject:
result.appearance = 0 result.appearance = 0
result.identityImage = IdentityImage() result.identityImage = IdentityImage()
result.ensVerified = false result.ensVerified = false
result.messagesFromContactsOnly = false
result.setup result.setup
proc profileChanged*(self: ProfileInfoView) {.signal.} proc profileChanged*(self: ProfileInfoView) {.signal.}
@ -43,6 +45,7 @@ QtObject:
self.address = profile.address self.address = profile.address
self.ensVerified = profile.ensVerified self.ensVerified = profile.ensVerified
self.identityImage = profile.identityImage self.identityImage = profile.identityImage
self.messagesFromContactsOnly = profile.messagesFromContactsOnly
self.profileChanged() self.profileChanged()
proc setIdentityImage*(self: ProfileInfoView, identityImage: IdentityImage) = proc setIdentityImage*(self: ProfileInfoView, identityImage: IdentityImage) =
@ -69,6 +72,18 @@ QtObject:
write = setAppearance write = setAppearance
notify = profileChanged 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 proc identicon*(self: ProfileInfoView): string {.slot.} = result = self.identicon
QtProperty[string] identicon: QtProperty[string] identicon:
read = identicon read = identicon

View File

@ -51,6 +51,7 @@ type
ChatModel* = ref object ChatModel* = ref object
publicKey*: string publicKey*: string
messagesFromContactsOnly*: bool
events*: EventEmitter events*: EventEmitter
communitiesToFetch*: seq[string] communitiesToFetch*: seq[string]
mailserverReady*: bool mailserverReady*: bool
@ -69,6 +70,7 @@ include chat/utils
proc newChatModel*(events: EventEmitter): ChatModel = proc newChatModel*(events: EventEmitter): ChatModel =
result = ChatModel() result = ChatModel()
result.messagesFromContactsOnly = false
result.events = events result.events = events
result.mailserverReady = false result.mailserverReady = false
result.communitiesToFetch = @[] 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]) = 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 contacts = getAddedContacts()
# Automatically decline chat group invitations if admin is not a contact var chatList = chats
var chatList = self.cleanSpamChatGroups(chats, contacts) if (self.messagesFromContactsOnly):
# Automatically decline chat group invitations if admin is not a contact
chatList = self.cleanSpamChatGroups(chats, contacts)
for chat in chatList: for chat in chatList:
if chat.isActive: if chat.isActive:
@ -172,12 +176,15 @@ proc requestMissingCommunityInfos*(self: ChatModel) =
for communityId in self.communitiesToFetch: for communityId in self.communitiesToFetch:
status_chat.requestCommunityInfo(communityId) status_chat.requestCommunityInfo(communityId)
proc init*(self: ChatModel, pubKey: string) = proc init*(self: ChatModel, pubKey: string, messagesFromContactsOnly: bool) =
self.publicKey = pubKey self.publicKey = pubKey
self.messagesFromContactsOnly = messagesFromContactsOnly
var contacts = getAddedContacts() 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) let profileUpdatesChatIds = chatList.filter(c => c.chatType == ChatType.Profile).map(c => c.id)

View File

@ -16,7 +16,7 @@ var
dirty.store(true) dirty.store(true)
settings = %* {} settings = %* {}
proc saveSetting*(key: Setting, value: string | JsonNode): StatusGoError = proc saveSetting*(key: Setting, value: string | JsonNode | bool): StatusGoError =
try: try:
let response = callPrivateRPC("settings_saveSetting", %* [key, value]) let response = callPrivateRPC("settings_saveSetting", %* [key, value])
let responseResult = $(response.parseJSON(){"result"}) let responseResult = $(response.parseJSON(){"result"})

View File

@ -171,6 +171,7 @@ type
Currency = "currency" Currency = "currency"
EtherscanLink = "etherscan-link" EtherscanLink = "etherscan-link"
InstallationId = "installation-id" InstallationId = "installation-id"
MessagesFromContactsOnly = "messages-from-contacts-only"
Mnemonic = "mnemonic" Mnemonic = "mnemonic"
Networks_Networks = "networks/networks" Networks_Networks = "networks/networks"
Networks_CurrentNetwork = "networks/current-network" Networks_CurrentNetwork = "networks/current-network"

View File

@ -4,6 +4,7 @@ import ../libstatus/types
type Profile* = ref object type Profile* = ref object
id*, alias*, username*, identicon*, address*, ensName*, localNickname*: string id*, alias*, username*, identicon*, address*, ensName*, localNickname*: string
ensVerified*: bool ensVerified*: bool
messagesFromContactsOnly*: bool
identityImage*: IdentityImage identityImage*: IdentityImage
appearance*: int appearance*: int
systemTags*: seq[string] systemTags*: seq[string]

View File

@ -62,5 +62,5 @@ proc reset*(self: Status) =
proc getNodeVersion*(self: Status): string = proc getNodeVersion*(self: Status): string =
libstatus_settings.getWeb3ClientVersion() 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) discard libstatus_settings.saveSetting(setting, value)

View File

@ -109,6 +109,15 @@ Item {
currentValue: appSettings.openLinksInStatus ? "Status" : qsTrId("my-default-browser") currentValue: appSettings.openLinksInStatus ? "Status" : qsTrId("my-default-browser")
onClicked: openPopup(openLinksWithModal) onClicked: openPopup(openLinksWithModal)
} }
StatusSettingsLineButton {
text: qsTr("Allow new contact requests")
isSwitch: true
switchChecked: !profileModel.profile.messagesFromContactsOnly
onClicked: function (checked) {
profileModel.setMessagesFromContactsOnly(!checked)
}
}
} }
} }