Skip to content

Commit

Permalink
Added blockings for notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
lostystyg committed Sep 1, 2022
1 parent c23e94c commit 6d8148d
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/pocketdb/helpers/ShortFormHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ bool PocketHelpers::ShortTxFilterValidator::Activities::IsFilterAllowed(PocketDb
PocketDb::ShortTxType::CommentScore,
PocketDb::ShortTxType::ContentScore,
PocketDb::ShortTxType::Boost,
PocketDb::ShortTxType::Blocking,
};

return allowed.find(type) != allowed.end();
Expand Down
14 changes: 7 additions & 7 deletions src/pocketdb/models/shortform/ShortTxData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,11 @@ UniValue PocketDb::ShortTxData::Serialize() const
if (m_commentAnswerId) data.pushKV("commentAnswerId", m_commentAnswerId.value());
if (m_rootTxHash) data.pushKV("rootTxHash", *m_rootTxHash);
if (m_multipleAddresses) {
UniValue multipleAddresses(UniValue::VARR);
std::vector<UniValue> tmp;
UniValue multipleAddresses(UniValue::VOBJ);
multipleAddresses.reserveKVSize(m_multipleAddresses->size());
for (const auto& addressData: *m_multipleAddresses) {
UniValue addressDataUni(UniValue::VOBJ);
addressDataUni.pushKV("address", addressData.first);
addressDataUni.pushKVs(addressData.second->Serialize());
tmp.emplace_back(std::move(addressDataUni));
multipleAddresses.pushKV(addressData.first, std::move(addressData.second->Serialize()), false);
}
multipleAddresses.push_backV(tmp);
data.pushKV("multipleAddresses", multipleAddresses);
}

Expand Down Expand Up @@ -102,3 +98,7 @@ const std::optional<std::string>& PocketDb::ShortTxData::GetCommentAnswerId() co
void PocketDb::ShortTxData::SetRootTxHash(const std::optional<std::string>& rootTxHash) { m_rootTxHash = rootTxHash; }

const std::optional<std::string>& PocketDb::ShortTxData::GetRootTxHash() const { return m_rootTxHash; }

void PocketDb::ShortTxData::SetMultipleAddresses(const std::optional<std::vector<std::pair<std::string, std::optional<ShortAccount>>>>& multipleAddresses) { m_multipleAddresses = multipleAddresses; }

const std::optional<std::vector<std::pair<std::string, std::optional<PocketDb::ShortAccount>>>>& PocketDb::ShortTxData::GetMultipleAddresses() { return m_multipleAddresses; }
91 changes: 91 additions & 0 deletions src/pocketdb/repositories/web/WebRpcRepository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5273,6 +5273,97 @@ namespace PocketDb
and tBoost.Height > ?
and (tBoost.Height < ? or (tBoost.Height = ? and tBoost.BlockNum < ?))
)sql",
[this](std::shared_ptr<sqlite3_stmt*>& stmt, int& i, QueryParams const& queryParams){
TryBindStatementText(stmt, i++, queryParams.address);
TryBindStatementInt64(stmt, i++, queryParams.heightMin);
TryBindStatementInt64(stmt, i++, queryParams.heightMax);
TryBindStatementInt64(stmt, i++, queryParams.heightMax);
TryBindStatementInt64(stmt, i++, queryParams.blockNumMax);
}
}},

{
ShortTxType::Blocking, { R"sql(
-- My blockings and unblockings
select
('blocking')TP,
b.Hash,
b.Type,
ac.String1,
b.Height as Height,
b.BlockNum as BlockNum,
null,
null,
null,
null,
null,
pac.String2,
pac.String3,
null,
ifnull(rac.Value,0),
(
select json_group_array(
json_object(
'address', mac.String1,
'account', json_object(
'name', pmac.String2,
'avatar', pmac.String3,
'reputation', ifnull(rmac.Value,0)
)
)
) from Transactions mac indexed by Transactions_Type_Last_String1_Height_Id
left join Payload pmac
on pmac.TxHash = mac.Hash
left join Ratings rmac indexed by Ratings_Type_Id_Last_Height
on rmac.Type = 0
and rmac.Id = mac.Id
and rmac.Last = 1
where mac.String1 in (select value from json_each(b.String3))
and mac.Type = 100
and mac.Last = 1
and mac.Height > 0
),
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
from Transactions b indexed by Transactions_Type_String1_Height_Time_Int1
left join Transactions ac indexed by Transactions_Type_Last_String1_Height_Id
on ac.String1 = b.String2
and ac.Type = 100
and ac.Last = 1
and ac.Height > 0
left join Payload pac
on pac.TxHash = ac.Hash
left join Ratings rac indexed by Ratings_Type_Id_Last_Height
on rac.Type = 0
and rac.Id = ac.Id
and rac.Last = 1
where b.Type in (305,306)
and b.String1 = ?
and b.Height > ?
and (b.Height < ? or (b.Height = ? and b.BlockNum < ?))
)sql",
[this](std::shared_ptr<sqlite3_stmt*>& stmt, int& i, QueryParams const& queryParams){
TryBindStatementText(stmt, i++, queryParams.address);
Expand Down
1 change: 1 addition & 0 deletions src/pocketdb/web/PocketContentRpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,7 @@ namespace PocketWeb::PocketWebRpc
{ShortTxTypeConvertor::toString(ShortTxType::CommentScore), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "acc's comments scores"},
{ShortTxTypeConvertor::toString(ShortTxType::ContentScore), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "acc's content scores"},
{ShortTxTypeConvertor::toString(ShortTxType::Boost), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "boosts content done by acc"},
{ShortTxTypeConvertor::toString(ShortTxType::Blocking), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "my blockings/unblockings"},
}
}
},
Expand Down

0 comments on commit 6d8148d

Please sign in to comment.