SHA256
Добавлен канал личных публикаций
This commit is contained in:
@@ -21,6 +21,16 @@ public final class ChannelReadStateDAO {
|
||||
|
||||
private ChannelReadStateDAO() {}
|
||||
|
||||
// Корневой канал существует виртуально даже до появления Header. Никаких записей CreateChannel.
|
||||
private static final String PUBLIC_CHANNELS = """
|
||||
public_channels AS (
|
||||
SELECT owner_login, slug, channel_root_block_number, channel_root_block_hash, is_deleted
|
||||
FROM channel_names_state WHERE channel_type_code=1 AND slug<>'stories'
|
||||
UNION ALL
|
||||
SELECT login, 'stories', 0, NULL::bytea, FALSE FROM user_identity_current
|
||||
)
|
||||
""";
|
||||
|
||||
public static ChannelReadStateDAO getInstance() {
|
||||
if (instance == null) {
|
||||
synchronized (ChannelReadStateDAO.class) {
|
||||
@@ -64,22 +74,21 @@ public final class ChannelReadStateDAO {
|
||||
}
|
||||
|
||||
public long sumUnreadCount(Connection c, String viewerLogin) throws SQLException {
|
||||
String sql = """
|
||||
String sql = "WITH " + PUBLIC_CHANNELS + """
|
||||
SELECT COALESCE(SUM(crs.unread_count),0)
|
||||
FROM channel_read_state crs
|
||||
WHERE LOWER(crs.viewer_login)=LOWER(?)
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM channel_names_state cns
|
||||
FROM public_channels cns
|
||||
JOIN connections_state cs
|
||||
ON LOWER(cs.login)=LOWER(crs.viewer_login)
|
||||
AND cs.rel_type=30
|
||||
AND LOWER(cs.to_login)=LOWER(cns.owner_login)
|
||||
AND COALESCE(cs.to_block_number,0)=cns.channel_root_block_number
|
||||
AND cs.to_block_hash=cns.channel_root_block_hash
|
||||
AND (cns.channel_root_block_number=0 OR cs.to_block_hash=cns.channel_root_block_hash)
|
||||
WHERE LOWER(cns.owner_login)=LOWER(crs.owner_login)
|
||||
AND cns.slug=crs.channel_name
|
||||
AND cns.channel_type_code=1
|
||||
AND NOT cns.is_deleted
|
||||
)
|
||||
""";
|
||||
@@ -96,18 +105,17 @@ public final class ChannelReadStateDAO {
|
||||
*/
|
||||
public boolean hasActiveSubscription(Connection c, String viewerLogin, String ownerBchName, String channelName,
|
||||
int followRelType) throws SQLException {
|
||||
String sql = """
|
||||
String sql = "WITH " + PUBLIC_CHANNELS + """
|
||||
SELECT 1
|
||||
FROM channel_names_state cns
|
||||
FROM public_channels cns
|
||||
JOIN connections_state cs
|
||||
ON LOWER(cs.login)=LOWER(?)
|
||||
AND cs.rel_type=?
|
||||
AND LOWER(cs.to_login)=LOWER(cns.owner_login)
|
||||
AND COALESCE(cs.to_block_number,0)=cns.channel_root_block_number
|
||||
AND cs.to_block_hash=cns.channel_root_block_hash
|
||||
AND (cns.channel_root_block_number=0 OR cs.to_block_hash=cns.channel_root_block_hash)
|
||||
WHERE LOWER(cns.owner_login)=LOWER(?)
|
||||
AND cns.slug=?
|
||||
AND cns.channel_type_code=1
|
||||
LIMIT 1
|
||||
""";
|
||||
try (PreparedStatement ps = c.prepareStatement(sql)) {
|
||||
@@ -122,10 +130,10 @@ public final class ChannelReadStateDAO {
|
||||
}
|
||||
|
||||
public String resolvePublicChannelNameByRoot(Connection c, String ownerBchName, int rootBlockNumber) throws SQLException {
|
||||
String sql = """
|
||||
String sql = "WITH " + PUBLIC_CHANNELS + """
|
||||
SELECT slug
|
||||
FROM channel_names_state
|
||||
WHERE LOWER(owner_login)=LOWER(?) AND channel_root_block_number=? AND channel_type_code=1
|
||||
FROM public_channels
|
||||
WHERE LOWER(owner_login)=LOWER(?) AND channel_root_block_number=?
|
||||
LIMIT 1
|
||||
""";
|
||||
try (PreparedStatement ps = c.prepareStatement(sql)) {
|
||||
@@ -139,10 +147,10 @@ public final class ChannelReadStateDAO {
|
||||
|
||||
|
||||
public Integer resolvePublicChannelRootByName(Connection c, String ownerBchName, String channelName) throws SQLException {
|
||||
String sql = """
|
||||
String sql = "WITH " + PUBLIC_CHANNELS + """
|
||||
SELECT channel_root_block_number
|
||||
FROM channel_names_state
|
||||
WHERE LOWER(owner_login)=LOWER(?) AND slug=? AND channel_type_code=1
|
||||
FROM public_channels
|
||||
WHERE LOWER(owner_login)=LOWER(?) AND slug=?
|
||||
LIMIT 1
|
||||
""";
|
||||
try (PreparedStatement ps = c.prepareStatement(sql)) {
|
||||
@@ -155,10 +163,10 @@ public final class ChannelReadStateDAO {
|
||||
}
|
||||
|
||||
public String resolveOwnerLogin(Connection c, String ownerBchName, String channelName) throws SQLException {
|
||||
String sql = """
|
||||
String sql = "WITH " + PUBLIC_CHANNELS + """
|
||||
SELECT owner_login
|
||||
FROM channel_names_state
|
||||
WHERE LOWER(owner_login)=LOWER(?) AND slug=? AND channel_type_code=1
|
||||
FROM public_channels
|
||||
WHERE LOWER(owner_login)=LOWER(?) AND slug=?
|
||||
LIMIT 1
|
||||
""";
|
||||
try (PreparedStatement ps = c.prepareStatement(sql)) {
|
||||
@@ -242,7 +250,7 @@ public final class ChannelReadStateDAO {
|
||||
String channelName,
|
||||
int followRelType,
|
||||
long nowMs) throws SQLException {
|
||||
String sql = """
|
||||
String sql = "WITH " + PUBLIC_CHANNELS + """
|
||||
UPDATE channel_read_state crs
|
||||
SET unread_count = crs.unread_count + 1,
|
||||
updated_at_ms = ?
|
||||
@@ -251,16 +259,15 @@ public final class ChannelReadStateDAO {
|
||||
AND LOWER(crs.viewer_login) <> LOWER(crs.owner_login)
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM channel_names_state cns
|
||||
FROM public_channels cns
|
||||
JOIN connections_state cs
|
||||
ON LOWER(cs.login)=LOWER(crs.viewer_login)
|
||||
AND cs.rel_type=?
|
||||
AND LOWER(cs.to_login)=LOWER(cns.owner_login)
|
||||
AND COALESCE(cs.to_block_number,0)=cns.channel_root_block_number
|
||||
AND cs.to_block_hash=cns.channel_root_block_hash
|
||||
AND (cns.channel_root_block_number=0 OR cs.to_block_hash=cns.channel_root_block_hash)
|
||||
WHERE LOWER(cns.owner_login)=LOWER(crs.owner_login)
|
||||
AND cns.slug=crs.channel_name
|
||||
AND cns.channel_type_code=1
|
||||
)
|
||||
RETURNING viewer_login
|
||||
""";
|
||||
@@ -280,15 +287,14 @@ public final class ChannelReadStateDAO {
|
||||
/** Delete the projection row when a channel FOLLOW is explicitly removed. */
|
||||
public boolean deleteForUnfollowTarget(Connection c, String viewerLogin, String ownerBchName,
|
||||
int rootBlockNumber) throws SQLException {
|
||||
String sql = """
|
||||
String sql = "WITH " + PUBLIC_CHANNELS + """
|
||||
DELETE FROM channel_read_state crs
|
||||
USING channel_names_state cns
|
||||
USING public_channels cns
|
||||
WHERE LOWER(crs.viewer_login)=LOWER(?)
|
||||
AND LOWER(crs.owner_login)=LOWER(?)
|
||||
AND LOWER(cns.owner_login)=LOWER(crs.owner_login)
|
||||
AND cns.slug=crs.channel_name
|
||||
AND cns.channel_root_block_number=?
|
||||
AND cns.channel_type_code=1
|
||||
""";
|
||||
try (PreparedStatement ps = c.prepareStatement(sql)) {
|
||||
ps.setString(1, viewerLogin);
|
||||
@@ -303,17 +309,17 @@ public final class ChannelReadStateDAO {
|
||||
* when its stored count changes. Keep the last accepted timestamp to reject stale requests.
|
||||
*/
|
||||
public int recalculateUnreadForOwnedChannels(Connection c, String ownerLogin, long nowMs) throws SQLException {
|
||||
String sql = """
|
||||
WITH counts AS (
|
||||
String sql = "WITH " + PUBLIC_CHANNELS + ", " + """
|
||||
counts AS (
|
||||
SELECT cns.owner_login, cns.slug, COUNT(b.block_number)::BIGINT AS message_count
|
||||
FROM channel_names_state cns
|
||||
FROM public_channels cns
|
||||
LEFT JOIN blocks_store b
|
||||
ON LOWER(b.login)=LOWER(cns.owner_login)
|
||||
AND b.line_code=cns.channel_root_block_number
|
||||
AND b.msg_type=1
|
||||
AND b.msg_sub_type IN (10,50,100,110,120,130)
|
||||
AND b.fork_number=shine_active_fork(b.login,b.block_number)
|
||||
WHERE LOWER(cns.owner_login)=LOWER(?)
|
||||
AND cns.channel_type_code=1
|
||||
GROUP BY cns.owner_login,cns.slug
|
||||
)
|
||||
UPDATE channel_read_state crs
|
||||
|
||||
@@ -113,27 +113,39 @@ public final class UserProfileStateDAO {
|
||||
|
||||
public List<ChannelCard> listPublicChannels(Connection c, String login, String mode, boolean includeDeleted, int limit, int offset) throws SQLException {
|
||||
int safeLimit=Math.max(1,Math.min(limit<=0?100:limit,500)), safeOffset=Math.max(0,offset);
|
||||
String virtualChannels = """
|
||||
WITH public_channels AS (
|
||||
SELECT owner_login, slug, display_name, ava_ar, ava_pr, owner_bch_name,
|
||||
channel_root_block_number, channel_root_block_hash, is_deleted, deleted_at_ms, deleted_block_number
|
||||
FROM channel_names_state WHERE channel_type_code=1
|
||||
UNION ALL
|
||||
SELECT u.login, 'stories', COALESCE(NULLIF(TRIM(CONCAT_WS(' ', p.first_name, p.last_name)), ''), u.login),
|
||||
COALESCE(p.ava_ar,''), '', u.blockchain_name, 0, NULL::bytea, FALSE, 0::bigint, NULL::integer
|
||||
FROM user_identity_current u LEFT JOIN user_profile_state p ON LOWER(p.login)=LOWER(u.login)
|
||||
)
|
||||
""";
|
||||
String sql;
|
||||
if ("owned".equals(mode)) {
|
||||
sql="""
|
||||
sql=virtualChannels+"""
|
||||
SELECT cn.owner_login, cn.slug, cn.display_name, cn.ava_ar, cn.ava_pr, cn.owner_bch_name,
|
||||
cn.channel_root_block_number, encode(cn.channel_root_block_hash,'hex') root_hash,
|
||||
cn.is_deleted, cn.deleted_at_ms, cn.deleted_block_number
|
||||
FROM channel_names_state cn
|
||||
WHERE LOWER(cn.owner_login)=LOWER(?) AND cn.channel_type_code=1 AND (? OR NOT cn.is_deleted)
|
||||
ORDER BY cn.display_name, cn.slug LIMIT ? OFFSET ?
|
||||
FROM public_channels cn
|
||||
WHERE LOWER(cn.owner_login)=LOWER(?) AND (? OR NOT cn.is_deleted)
|
||||
ORDER BY CASE WHEN cn.channel_root_block_number=0 THEN 0 ELSE 1 END, cn.display_name, cn.slug LIMIT ? OFFSET ?
|
||||
""";
|
||||
} else if ("following".equals(mode)) {
|
||||
sql="""
|
||||
SELECT DISTINCT cn.owner_login, cn.slug, cn.display_name, cn.ava_ar, cn.ava_pr, cn.owner_bch_name,
|
||||
sql=virtualChannels+"""
|
||||
SELECT cn.owner_login, cn.slug, cn.display_name, cn.ava_ar, cn.ava_pr, cn.owner_bch_name,
|
||||
cn.channel_root_block_number, encode(cn.channel_root_block_hash,'hex') root_hash,
|
||||
cn.is_deleted, cn.deleted_at_ms, cn.deleted_block_number
|
||||
FROM connections_state cs
|
||||
JOIN channel_names_state cn
|
||||
ON LOWER(cn.owner_login)=LOWER(cs.to_login)
|
||||
AND cn.channel_root_block_number=cs.to_block_number
|
||||
AND cn.channel_root_block_hash=cs.to_block_hash
|
||||
WHERE LOWER(cs.login)=LOWER(?) AND cs.rel_type=30 AND cn.channel_type_code=1 AND (? OR NOT cn.is_deleted)
|
||||
FROM public_channels cn
|
||||
WHERE EXISTS (SELECT 1 FROM connections_state cs
|
||||
WHERE LOWER(cs.login)=LOWER(?) AND cs.rel_type=30
|
||||
AND LOWER(cs.to_login)=LOWER(cn.owner_login)
|
||||
AND cs.to_block_number=cn.channel_root_block_number
|
||||
AND (cn.channel_root_block_number=0 OR cs.to_block_hash=cn.channel_root_block_hash))
|
||||
AND (? OR NOT cn.is_deleted)
|
||||
ORDER BY cn.display_name, cn.slug LIMIT ? OFFSET ?
|
||||
""";
|
||||
} else throw new IllegalArgumentException("Unsupported channel mode: "+mode);
|
||||
@@ -143,7 +155,7 @@ public final class UserProfileStateDAO {
|
||||
try(ResultSet rs=ps.executeQuery()){
|
||||
while(rs.next()) out.add(new ChannelCard(
|
||||
rs.getString("owner_login"), rs.getString("slug"), rs.getString("display_name"), rs.getString("ava_ar"), rs.getString("ava_pr"),
|
||||
rs.getString("owner_bch_name"), rs.getInt("channel_root_block_number"), rs.getString("root_hash"),
|
||||
rs.getString("owner_bch_name"), rs.getInt("channel_root_block_number"), rs.getInt("channel_root_block_number") == 0 ? publicationsHash(c, rs.getString("owner_bch_name")) : rs.getString("root_hash"),
|
||||
rs.getBoolean("is_deleted"), rs.getLong("deleted_at_ms"), (Integer) rs.getObject("deleted_block_number")
|
||||
));
|
||||
}
|
||||
@@ -151,6 +163,11 @@ public final class UserProfileStateDAO {
|
||||
return out;
|
||||
}
|
||||
|
||||
private static String publicationsHash(Connection c, String ownerBch) throws SQLException {
|
||||
byte[] hash=CanonicalChainResolver.getInstance().getHash(c,ownerBch,0);
|
||||
return java.util.HexFormat.of().formatHex(hash == null ? new byte[32] : hash);
|
||||
}
|
||||
|
||||
private static ProfileCard map(ResultSet rs)throws SQLException{return new ProfileCard(rs.getString("login"),rs.getString("first_name"),rs.getString("last_name"),rs.getString("ava_ar"),rs.getString("account_role"),rs.getString("shine_status"));}
|
||||
public record ProfileCard(String login,String firstName,String lastName,String avatarAr,String accountRole,String shineStatus){}
|
||||
public record RelationCard(String login,String firstName,String lastName,String avatarAr,String accountRole,String shineStatus,boolean primaryConfirmed,boolean shineConfirmed,String relationType,int primaryConfirmationsCount,int shineConfirmationsCount){}
|
||||
|
||||
+9
@@ -444,6 +444,9 @@ public final class Net_AddBlock_Handler implements JsonMessageHandler {
|
||||
: ChannelNameRules.requireValidPublicDisplayNameForCreate(createChannelBody.channelName);
|
||||
}
|
||||
slug = ChannelNameRules.toCanonicalSlug(normalizedName);
|
||||
if (!replayMode && "stories".equals(slug)) {
|
||||
return new AddBlockResult(WireCodes.Status.BAD_REQUEST, "reserved_channel_name", serverLastNum, serverLastHashHex);
|
||||
}
|
||||
} catch (IllegalArgumentException badName) {
|
||||
return new AddBlockResult(WireCodes.Status.BAD_REQUEST, "bad_channel_name", serverLastNum, serverLastHashHex);
|
||||
}
|
||||
@@ -533,6 +536,12 @@ public final class Net_AddBlock_Handler implements JsonMessageHandler {
|
||||
channelMetaUpdateEntry.setMetaUpdatedAtMs(block.timestamp * 1000L);
|
||||
}
|
||||
|
||||
if ((block.type & 0xFFFF) == 1
|
||||
&& (block.subType & 0xFFFF) == (MsgSubType.TEXT_CHANNEL_DELETE & 0xFFFF)
|
||||
&& block.body instanceof TextLineBody deleteBody && deleteBody.lineCode() == 0 && !replayMode) {
|
||||
return new AddBlockResult(WireCodes.Status.BAD_REQUEST, "cannot_delete_publications", serverLastNum, serverLastHashHex);
|
||||
}
|
||||
|
||||
if ((block.type & 0xFFFF) == 1
|
||||
&& (block.subType & 0xFFFF) == (MsgSubType.TEXT_EDIT_POST & 0xFFFF)) {
|
||||
try {
|
||||
|
||||
+2
-2
@@ -108,7 +108,7 @@ public final class BlockchainWriter {
|
||||
}
|
||||
if (channelVisibilityChanged) counterChangedLogins.addAll(refreshChannelVisibilityStats(c, blockchainName, lineCode));
|
||||
}
|
||||
if (!replayMode && isPublicChannelPublication(msgType, msgSubType) && lineCode != null && lineCode > 0) {
|
||||
if (!replayMode && isPublicChannelPublication(msgType, msgSubType) && lineCode != null && lineCode >= 0) {
|
||||
String channelName = channelReadStateDAO.resolvePublicChannelNameByRoot(c, blockchainName, lineCode);
|
||||
if (channelName != null && !channelName.isBlank()) {
|
||||
counterChangedLogins.addAll(channelReadStateDAO.incrementUnreadForSubscribers(
|
||||
@@ -119,7 +119,7 @@ public final class BlockchainWriter {
|
||||
if (!replayMode && msgType == 3
|
||||
&& msgSubType == (MsgSubType.CONNECTION_UNFOLLOW & 0xFFFF)
|
||||
&& be.getToBchName() != null && !be.getToBchName().isBlank()
|
||||
&& be.getToBlockNumber() != null && be.getToBlockNumber() > 0) {
|
||||
&& be.getToBlockNumber() != null && be.getToBlockNumber() >= 0) {
|
||||
if (channelReadStateDAO.deleteForUnfollowTarget(
|
||||
c, be.getLogin(), be.getToBchName(), be.getToBlockNumber())) {
|
||||
counterChangedLogins.add(be.getLogin());
|
||||
|
||||
+23
@@ -55,6 +55,11 @@ final class ChannelsReadSupport {
|
||||
return value;
|
||||
}
|
||||
|
||||
static byte[] publicationsRootHash(Connection c, String ownerBch) throws SQLException {
|
||||
byte[] hash = shine.db.dao.CanonicalChainResolver.getInstance().getHash(c, ownerBch, 0);
|
||||
return hash == null ? new byte[32] : hash;
|
||||
}
|
||||
|
||||
static ChannelMeta detectChannelMeta(Connection c, String ownerBch, int rootNumber) throws SQLException {
|
||||
ChannelMeta meta = new ChannelMeta();
|
||||
meta.channelTypeVersion = CreateChannelBody.CHANNEL_TYPE_VERSION_DEFAULT & 0xFFFF;
|
||||
@@ -64,6 +69,24 @@ final class ChannelsReadSupport {
|
||||
meta.displayName = STORIES_CHANNEL_NAME;
|
||||
meta.channelDescription = "";
|
||||
meta.channelTypeCode = CreateChannelBody.CHANNEL_TYPE_STORIES & 0xFFFF;
|
||||
String ownerLogin = loginFromChainName(ownerBch);
|
||||
meta.displayName = ownerLogin;
|
||||
try (PreparedStatement ps = c.prepareStatement("""
|
||||
SELECT first_name,last_name,ava_ar,updated_at_ms FROM user_profile_state WHERE LOWER(login)=LOWER(?) LIMIT 1
|
||||
""")) {
|
||||
ps.setString(1, ownerLogin);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (rs.next()) {
|
||||
String name = (rs.getString("first_name") + " " + rs.getString("last_name")).trim();
|
||||
if (!name.isBlank()) meta.displayName = name;
|
||||
var avatar = server.logic.ws_protocol.JSON.handlers.profile.AvatarValueParser.parse(rs.getString("ava_ar"));
|
||||
meta.avaAr = avatar.ar();
|
||||
meta.avaPr = avatar.pr();
|
||||
meta.avaSize = avatar.size();
|
||||
meta.metaUpdatedAtMs = rs.getLong("updated_at_ms");
|
||||
}
|
||||
}
|
||||
}
|
||||
return meta;
|
||||
}
|
||||
|
||||
|
||||
+10
-1
@@ -79,7 +79,7 @@ public class Net_GetChannelMessages_Handler implements JsonMessageHandler {
|
||||
channel.setDeletedBlockNumber(meta.deletedBlockNumber);
|
||||
Net_GetChannelMessages_Response.BlockRef rootRef = new Net_GetChannelMessages_Response.BlockRef();
|
||||
rootRef.setBlockNumber(lineCode);
|
||||
rootRef.setBlockHash(req.getChannel().getChannelRootBlockHash());
|
||||
rootRef.setBlockHash(lineCode == 0 ? ChannelsReadSupport.toHex(ChannelsReadSupport.publicationsRootHash(c, ownerBch)) : req.getChannel().getChannelRootBlockHash());
|
||||
channel.setChannelRoot(rootRef);
|
||||
resp.setChannel(channel);
|
||||
|
||||
@@ -205,6 +205,15 @@ public class Net_GetChannelMessages_Handler implements JsonMessageHandler {
|
||||
}
|
||||
|
||||
private static int loadSubscribersCount(Connection c, String ownerBch, int rootNumber, int channelTypeCode) {
|
||||
if (rootNumber == 0) {
|
||||
try (PreparedStatement ps = c.prepareStatement("SELECT COUNT(DISTINCT LOWER(login)) FROM connections_state WHERE LOWER(to_login)=LOWER(?) AND rel_type=30 AND to_block_number=0")) {
|
||||
ps.setString(1, BlockchainNameUtil.loginFromBlockchainName(ownerBch));
|
||||
try (ResultSet rs = ps.executeQuery()) { return rs.next() ? rs.getInt(1) : 0; }
|
||||
} catch (Exception e) {
|
||||
log.warn("GetChannelMessages: не удалось загрузить подписчиков публикаций {}", ownerBch, e);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (channelTypeCode != (CreateChannelBody.CHANNEL_TYPE_PUBLIC & 0xFFFF)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
+3
-2
@@ -50,7 +50,8 @@ public class Net_GetChannelsCounters_Handler implements JsonMessageHandler {
|
||||
|
||||
private int countFeed(Connection c, String login) throws Exception {
|
||||
String sql = """
|
||||
SELECT COUNT(*)
|
||||
SELECT COUNT(DISTINCT (LOWER(to_login), COALESCE(to_block_number,0),
|
||||
CASE WHEN COALESCE(to_block_number,0)=0 THEN NULL ELSE to_block_hash END))
|
||||
FROM connections_state
|
||||
WHERE LOWER(login) = LOWER(?)
|
||||
AND rel_type = ?
|
||||
@@ -81,7 +82,7 @@ public class Net_GetChannelsCounters_Handler implements JsonMessageHandler {
|
||||
}
|
||||
|
||||
private int countMyChannels(Connection c, String login) throws Exception {
|
||||
String bchCountSql = "SELECT COUNT(*) FROM blockchain_state WHERE LOWER(login) = LOWER(?)";
|
||||
String bchCountSql = "SELECT COUNT(*) FROM user_identity_current WHERE LOWER(login) = LOWER(?)";
|
||||
int stories = 0;
|
||||
try (PreparedStatement ps = c.prepareStatement(bchCountSql)) {
|
||||
ps.setString(1, login);
|
||||
|
||||
+2
-1
@@ -84,7 +84,7 @@ public class Net_ListSubscriptionsFeed_Handler implements JsonMessageHandler {
|
||||
|
||||
Net_ListSubscriptionsFeed_Response.BlockRef rootRef = new Net_ListSubscriptionsFeed_Response.BlockRef();
|
||||
rootRef.setBlockNumber(key.rootNumber);
|
||||
rootRef.setBlockHash(ChannelsReadSupport.toHex(key.rootHash));
|
||||
rootRef.setBlockHash(ChannelsReadSupport.toHex(key.rootNumber == 0 && key.ownerLogin.equalsIgnoreCase(viewerLogin) ? ChannelsReadSupport.publicationsRootHash(c, key.ownerBch) : key.rootHash));
|
||||
channelRef.setChannelRoot(rootRef);
|
||||
|
||||
row.setChannel(channelRef);
|
||||
@@ -155,6 +155,7 @@ public class Net_ListSubscriptionsFeed_Handler implements JsonMessageHandler {
|
||||
int rootNumber = rs.getInt("root_number");
|
||||
if (onlyUserRoots && rootNumber != 0) continue;
|
||||
if (!onlyUserRoots && rootNumber == 0) continue;
|
||||
if (rs.getString("to_bch_name") == null) continue;
|
||||
out.add(new ChannelKey(
|
||||
rs.getString("to_login"),
|
||||
rs.getString("to_bch_name"),
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
package server.logic.ws_protocol.JSON.handlers.profile;
|
||||
import server.logic.ws_protocol.JSON.*;import server.logic.ws_protocol.JSON.entyties.*;import server.logic.ws_protocol.JSON.handlers.JsonMessageHandler;import server.logic.ws_protocol.JSON.handlers.profile.entyties.*;import server.logic.ws_protocol.JSON.utils.NetExceptionResponseFactory;import server.logic.ws_protocol.WireCodes;import shine.db.dao.UserProfileStateDAO;import java.sql.*;import java.util.*;
|
||||
public class Net_ListUserProfileChannels_Handler implements JsonMessageHandler {public Net_Response handle(Net_Request base,ConnectionContext ctx)throws Exception{var req=(Net_ListUserProfileChannels_Request)base;if(req.getLogin()==null||req.getLogin().isBlank())return NetExceptionResponseFactory.error(req,400,"BAD_FIELDS","login required");try(Connection c=shine.db.DbController.getInstance().getConnection()){var rows=UserProfileStateDAO.getInstance().listPublicChannels(c,req.getLogin(),req.getMode(),Boolean.TRUE.equals(req.getIncludeDeleted()),req.getLimit()==null?100:req.getLimit(),req.getOffset()==null?0:req.getOffset());var resp=new Net_ListUserProfileChannels_Response();resp.setOp(req.getOp());resp.setRequestId(req.getRequestId());resp.setStatus(WireCodes.Status.OK);resp.setLogin(req.getLogin());resp.setMode(req.getMode());List<Net_ListUserProfileChannels_Response.ChannelItem> items=new ArrayList<>();for(var r:rows){var i=new Net_ListUserProfileChannels_Response.ChannelItem();i.setOwnerLogin(r.ownerLogin());i.setSlug(r.slug());i.setDisplayName(r.displayName());i.setAvatarAr(r.avatarAr());i.setAvatarPr(r.avatarPr());i.setOwnerBlockchainName(r.ownerBlockchainName());i.setRootBlockNumber(r.rootBlockNumber());i.setRootBlockHashHex(r.rootBlockHashHex());i.setDeleted(r.deleted());i.setDeletedAtMs(r.deletedAtMs());i.setDeletedBlockNumber(r.deletedBlockNumber());items.add(i);}resp.setChannels(items);return resp;}}}
|
||||
public class Net_ListUserProfileChannels_Handler implements JsonMessageHandler {public Net_Response handle(Net_Request base,ConnectionContext ctx)throws Exception{var req=(Net_ListUserProfileChannels_Request)base;if(req.getLogin()==null||req.getLogin().isBlank())return NetExceptionResponseFactory.error(req,400,"BAD_FIELDS","login required");try(Connection c=shine.db.DbController.getInstance().getConnection()){var rows=UserProfileStateDAO.getInstance().listPublicChannels(c,req.getLogin(),req.getMode(),Boolean.TRUE.equals(req.getIncludeDeleted()),req.getLimit()==null?100:req.getLimit(),req.getOffset()==null?0:req.getOffset());var resp=new Net_ListUserProfileChannels_Response();resp.setOp(req.getOp());resp.setRequestId(req.getRequestId());resp.setStatus(WireCodes.Status.OK);resp.setLogin(req.getLogin());resp.setMode(req.getMode());List<Net_ListUserProfileChannels_Response.ChannelItem> items=new ArrayList<>();for(var r:rows){var i=new Net_ListUserProfileChannels_Response.ChannelItem();i.setOwnerLogin(r.ownerLogin());i.setSlug(r.slug());i.setDisplayName(r.displayName());if(r.rootBlockNumber()==0){var avatar=AvatarValueParser.parse(r.avatarAr());i.setAvatarAr(avatar.ar());i.setAvatarPr(avatar.pr());}else{i.setAvatarAr(r.avatarAr());i.setAvatarPr(r.avatarPr());}i.setOwnerBlockchainName(r.ownerBlockchainName());i.setRootBlockNumber(r.rootBlockNumber());i.setRootBlockHashHex(r.rootBlockHashHex());i.setDeleted(r.deleted());i.setDeletedAtMs(r.deletedAtMs());i.setDeletedBlockNumber(r.deletedBlockNumber());items.add(i);}resp.setChannels(items);return resp;}}}
|
||||
|
||||
+3
-3
@@ -139,7 +139,7 @@ public class Net_GetUser_Handler implements JsonMessageHandler {
|
||||
}
|
||||
|
||||
private static void loadUserStats(Net_GetUser_Response resp, String login) {
|
||||
resp.setOwnedPublicChannelsCount(0);
|
||||
resp.setOwnedPublicChannelsCount(1);
|
||||
resp.setFollowingUsersCount(0);
|
||||
resp.setFollowingChannelsCount(0);
|
||||
resp.setCloseFriendsCount(0);
|
||||
@@ -169,9 +169,9 @@ public class Net_GetUser_Handler implements JsonMessageHandler {
|
||||
if (!rs.next()) {
|
||||
return;
|
||||
}
|
||||
resp.setOwnedPublicChannelsCount(rs.getInt("owned_public_channels_count"));
|
||||
resp.setOwnedPublicChannelsCount(1 + rs.getInt("owned_public_channels_count"));
|
||||
resp.setFollowingUsersCount(rs.getInt("following_users_count"));
|
||||
resp.setFollowingChannelsCount(rs.getInt("following_channels_count"));
|
||||
resp.setFollowingChannelsCount(rs.getInt("following_channels_count") + rs.getInt("following_users_count"));
|
||||
resp.setCloseFriendsCount(rs.getInt("close_friends_count"));
|
||||
resp.setFriendsCount(rs.getInt("friends_count"));
|
||||
resp.setPrimaryConfirmationsReceivedCount(rs.getInt("primary_confirmations_received_count"));
|
||||
|
||||
Reference in New Issue
Block a user