fix: ens names should not display `@`

Fixes #8122
This commit is contained in:
Lukáš Tinkl 2022-11-08 12:37:25 +01:00 committed by Lukáš Tinkl
parent 105e1c156b
commit 2b6164fc8d
19 changed files with 27 additions and 369 deletions

View File

@ -84,13 +84,6 @@ QtObject:
read = getEnsName
notify = nameChanged
proc getPrettyEnsName*(self: UserProfile): string {.slot.} =
utils.prettyEnsName(self.ensName)
QtProperty[string] prettyEnsName:
read = getPrettyEnsName
notify = nameChanged
# this is not a slot
proc setFirstEnsName*(self: UserProfile, name: string) =
if(self.firstEnsName == name):
@ -105,7 +98,7 @@ QtObject:
notify = nameChanged
proc getPrettyFirstEnsName*(self: UserProfile): string {.slot.} =
utils.prettyEnsName(self.firstEnsName)
self.firstEnsName
QtProperty[string] prettyFirstEnsName:
read = getPrettyFirstEnsName
notify = nameChanged
@ -125,7 +118,7 @@ QtObject:
notify = nameChanged
proc getPrettyPreferredName*(self: UserProfile): string {.slot.} =
utils.prettyEnsName(self.preferredName)
self.preferredName
QtProperty[string] prettyPreferredName:
read = getPrettyPreferredName
notify = nameChanged
@ -149,7 +142,7 @@ QtObject:
elif(self.firstEnsName.len > 0):
return self.getPrettyFirstEnsName()
elif(self.ensName.len > 0):
return self.getPrettyEnsName()
return self.ensName
elif(self.displayName.len > 0):
return self.getDisplayName()
return self.username

View File

@ -27,13 +27,6 @@ proc first*(jArray: JsonNode, fieldName, id: string): JsonNode =
if child{fieldName}.getStr.toLower == id.toLower:
return child
proc prettyEnsName*(ensName: string): string =
if ensName.endsWith(STATUS_DOMAIN):
return "@" & ensName.split(".")[0]
elif ensName.endsWith(ETH_DOMAIN):
return "@" & ensName
return ensName
const sep = when defined(windows): "\\" else: "/"
proc defaultDataDir(): string =

View File

@ -151,7 +151,7 @@ proc toContactsDto*(jsonObj: JsonNode): ContactsDto =
proc userExtractedName(contact: ContactsDto): string =
if(contact.name.len > 0 and contact.ensVerified):
result = prettyEnsName(contact.name)
result = contact.name
elif contact.displayName.len > 0:
result = contact.displayName
else:

View File

