aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server/src')
-rw-r--r--juick-server/src/main/assets/scripts.js123
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/Profile.java13
-rw-r--r--juick-server/src/main/resources/templates/views/thread.html10
3 files changed, 97 insertions, 49 deletions
diff --git a/juick-server/src/main/assets/scripts.js b/juick-server/src/main/assets/scripts.js
index 8060bd71..6cc51d82 100644
--- a/juick-server/src/main/assets/scripts.js
+++ b/juick-server/src/main/assets/scripts.js
@@ -179,7 +179,7 @@ function initWS() {
window.addEventListener('beforeunload', () => {
clearInterval(keepAlive);
ws.close();
- })
+ });
}
function wsSendKeepAlive() {
@@ -359,20 +359,20 @@ function showCommentForm(mid, rid) {
body: formData,
credentials: 'omit'
}).then(handleErrors)
- .then(response => {
- if (response.ok) {
- response.json().then(result => {
- if (result.newMessage) {
- window.location.href = new URL(`${mid}#${result.newMessage.rid}`, window.location.href);
- } else {
- alert(result.text);
- }
- window.location.reload(true);
- });
- }
- }).catch(error => {
- alert(error.message);
- });
+ .then(response => {
+ if (response.ok) {
+ response.json().then(result => {
+ if (result.newMessage) {
+ window.location.href = new URL(`${mid}#${result.newMessage.rid}`, window.location.href);
+ } else {
+ alert(result.text);
+ }
+ window.location.reload(true);
+ });
+ }
+ }).catch(error => {
+ alert(error.message);
+ });
e.preventDefault();
});
}
@@ -642,6 +642,21 @@ function addTag(tag) {
return false;
}
+function fetchUserUri(dataUri, callback) {
+ let data = new FormData();
+ data.append('uri', dataUri);
+ fetch('/u/', {
+ method: 'POST',
+ body: data
+ }).then(handleErrors)
+ .then(response => {
+ return response.json();
+ })
+ .then(json => {
+ callback(json);
+ });
+}
+
/******************************************************************************/
function ready(fn) {
@@ -720,21 +735,21 @@ ready(function () {
body: formData,
credentials: 'omit'
}).then(handleErrors)
- .then(response => {
- if (response.ok) {
- response.json().then(result => {
- if (result.newMessage) {
- window.location = new URL(`/m/${result.newMessage.mid}`, window.location.href);
- } else {
- alert(result.text);
- }
- });
- } else {
- alert('Something went wrong :(');
- }
- }).catch(error => {
- alert(error.message);
- });
+ .then(response => {
+ if (response.ok) {
+ response.json().then(result => {
+ if (result.newMessage) {
+ window.location = new URL(`/m/${result.newMessage.mid}`, window.location.href);
+ } else {
+ alert(result.text);
+ }
+ });
+ } else {
+ alert('Something went wrong :(');
+ }
+ }).catch(error => {
+ alert(error.message);
+ });
e.preventDefault();
});
}
@@ -746,21 +761,21 @@ ready(function () {
body: formData,
credentials: 'omit'
}).then(handleErrors)
- .then(response => {
- if (response.ok) {
- response.json().then(result => {
- if (result.to) {
- window.location = new URL('/pm/sent', window.location.href);
- } else {
- alert('Something went wrong :(');
- }
- });
- } else {
- alert('Something went wrong :(');
- }
- }).catch(error => {
- alert(error.message);
- });
+ .then(response => {
+ if (response.ok) {
+ response.json().then(result => {
+ if (result.to) {
+ window.location = new URL('/pm/sent', window.location.href);
+ } else {
+ alert('Something went wrong :(');
+ }
+ });
+ } else {
+ alert('Something went wrong :(');
+ }
+ }).catch(error => {
+ alert(error.message);
+ });
e.preventDefault();
});
});
@@ -848,6 +863,24 @@ ready(function () {
article.classList.add('nsfw');
}
});
+ document.querySelectorAll('[data-uri]').forEach(el => {
+ fetchUserUri(el.getAttribute('data-uri'), user => {
+ let header = el.closest('.msg-header');
+ header.querySelectorAll('.a-username').forEach(a => {
+ a.setAttribute('href', user.uri);
+ let img = a.querySelector('img');
+ if (img && user.avatar) {
+ img.setAttribute('src', user.avatar);
+ img.setAttribute('alt', user.uname);
+ }
+ let textNode = a.childNodes[0];
+ if (textNode.nodeType === Node.TEXT_NODE && textNode.nodeValue.trim().length > 0) {
+ let uname = document.createTextNode(user.uname);
+ a.replaceChild(uname, a.firstChild);
+ }
+ });
+ });
+ });
initWS();
window.addEventListener('pagehide', wsShutdown);
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
index f2beaa53..80a2851c 100644
--- a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
+++ b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
@@ -11,6 +11,7 @@ import com.juick.server.api.activity.model.activities.Create;
import com.juick.server.api.activity.model.activities.Delete;
import com.juick.server.api.activity.model.activities.Follow;
import com.juick.server.api.activity.model.activities.Undo;
+import com.juick.server.util.HttpBadRequestException;
import com.juick.server.util.HttpNotFoundException;
import com.juick.server.util.UserUtils;
import com.juick.service.MessagesService;
@@ -23,6 +24,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
@@ -274,4 +276,15 @@ public class Profile {
}
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
+ @PostMapping(value = "/u/", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
+ public User fetchUser(@RequestParam URI uri) {
+ Person person = (Person) signatureManager.getContext(uri).orElseThrow(HttpBadRequestException::new);
+ User user = new User();
+ user.setUri(URI.create(person.getUrl()));
+ user.setName(person.getPreferredUsername());
+ if (person.getIcon() != null) {
+ user.setAvatar(person.getIcon().getUrl());
+ }
+ return user;
+ }
}
diff --git a/juick-server/src/main/resources/templates/views/thread.html b/juick-server/src/main/resources/templates/views/thread.html
index 2bed39ae..af9b4069 100644
--- a/juick-server/src/main/resources/templates/views/thread.html
+++ b/juick-server/src/main/resources/templates/views/thread.html
@@ -120,11 +120,13 @@
{% for msg in replies %}
<li id="{{ msg.rid }}" class="msg">
<div class="msg-cont">
- <div class="msg-header">
+ <div class="msg-header" data-uri="{{ msg.user.uri }}">
{% if not msg.user.banned %}
- <a href="/{{ msg.user.name }}/" data-uri="{{ msg.user.uri }}">{{ msg.user.name }}</a>
- <div class="msg-avatar"><a href="/{{ msg.user.name }}/" data-uri="{{ msg.user.uri }}">
- <img src="//i.juick.com/a/{{ msg.user.uid }}.png" alt="{{ msg.user.name }}"/></a>
+ <a class="a-username" href="/{{ msg.user.name }}/">{{ msg.user.name }}</a>
+ <div class="msg-avatar">
+ <a class="a-username" href="/{{ msg.user.name }}/">
+ <img src="//i.juick.com/a/{{ msg.user.uid }}.png" alt="{{ msg.user.name }}"/>
+ </a>
</div>
{% else %}
[удалено]: