Compare commits

..

3 commits

Author SHA1 Message Date
02479072f6
style(ui): improve styling of Message component
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
ci/woodpecker/pr/build-and-publish Pipeline was successful
- increase profile picture size
- improve vertical and horizontal centering
- improve the way margins and gaps are styled
- adjust grid CSS
2025-08-06 21:19:48 +02:00
31b0d2e7eb
style(ui): improve styling of media-embedded messages 2025-08-06 21:13:30 +02:00
d5f1ecfd26
feat: make sure every media is embedded in messages and only hide text if it's composed only of links 2025-08-06 21:12:27 +02:00
2 changed files with 48 additions and 28 deletions

View file

@ -43,10 +43,10 @@
{{ date.toLocaleTimeString(undefined, { hour12: props.format == "12", timeStyle: "short" }) }} {{ date.toLocaleTimeString(undefined, { hour12: props.format == "12", timeStyle: "short" }) }}
</span> </span>
</div> </div>
<div class="message-text" v-html="sanitized" :hidden="hasEmbed" tabindex="0"></div> <div class="message-text" v-html="sanitized" :hidden="hideText" tabindex="0"></div>
</div>
<MessageMedia v-if="mediaLinks.length" :links="mediaLinks" /> <MessageMedia v-if="mediaLinks.length" :links="mediaLinks" />
</div> </div>
</div>
<div v-else ref="messageElement" @contextmenu="showContextMenu($event, contextMenu, menuItems)" :id="props.last ? 'last-message' : undefined" <div v-else ref="messageElement" @contextmenu="showContextMenu($event, contextMenu, menuItems)" :id="props.last ? 'last-message' : undefined"
class="message grouped-message" :class="{ 'message-margin-bottom': props.marginBottom, 'mentioned': props.replyMessage || props.isMentioned }" class="message grouped-message" :class="{ 'message-margin-bottom': props.marginBottom, 'mentioned': props.replyMessage || props.isMentioned }"
:data-message-id="props.messageId" :editing.sync="props.editing" :replying-to.sync="props.replyingTo"> :data-message-id="props.messageId" :editing.sync="props.editing" :replying-to.sync="props.replyingTo">
@ -56,7 +56,7 @@
</span> </span>
</div> </div>
<div class="message-data"> <div class="message-data">
<div class="message-text" :class="$style['message-text']" v-html="sanitized" :hidden="hasEmbed" tabindex="0"></div> <div class="message-text" :class="$style['message-text']" v-html="sanitized" :hidden="hideText" tabindex="0"></div>
</div> </div>
<MessageMedia v-if="mediaLinks.length" :links="mediaLinks" /> <MessageMedia v-if="mediaLinks.length" :links="mediaLinks" />
</div> </div>
@ -89,10 +89,10 @@ console.log("[MSG] reply message:", props.replyMessage);
const linkRegex = /https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)/g; const linkRegex = /https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)/g;
const linkMatches = props.message.message.matchAll(linkRegex).map(link => link[0]); const linkMatches = props.message.message.matchAll(linkRegex).map(link => link[0]);
const mediaLinks: string[] = []; const mediaLinks = ref<string[]>([]);
console.log("link matches:", linkMatches); console.log("link matches:", linkMatches);
const hasEmbed = ref(false); const hideText = ref(false);
const sanitized = ref<string>(); const sanitized = ref<string>();
@ -121,22 +121,34 @@ onMounted(async () => {
console.log("added listeners"); console.log("added listeners");
} }
const links: string[] = [];
for (const link of linkMatches) { for (const link of linkMatches) {
console.log("link:", link); console.log("link:", link);
try { try {
const res = await $fetch.raw(link); const res = await $fetch.raw(link);
if (res.ok && res.headers.get("content-type")?.match(/^image\/(apng|gif|jpeg|png|webp)$/)) { if (res.ok && res.headers.get("content-type")?.match(/^image\/(apng|gif|jpeg|png|webp)$/)) {
console.log("link is image"); console.log("link is image");
mediaLinks.push(link); links.push(link);
} }
if (mediaLinks.length) {
hasEmbed.value = true
};
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} }
mediaLinks.value = [...links];
} }
if (mediaLinks.value.length) {
const nonLinks = props.message.message.split(linkRegex);
let invalidContent = false;
for (const nonLink of nonLinks) {
if (nonLink != "" && nonLink != "\n" && nonLink != "<br>") {
invalidContent = true;
break;
}
}
hideText.value = !invalidContent;
};
console.log("media links:", mediaLinks); console.log("media links:", mediaLinks);
}); });
@ -177,9 +189,8 @@ function getDayDifference(date1: Date, date2: Date) {
text-align: left; text-align: left;
/* border: 1px solid lightcoral; */ /* border: 1px solid lightcoral; */
display: grid; display: grid;
grid-template-columns: 2rem 1fr; grid-template-columns: 4rem 1fr;
align-items: center; align-items: center;
column-gap: 1dvw;
width: 100%; width: 100%;
overflow-wrap: anywhere; overflow-wrap: anywhere;
} }
@ -213,10 +224,9 @@ function getDayDifference(date1: Date, date2: Date) {
.message-data { .message-data {
/* border: 1px solid white; */ /* border: 1px solid white; */
margin-left: .5dvw;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
height: fit-content; height: 100%;
width: 100%; width: 100%;
grid-row: 2; grid-row: 2;
grid-column: 2; grid-column: 2;
@ -228,10 +238,10 @@ function getDayDifference(date1: Date, date2: Date) {
} }
.message-author-avatar { .message-author-avatar {
min-height: 2em; min-height: 2.5em;
max-height: 2em; max-height: 2.5em;
min-width: 2em; min-width: 2.5em;
max-width: 2em; max-width: 2.5em;
} }
.left-column { .left-column {
@ -242,8 +252,11 @@ function getDayDifference(date1: Date, date2: Date) {
white-space: nowrap; white-space: nowrap;
grid-row: 2; grid-row: 2;
grid-column: 1; grid-column: 1;
height: 100%;
align-items: start;
} }
.author-username { .author-username {
margin-right: .5dvw; margin-right: .5dvw;
color: white; color: white;

View file

@ -34,9 +34,16 @@ function createModal(link: string) {
<style scoped> <style scoped>
.media-container { .media-container {
display: flex;
grid-column: 2; grid-column: 2;
grid-row: 3; grid-row: 3;
margin-left: .5dvw; gap: .2rem;
}
.grouped-message .media-container {
display: flex;
grid-column: 2;
grid-row: 2;
} }
.media-item { .media-item {