@ -9,10 +9,12 @@ Item {
property bool mainModuleReady: false
QtObject {
function getCompressedPk(publicKey) {
return "compressed"
function isCompressedPubKey(publicKey) {
return true
}
function getCompressedPk(publicKey) { return "zx3sh" + publicKey }
function getColorHashAsJson(publicKey) {
return JSON.stringify([{colorId: 0, segmentLength: 1},
{colorId: 19, segmentLength: 2}])

View File

@ -22,7 +22,12 @@ SplitView {
function getCompressedPk(publicKey) { return "zx3sh" + publicKey }
function getColorHashAsJson(publicKey) { return JSON.stringify("") } // TODO
function getColorHashAsJson(publicKey) {
return JSON.stringify([{colorId: 0, segmentLength: 1},
{colorId: 19, segmentLength: 2}])
}
function isCompressedPubKey(publicKey) { return true }
Component.onCompleted: {
Utils.globalUtilsInst = this

View File

@ -1,4 +1,5 @@
import QtQuick 2.0
import QtQuick 2.14
import StatusQ.Core.Theme 0.1
import StatusQ.Core 0.1

View File

@ -1,75 +0,0 @@
import QtQuick 2.13
import QtQuick.Controls 2.3
import StatusQ.Core 0.1
import StatusQ.Components 0.1
import StatusQ.Controls 0.1
import StatusQ.Core.Theme 0.1
import utils 1.0
StatusListView {
id: contactListPanel
property string searchString
property bool selectMode: true
property var onItemChecked
property var selectedPubKeys: []
spacing: 0
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
delegate: StatusListItem {
id: contactDelegate
property bool isChecked: selectedPubKeys.indexOf(model.pubKey) !== -1
visible: {
if (selectMode) {
return !searchString || model.displayName.toLowerCase().includes(searchString)
}
return checkbox.checked
}
title: !model.displayName.endsWith(".eth") && !!model.localNickname ?
model.localNickname : Utils.removeStatusEns(model.displayName)
asset.height: asset.isImage ? 40 : 20
asset.width: asset.isImage ? 40 : 20
asset.name: model.icon
asset.isImage: model.icon !== ""
asset.color: Utils.colorForColorId(model.colorId)
asset.charactersLen: 2
ringSettings.ringSpecModel: Utils.getColorHashAsJson(model.pubKey)
height: visible ? implicitHeight : 0
function contactToggled(pubKey) {
if (contactListPanel.selectMode) {
let pubkeys = contactListPanel.selectedPubKeys
let idx = pubkeys.indexOf(pubKey)
if (idx === -1) {
pubkeys.push(pubKey)
} else if (idx > -1) {
pubkeys.splice(idx, 1);
}
contactListPanel.selectedPubKeys = pubkeys
}
}
components: [
StatusCheckBox {
id: checkbox
visible: contactListPanel.selectMode
checked: selectedPubKeys.indexOf(model.pubKey) !== -1
onClicked: {
contactDelegate.contactToggled(model.pubKey)
}
}
]
onClicked: {
contactDelegate.contactToggled(model.pubKey)
}
}
}

View File

@ -79,10 +79,11 @@ Item {
section.property: "onlineStatus"
section.delegate: (root.width > 58) ? sectionDelegateComponent : null
delegate: StatusMemberListItem {
readonly property bool ensVerified: Utils.isEnsVerified(model.pubKey)
width: ListView.view.width
nickName: model.localNickname
userName: !!model.ensName ? "@" + Utils.removeStatusEns(model.ensName) : model.displayName !== "" ? model.displayName : model.alias
pubKey: !!model.ensName ? "" : Utils.getCompressedPk(model.pubKey)
userName: ensVerified ? model.ensName : model.displayName !== "" ? model.displayName : model.alias
pubKey: ensVerified ? "" : Utils.getCompressedPk(model.pubKey)
isContact: model.isContact
isVerified: model.isVerified
isUntrustworthy: model.isUntrustworthy
@ -92,7 +93,7 @@ Item {
asset.isLetterIdenticon: (asset.name === "")
asset.color: Utils.colorForColorId(model.colorId)
status: model.onlineStatus
ringSettings.ringSpecModel: !!model.ensName ? undefined : Utils.getColorHashAsJson(model.pubKey, true) // FIXME: use model.colorHash
ringSettings.ringSpecModel: ensVerified ? undefined : Utils.getColorHashAsJson(model.pubKey, true) // FIXME: use model.colorHash
onClicked: {
if (mouse.button === Qt.RightButton) {
// Set parent, X & Y positions for the messageContextMenu

View File

@ -1,100 +0,0 @@
import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13
import utils 1.0
import shared.controls 1.0
import shared 1.0
import shared.panels 1.0
import shared.popups 1.0
import shared.status 1.0
import "./"
// TODO: replace with StatusModal
ModalPopup {
id: popup
title: qsTr("New chat")
property var store
property var contactsStore
signal joinPrivateChat(string publicKey, string ensName)
signal profileClicked()
function doJoin(pubKey, username) {
popup.joinPrivateChat(pubKey, Utils.isChatKey(pubKey) ? "" : username);
popup.close();
}
onOpened: {
contactFieldAndList.chatKey.text = ""
contactFieldAndList.pubKey = ""
contactFieldAndList.ensUsername = ""
contactFieldAndList.chatKey.forceActiveFocus(Qt.MouseFocusReason)
contactFieldAndList.existingContacts.visible = contactsStore.myContactsModel.count > 0
contactFieldAndList.noContactsRect.visible = !contactFieldAndList.existingContacts.visible
}
ContactsListAndSearch {
id: contactFieldAndList
anchors.top: parent.top
anchors.bottom: parent.bottom
width: parent.width
addContactEnabled: false
contactsStore: popup.contactsStore
rootStore: popup.store
onUserClicked: function (pubKey, isAddedContact, username) {
popup.doJoin(pubKey, username);
}
}
Control {
width: 124
height: 36
anchors.bottom: parent.bottom
anchors.bottomMargin: 24
anchors.horizontalCenter: parent.horizontalCenter
background: Rectangle {
anchors.fill: parent
radius: 34
color: Style.current.blue
}
contentItem: Item {
anchors.fill: parent
RoundedImage {
id: dollarEmoji
width: 32
height: 32
anchors.left: parent.left
anchors.leftMargin: 2
anchors.verticalCenter: parent.verticalCenter
source: Global.getProfileImage(userProfile.pubKey)
}
StyledText {
anchors.left: dollarEmoji.right
anchors.leftMargin: 6
anchors.verticalCenter: parent.verticalCenter
text: qsTr("My Profile")
font.pixelSize: 15
color: Style.current.white
}
}
MouseArea {
anchors.fill: parent
cursorShape: "PointingHandCursor"
onClicked: {
popup.profileClicked();
Global.settingsSubsection = Constants.settingsSubsection.profile;
popup.close();
}
}
}
}
/*##^##
Designer {
D{i:0;height:300;width:300}
}
##^##*/

View File

@ -185,8 +185,4 @@ StatusSectionLayout {
root.rootStore.chatCommunitySectionModule.createOneToOneChat(communityId, chatId, ensName)
}
}
Component.onCompleted: {
rootStore.groupInfoPopupComponent = groupInfoPopupComponent;
}
}

View File

@ -270,23 +270,6 @@ Item {
}
}
Component {
id: privateChatPopupComponent
PrivateChatPopup {
store: root.store
contactsStore: root.contactsStore
onJoinPrivateChat: {
chatSectionModule.createOneToOneChat("", publicKey, ensName)
}
onClosed: {
destroy()
}
onProfileClicked: {
root.openProfileClicked();
}
}
}
Component {
id: communitiesPopupComponent
CommunitiesPopup {

View File

@ -55,7 +55,7 @@ StatusListItem {
subTitle: {
if (d.ensVerified) {
if (d.localNickname)
return '@' + Utils.removeStatusEns(d.name)
return d.name
return ""
}
return Utils.getElidedCompressedPk(root.publicKey)

View File

@ -73,7 +73,7 @@ SettingsContentBase {
isMessage: true
shouldRepeatHeader: true
messageTimestamp: Date.now()
senderDisplayName: "@vitalik"
senderDisplayName: "vitalik.eth"
senderIcon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAb0lEQVR4Ae3UQQqAIBRF0Wj9ba9Bq6l5JBQqfn/ngDMH3YS3AAB/tO3H+XRG3b9bR/+gVoREI2RapVXpfd5+X5oXERKNkHS+rk3tOpWkeREh0QiZVu91ql2zNC8iJBoh0yqtSqt1slpCghICANDPBc0ESPh0bHkHAAAAAElFTkSuQmCC"
messageText: qsTr("Blockchains will drop search costs, causing a kind of decomposition that allows you to have markets of entities that are horizontally segregated and vertically segregated.")
messageContentType: Constants.messageContentType.messageType

View File

@ -1,133 +0,0 @@
import QtQuick 2.13
import utils 1.0
QtObject {
id: root
property string hoveredMessage
property string activeMessage
property string fromAuthor: "0x0011223344556677889910"
property string userName: "Jotaro Kujo"
property string alias: ""
property string localName: ""
property string message: "That's right. We're friends... Of justice, that is."
property string plainText: "That's right. We're friends... Of justice, that is."
property bool isCurrentUser: false
property string timestamp: "1234567"
property string sticker: "Qme8vJtyrEHxABcSVGPF95PtozDgUyfr1xGjePmFdZgk9v"
property int contentType: 1 // constants don't work in default props
property string chatId: "chatId"
property string outgoingStatus: ""
property string responseTo: ""
property string messageId: ""
property string emojiReactions: ""
property int prevMessageIndex: -1
property int nextMessageIndex: -1
property bool timeout: false
property bool hasMention: false
property string linkUrls: ""
property bool placeholderMessage: false
property bool activityCenterMessage: false
property bool pinnedMessage: false
property bool read: true
property string pinnedBy
property bool forceHoverHandler: false // Used to force the HoverHandler to be active (useful for messages in popups)
property string communityId: ""
property int stickerPackId: -1
property int gapFrom: 0
property int gapTo: 0
property bool isEdit: false
property string replaces: ""
property bool isEdited: false
property bool showEdit: true
property var messageContextMenu
property bool isMessageActive: typeof root.activeMessage !== "undefined" && root.activeMessage === root.messageId
property string displayUserName: {
if (isCurrentUser) {
return qsTr("You")
}
if (localName !== "") {
return localName
}
if (userName !== "") {
return Utils.removeStatusEns(userName)
}
return Utils.removeStatusEns(alias)
}
property string authorCurrentMsg: "authorCurrentMsg"
property string authorPrevMsg: "authorPrevMsg"
property string prevMsgTimestamp: chatsModel.messageView.messageList.getMessageData(prevMessageIndex, "timestamp")
property string nextMsgTimestamp: chatsModel.messageView.messageList.getMessageData(nextMessageIndex, "timestamp")
property bool shouldRepeatHeader: ((parseInt(timestamp, 10) - parseInt(prevMsgTimestamp, 10)) / 60 / 1000) > Constants.repeatHeaderInterval
property bool isEmoji: contentType === Constants.emojiType
property bool isImage: contentType === Constants.imageType
property bool isAudio: contentType === Constants.audioType
property bool isStatusMessage: contentType === Constants.systemMessagePrivateGroupType
property bool isSticker: contentType === Constants.stickerType
property bool isText: contentType === Constants.messageType || contentType === Constants.editType
property bool isMessage: isEmoji || isImage || isSticker || isText || isAudio
|| contentType === Constants.communityInviteType || contentType === Constants.transactionType
property bool isExpired: (outgoingStatus === "sending" && (Math.floor(timestamp) + 180000) < Date.now())
property int statusAgeEpoch: 0
// property int replyMessageIndex: chatsModel.messageView.messageList.getMessageIndex(responseTo);
// property string repliedMessageAuthor: replyMessageIndex > -1 ? chatsModel.messageView.messageList.getMessageData(replyMessageIndex, "userName") : "";
// property string repliedMessageAuthorPubkey: replyMessageIndex > -1 ? chatsModel.messageView.messageList.getMessageData(replyMessageIndex, "publicKey") : "";
// property bool repliedMessageAuthorIsCurrentUser: replyMessageIndex > -1 ? repliedMessageAuthorPubkey === userProfile.pubKey : "";
// property bool repliedMessageIsEdited: replyMessageIndex > -1 ? chatsModel.messageView.messageList.getMessageData(replyMessageIndex, "isEdited") === "true" : false;
// property string repliedMessageContent: replyMessageIndex > -1 ? chatsModel.messageView.messageList.getMessageData(replyMessageIndex, "message") : "";
// property int repliedMessageType: replyMessageIndex > -1 ? parseInt(chatsModel.messageView.messageList.getMessageData(replyMessageIndex, "contentType")) : 0;
// property string repliedMessageImage: replyMessageIndex > -1 ? chatsModel.messageView.messageList.getMessageData(replyMessageIndex, "image") : "";
// property string repliedMessageUserIdenticon: replyMessageIndex > -1 ? chatsModel.messageView.messageList.getMessageData(replyMessageIndex, "identicon") : "";
// property string repliedMessageUserImage: replyMessageIndex > -1 ? appMain.getProfileImage(repliedMessageAuthorPubkey, repliedMessageAuthorIsCurrentUser , false) || "" : "";
property var imageClick: function () {}
property var scrollToBottom: function () {}
property string userPubKey: {
if (contentType === Constants.chatIdentifier) {
return chatId
}
return fromAuthor
}
property bool useLargeImage: contentType === Constants.chatIdentifier
property string profileImageSource: !placeholderMessage && appMain.getProfileImage(userPubKey, isCurrentUser, useLargeImage) || ""
property var emojiReactionsModel: {
if (!emojiReactions) {
return []
}
try {
// group by id
var allReactions = Object.values(JSON.parse(emojiReactions))
var byEmoji = {}
allReactions.forEach(function (reaction) {
if (!byEmoji[reaction.emojiId]) {
byEmoji[reaction.emojiId] = {
emojiId: reaction.emojiId,
fromAccounts: [],
count: 0,
currentUserReacted: false
}
}
byEmoji[reaction.emojiId].count++;
byEmoji[reaction.emojiId].fromAccounts.push(chatsModel.userNameOrAlias(reaction.from));
if (!byEmoji[reaction.emojiId].currentUserReacted && reaction.from === userProfile.pubKey) {
byEmoji[reaction.emojiId].currentUserReacted = true
}
})
return Object.values(byEmoji)
} catch (e) {
console.error('Error parsing emoji reactions', e)
return []
}
}
}

View File

@ -61,7 +61,7 @@ Badge {
StyledText {
Layout.alignment: Qt.AlignVCenter
text: chatType !== Constants.chatType.publicChat ?
StatusQUtils.Emoji.parse(Utils.removeStatusEns(StatusQUtils.Utils.filterXSS(name))) :
StatusQUtils.Emoji.parse(StatusQUtils.Utils.filterXSS(name)) :
"#" + StatusQUtils.Utils.filterXSS(name)
color: Theme.palette.baseColor1

View File

@ -129,7 +129,7 @@ Item {
root.validationError = qsTr("Can't chat with yourself");
} else {
chatKey.hasValidSearchResult = true
searchResults.username = Utils.addStatusEns(chatKey.text.trim())
searchResults.username = chatKey.text.trim()
let userAlias = globalUtils.generateAlias(resolvedPubKey)
userAlias = userAlias.length > 20 ? userAlias.substring(0, 19) + "..." : userAlias
searchResults.userAlias = userAlias + " • " + Utils.compactAddress(resolvedPubKey, 4)

View File

@ -47,7 +47,7 @@ Pane {
readonly property bool isCurrentUser: root.profileStore.pubkey === root.publicKey
readonly property string userDisplayName: contactDetails.displayName
readonly property string userNickName: contactDetails.localNickname
readonly property string prettyEnsName: '@' + Utils.removeStatusEns(contactDetails.name)
readonly property string prettyEnsName: contactDetails.name
readonly property bool isContact: contactDetails.isContact
readonly property bool isBlocked: contactDetails.isBlocked

View File

@ -165,7 +165,7 @@ Item {
}
PropertyChanges {
target: txtToPrimary
text: Utils.removeStatusEns(root.toAccount.name)
text: root.toAccount.name
}
},
State {

View File

@ -109,14 +109,6 @@ QtObject {
return emoji_regex.test(inputText);
}
function removeStatusEns(userName){
return userName.endsWith(".stateofus.eth") ? userName.substr(0, userName.length - 14) : userName
}
function addStatusEns(userName){
return userName.endsWith(".eth") ? userName : userName + ".stateofus.eth"
}
function isValidAddress(inputValue) {
return inputValue !== "0x" && /^0x[a-fA-F0-9]{40}$/.test(inputValue)
}