diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/assets/scripts.js | 5 | ||||
-rw-r--r-- | src/main/assets/style.css | 7 | ||||
-rw-r--r-- | src/main/java/com/juick/service/UserService.java | 2 | ||||
-rw-r--r-- | src/main/java/com/juick/service/UserServiceImpl.java | 26 | ||||
-rw-r--r-- | src/main/java/com/juick/www/api/activity/Profile.java | 2 | ||||
-rw-r--r-- | src/main/java/com/juick/www/controllers/Site.java | 2 | ||||
-rw-r--r-- | src/main/resources/db/specific/h2/V1.22__schema.sql | 2 | ||||
-rw-r--r-- | src/main/resources/templates/views/users.html | 12 | ||||
-rw-r--r-- | src/test/java/com/juick/server/tests/ServerTests.java | 1 |
9 files changed, 34 insertions, 25 deletions
diff --git a/src/main/assets/scripts.js b/src/main/assets/scripts.js index 95ca913d..13f0cb75 100644 --- a/src/main/assets/scripts.js +++ b/src/main/assets/scripts.js @@ -524,6 +524,9 @@ function fetchUserUri(dataUri, callback) { .then(json => { users[dataUri] = json; callback(json); + }) + .catch(e => { + callback({ preferredUsername: dataUri }); }); } } @@ -731,7 +734,7 @@ ready(() => { } let textNode = a.childNodes[0]; if (textNode && textNode.nodeType === Node.TEXT_NODE && textNode.nodeValue && textNode.nodeValue.trim().length > 0) { - let uname = document.createTextNode(user.preferredUsername); + let uname = document.createTextNode(user.preferredUsername || dataUri); if (a.firstChild) { a.replaceChild(uname, a.firstChild); } diff --git a/src/main/assets/style.css b/src/main/assets/style.css index 28293164..9b5d7615 100644 --- a/src/main/assets/style.css +++ b/src/main/assets/style.css @@ -658,9 +658,14 @@ blockquote { flex-wrap: wrap; } .users > span { + display: flex; + flex-direction: row; + align-items: center; + white-space: nowrap; + text-overflow: ellipsis; overflow: hidden; padding: 6px 0; - width: 200px; + width: 220px; } .users img { height: 32px; diff --git a/src/main/java/com/juick/service/UserService.java b/src/main/java/com/juick/service/UserService.java index db02c34e..8fe8bc1f 100644 --- a/src/main/java/com/juick/service/UserService.java +++ b/src/main/java/com/juick/service/UserService.java @@ -113,8 +113,6 @@ public interface UserService { boolean linkTwitterAccount(User user, String accessToken, String accessTokenSecret, String screenName); - int getStatsMyReaders(int uid); - int getStatsMessages(int uid); int getStatsReplies(int uid); diff --git a/src/main/java/com/juick/service/UserServiceImpl.java b/src/main/java/com/juick/service/UserServiceImpl.java index b5581b76..b15a18e5 100644 --- a/src/main/java/com/juick/service/UserServiceImpl.java +++ b/src/main/java/com/juick/service/UserServiceImpl.java @@ -42,6 +42,7 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Nonnull; +import java.net.URI; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -519,17 +520,23 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { @Transactional(readOnly = true) @Override public List<User> getUserReaders(final int uid) { - return getJdbcTemplate().query( - "SELECT users.id, users.nick FROM subscr_users " + - "INNER JOIN users ON subscr_users.suser_id=users.id " + - "WHERE subscr_users.user_id=? ORDER BY users.nick", + return getNamedParameterJdbcTemplate().query( + """ + SELECT users.id, users.nick nick, '' user_uri FROM subscr_users + INNER JOIN users ON subscr_users.suser_id=users.id + WHERE subscr_users.user_id=:user_id + UNION ALL SELECT 0, '', acct user_uri from followers WHERE user_id=:user_id + ORDER BY nick + """, + new MapSqlParameterSource() + .addValue("user_id", uid), (rs, num) -> { User u = new User(); u.setUid(rs.getInt(1)); u.setName(rs.getString(2)); + u.setUri(URI.create(rs.getString(3))); return u; - }, - uid); + }); } @Transactional(readOnly = true) @@ -584,13 +591,6 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { @Transactional(readOnly = true) @Override - public int getStatsMyReaders(final int uid) { - List<Integer> list = getJdbcTemplate().queryForList("SELECT COUNT(*) FROM subscr_users WHERE user_id = ?", Integer.class, uid); - return list.isEmpty() ? 0 : list.get(0); - } - - @Transactional(readOnly = true) - @Override public int getStatsMessages(final int uid) { List<Integer> list = getJdbcTemplate().queryForList("SELECT COUNT(*) FROM messages WHERE user_id = ?", Integer.class, uid); return list.isEmpty() ? 0 : list.get(0); diff --git a/src/main/java/com/juick/www/api/activity/Profile.java b/src/main/java/com/juick/www/api/activity/Profile.java index 5deba2cf..c87d6118 100644 --- a/src/main/java/com/juick/www/api/activity/Profile.java +++ b/src/main/java/com/juick/www/api/activity/Profile.java @@ -174,7 +174,7 @@ public class Profile { UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(baseUri); OrderedCollection followers = new OrderedCollection(); followers.setId(ServletUriComponentsBuilder.fromCurrentRequestUri().toUriString()); - followers.setTotalItems(userService.getStatsMyReaders(user.getUid())); + followers.setTotalItems(userService.getUserReaders(user.getUid()).size()); followers.setFirst(uriComponentsBuilder.path(String.format("/u/%s/followers", userName)).toUriString()); return (OrderedCollection) Context.build(followers); } diff --git a/src/main/java/com/juick/www/controllers/Site.java b/src/main/java/com/juick/www/controllers/Site.java index 2484c8fa..dcb89718 100644 --- a/src/main/java/com/juick/www/controllers/Site.java +++ b/src/main/java/com/juick/www/controllers/Site.java @@ -87,7 +87,7 @@ public class Site { model.addAttribute("isInBL", userService.isInBL(visitor.getUid(), user.getUid())); model.addAttribute("isInBLAny", userService.isInBLAny(user.getUid(), visitor.getUid())); model.addAttribute("statsIRead", userService.getUserFriends(user.getUid()).size()); - model.addAttribute("statsMyReaders", userService.getStatsMyReaders(user.getUid())); + model.addAttribute("statsMyReaders", userService.getUserReaders(user.getUid()).size()); model.addAttribute("statsMyBL", userService.getUserBLUsers(user.getUid()).size()); model.addAttribute("statsMessages", userService.getStatsMessages(user.getUid())); model.addAttribute("statsReplies", userService.getStatsReplies(user.getUid())); diff --git a/src/main/resources/db/specific/h2/V1.22__schema.sql b/src/main/resources/db/specific/h2/V1.22__schema.sql index 2ded0e53..dcb92374 100644 --- a/src/main/resources/db/specific/h2/V1.22__schema.sql +++ b/src/main/resources/db/specific/h2/V1.22__schema.sql @@ -108,7 +108,7 @@ CREATE MEMORY TABLE "PUBLIC"."PM"( CREATE MEMORY TABLE "PUBLIC"."FOLLOWERS"( "USER_ID" INTEGER DEFAULT NULL, "TS" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, - "ACCT" CHARACTER(64) NOT NULL + "ACCT" VARCHAR(64) NOT NULL ); -- 0 +/- SELECT COUNT(*) FROM PUBLIC.FOLLOWERS; CREATE MEMORY TABLE "PUBLIC"."SUBSCR_USERS"( diff --git a/src/main/resources/templates/views/users.html b/src/main/resources/templates/views/users.html index 702ba6b9..f5b15f77 100644 --- a/src/main/resources/templates/views/users.html +++ b/src/main/resources/templates/views/users.html @@ -3,11 +3,13 @@ {% block content %} <div class="users"> {% for u in users %} - <span> - <a href="/{{ u.name }}/"> - <img src="//i.juick.com/as/{{ u.uid }}.png" alt="{{ u.name }}"/> - {{ u.name }} - </a> + <span class="msg-header" {% if (u.uri is not empty) %} data-uri="{{ u.uri }}" {% endif %}> + <div class="msg-avatar"> + <a class="a-username" href="/{{ u.name | default(u.uri) }}/"> + <img src="//i.juick.com/as/{{ u.uid }}.png" alt="{{ u.name | default(u.uri) }}"/> + </a> + </div> + <a class="a-username" href="/{{ u.name | default(u.uri) }}/">{{ u.name | default('Anonymous') }}</a> </span> {% endfor %} </div> diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java index 54cffbd4..1e40ee6e 100644 --- a/src/test/java/com/juick/server/tests/ServerTests.java +++ b/src/test/java/com/juick/server/tests/ServerTests.java @@ -1323,6 +1323,7 @@ public class ServerTests { @Test public void meContainsAllInfo() throws Exception { jdbcTemplate.update("DELETE FROM subscr_users"); + jdbcTemplate.update("DELETE FROM followers"); assertThat(userService.getUserReaders(ugnich.getUid()).size(), is(0)); assertThat(userService.getUserFriends(ugnich.getUid()).size(), is(0)); commandsManager.processCommand(freefd, "S @ugnich", emptyUri); |