fix: fix sending three word names mentions not working

This commit is contained in:
Jonathan Rainville 2021-03-23 11:57:19 -04:00 committed by Iuri Matias
parent 47ae3a4c16
commit 5d67a3f5f9
4 changed files with 36 additions and 20 deletions

View File

@ -176,12 +176,23 @@ QtObject:
proc plainText(self: ChatsView, input: string): string {.slot.} =
result = plain_text(input)
proc sendMessage*(self: ChatsView, message: string, replyTo: string, contentType: int = ContentType.Message.int, isStatusUpdate: bool = false) {.slot.} =
proc sendMessage*(self: ChatsView, message: string, replyTo: string, contentType: int = ContentType.Message.int, isStatusUpdate: bool = false, contactsString: string = "") {.slot.} =
let aliasPattern = re(r"(@[A-z][a-z]+ [A-z][a-z]* [A-z][a-z]*)", flags = {reStudy, reIgnoreCase})
let ensPattern = re(r"(@\w+(?=(\.stateofus)?\.eth))", flags = {reStudy, reIgnoreCase})
let namePattern = re(r"(@\w+)", flags = {reStudy, reIgnoreCase})
let contacts = self.status.contacts.getContacts()
var contacts: seq[Profile]
if (contactsString == ""):
contacts = self.status.contacts.getContacts()
else:
let contactsJSON = parseJson(contactsString)
contacts = @[]
for contact in contactsJSON:
contacts.add(Profile(
address: contact["address"].str,
alias: contact["alias"].str,
ensName: contact["ensName"].str
))
let aliasMentions = findAll(message, aliasPattern)
let ensMentions = findAll(message, ensPattern)

View File

@ -42,21 +42,23 @@ StackLayout {
property var idMap: ({})
property var suggestionsObj: ([])
function addSuggestionFromMessageList(i){
const contactAddr = chatsModel.messageList.getMessageData(i, "publicKey");
if(idMap[contactAddr]) return;
chatInput.suggestionsList.append({
suggestionsObj.push({
alias: chatsModel.messageList.getMessageData(i, "alias"),
ensName: chatsModel.messageList.getMessageData(i, "ensName"),
address: contactAddr,
identicon: chatsModel.messageList.getMessageData(i, "identicon"),
localNickname: chatsModel.messageList.getMessageData(i, "localName")
});
})
chatInput.suggestionsList.append(suggestionsObj[suggestionsObj.length - 1]);
idMap[contactAddr] = true;
}
function populateSuggestions(){
function populateSuggestions() {
chatInput.suggestionsList.clear()
const len = chatsModel.suggestionList.rowCount()
@ -66,13 +68,16 @@ StackLayout {
const contactAddr = chatsModel.suggestionList.rowData(i, "address");
if(idMap[contactAddr]) continue;
const contactIndex = profileModel.contacts.list.getContactIndexByPubkey(chatsModel.suggestionList.rowData(i, "address"));
chatInput.suggestionsList.append({
suggestionsObj.push({
alias: chatsModel.suggestionList.rowData(i, "alias"),
ensName: chatsModel.suggestionList.rowData(i, "ensName"),
address: contactAddr,
identicon: profileModel.contacts.list.rowData(contactIndex, "thumbnailImage"),
localNickname: chatsModel.suggestionList.rowData(i, "localNickname")
});
})
chatInput.suggestionsList.append(suggestionsObj[suggestionsObj.length - 1]);
idMap[contactAddr] = true;
}
const len2 = chatsModel.messageList.rowCount();
@ -322,7 +327,7 @@ StackLayout {
let msg = chatsModel.plainText(Emoji.deparse(chatInput.textInput.text))
if (msg.length > 0){
msg = chatInput.interpretMessage(msg)
chatsModel.sendMessage(msg, chatInput.isReply ? SelectedMessage.messageId : "", Utils.isOnlyEmoji(msg) ? Constants.emojiType : Constants.messageType, false);
chatsModel.sendMessage(msg, chatInput.isReply ? SelectedMessage.messageId : "", Utils.isOnlyEmoji(msg) ? Constants.emojiType : Constants.messageType, false, JSON.stringify(suggestionsObj));
if(event) event.accepted = true
sendMessageSound.stop();
Qt.callLater(sendMessageSound.play);

View File

@ -82,7 +82,7 @@ ScrollView {
var msg = chatsModel.plainText(Emoji.deparse(statusUpdateInput.textInput.text))
if (msg.length > 0){
msg = statusUpdateInput.interpretMessage(msg)
chatsModel.sendMessage(msg, "", Utils.isOnlyEmoji(msg) ? Constants.emojiType : Constants.messageType, true);
chatsModel.sendMessage(msg, "", Utils.isOnlyEmoji(msg) ? Constants.emojiType : Constants.messageType, true, "");
statusUpdateInput.textInput.text = "";
if(event) event.accepted = true
statusUpdateInput.messageSound.stop()