allow user to set custom display names for peers and conversations

This commit is contained in:
liamcottle 2024-09-19 23:46:08 +12:00
parent 9ebf48b02b
commit c73213d435
4 changed files with 140 additions and 5 deletions

View file

@ -8,7 +8,15 @@
<!-- peer info -->
<div>
<div class="font-semibold">{{ selectedPeer.display_name }}</div>
<div @click="updateCustomDisplayName" class="flex cursor-pointer">
<div v-if="selectedPeer.custom_display_name != null" class="my-auto mr-1" title="Custom Display Name">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-4">
<path stroke-linecap="round" stroke-linejoin="round" d="M9.568 3H5.25A2.25 2.25 0 0 0 3 5.25v4.318c0 .597.237 1.17.659 1.591l9.581 9.581c.699.699 1.78.872 2.607.33a18.095 18.095 0 0 0 5.223-5.223c.542-.827.369-1.908-.33-2.607L11.16 3.66A2.25 2.25 0 0 0 9.568 3Z" />
<path stroke-linecap="round" stroke-linejoin="round" d="M6 6h.008v.008H6V6Z" />
</svg>
</div>
<div class="my-auto font-semibold" :title="selectedPeer.display_name">{{ selectedPeer.custom_display_name ?? selectedPeer.display_name }}</div>
</div>
<div class="text-sm"><{{ selectedPeer.destination_hash }}> <span v-if="selectedPeerPath" @click="onDestinationPathClick(selectedPeerPath)" class="cursor-pointer">{{ selectedPeerPath.hops }} {{ selectedPeerPath.hops === 1 ? 'hop' : 'hops' }} away</span></div>
</div>
@ -638,6 +646,53 @@ export default {
isLxmfMessageInUi: function(hash) {
return this.chatItems.findIndex((chatItem) => chatItem.lxmf_message?.hash === hash) !== -1;
},
async getCustomDisplayName() {
if(this.selectedPeer){
try {
// get custom display name
const response = await window.axios.get(`/api/v1/destination/${this.selectedPeer.destination_hash}/custom-display-name`);
// update ui
this.selectedPeer.custom_display_name = response.data.custom_display_name;
} catch(e) {
console.log(e);
}
}
},
async updateCustomDisplayName() {
// do nothing if no peer selected
if(!this.selectedPeer){
return;
}
// ask user for new display name
const displayName = await DialogUtils.prompt("Enter a custom display name");
if(displayName == null){
return;
}
try {
// update display name on server
await axios.post(`/api/v1/destination/${this.selectedPeer.destination_hash}/custom-display-name/update`, {
display_name: displayName,
});
// update display name in ui
await this.getCustomDisplayName();
// reload conversations (so conversations list updates name)
this.$emit("reload-conversations");
} catch(e) {
console.log(e);
DialogUtils.alert("Failed to update display name");
}
},
async deleteConversation() {
// do nothing if no peer selected

View file

@ -29,7 +29,7 @@
</div>
</div>
<div class="mr-auto">
<div class="text-gray-900" :class="{ 'font-semibold': conversation.is_unread || conversation.failed_messages_count > 0 }">{{ conversation.display_name }}</div>
<div class="text-gray-900" :class="{ 'font-semibold': conversation.is_unread || conversation.failed_messages_count > 0 }">{{ conversation.custom_display_name ?? conversation.display_name }}</div>
<div class="text-gray-500 text-sm">{{ formatTimeAgo(conversation.updated_at) }}</div>
</div>
<div v-if="conversation.is_unread" class="my-auto ml-2 mr-2">
@ -90,7 +90,7 @@
</div>
</div>
<div>
<div class="text-gray-900">{{ peer.display_name }}</div>
<div class="text-gray-900">{{ peer.custom_display_name ?? peer.display_name }}</div>
<div class="text-gray-500 text-sm">{{ formatTimeAgo(peer.updated_at) }}</div>
</div>
</div>
@ -161,8 +161,9 @@ export default {
return this.conversations.filter((conversation) => {
const search = this.conversationsSearchTerm.toLowerCase();
const matchesDisplayName = conversation.display_name.toLowerCase().includes(search);
const matchesCustomDisplayName = conversation.custom_display_name?.toLowerCase()?.includes(search) === true;
const matchesDestinationHash = conversation.destination_hash.toLowerCase().includes(search);
return matchesDisplayName || matchesDestinationHash;
return matchesDisplayName || matchesCustomDisplayName || matchesDestinationHash;
});
},
peersCount() {
@ -181,8 +182,9 @@ export default {
return this.peersOrderedByLatestAnnounce.filter((peer) => {
const search = this.peersSearchTerm.toLowerCase();
const matchesDisplayName = peer.display_name.toLowerCase().includes(search);
const matchesCustomDisplayName = peer.custom_display_name?.toLowerCase()?.includes(search) === true;
const matchesDestinationHash = peer.destination_hash.toLowerCase().includes(search);
return matchesDisplayName || matchesDestinationHash;
return matchesDisplayName || matchesCustomDisplayName || matchesDestinationHash;
});
},
},