Skip to content

Commit

Permalink
Merge pull request #279 from ioriayane/update_pinned_post_handling
Browse files Browse the repository at this point in the history
固定ポストを公式に準拠
  • Loading branch information
ioriayane authored Sep 28, 2024
2 parents ade1d6d + 43445d2 commit 428b2e9
Show file tree
Hide file tree
Showing 25 changed files with 133 additions and 113 deletions.
2 changes: 1 addition & 1 deletion 1stparty/atproto
Submodule atproto updated 230 files
2 changes: 1 addition & 1 deletion app/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ ApplicationWindow {
}
onFinished: {
console.log("onFinished:" + allAccountsReady + ", count=" + columnManageModel.rowCount())
if(columnManageModel.rowCount() === 0){
if(rowCount() === 0){
accountDialog.open()
}else if(columnManageModel.rowCount() === 0){
if(allAccountsReady){
Expand Down
32 changes: 6 additions & 26 deletions app/qtquick/account/accountlistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ void AccountListModel::load()
}
}

checkAllAccountsReady();
if (m_accountList.isEmpty()) {
emit finished();
}
Expand Down Expand Up @@ -470,10 +471,10 @@ void AccountListModel::createSession(int row)
emit errorOccured(session->errorCode(), session->errorMessage());
}
emit dataChanged(index(row), index(row));
checkAllAccountsReady();
if (allAccountTried()) {
emit finished();
}
checkAllAccountsReady();
session->deleteLater();
});
session->setAccount(m_accountList.at(row));
Expand Down Expand Up @@ -514,10 +515,10 @@ void AccountListModel::refreshSession(int row, bool initial)
}
}
emit dataChanged(index(row), index(row));
checkAllAccountsReady();
if (allAccountTried()) {
emit finished();
}
checkAllAccountsReady();
session->deleteLater();
});
session->setAccount(m_accountList.at(row));
Expand Down Expand Up @@ -554,7 +555,9 @@ void AccountListModel::getProfile(int row)
emit updatedAccount(row, m_accountList[row].uuid);
emit dataChanged(index(row), index(row));

getRawProfile(row);
qDebug() << "Update pinned post" << detail.pinnedPost.uri;
PinnedPostCache::getInstance()->update(m_accountList.at(row).did,
detail.pinnedPost.uri);
} else {
emit errorOccured(profile->errorCode(), profile->errorMessage());
}
Expand All @@ -564,29 +567,6 @@ void AccountListModel::getProfile(int row)
});
}

void AccountListModel::getRawProfile(int row)
{
if (row < 0 || row >= m_accountList.count())
return;

ComAtprotoRepoGetRecordEx *record = new ComAtprotoRepoGetRecordEx(this);
connect(record, &ComAtprotoRepoGetRecordEx::finished, this, [=](bool success) {
if (success) {
AtProtocolType::AppBskyActorProfile::Main profile =
AtProtocolType::LexiconsTypeUnknown::fromQVariant<
AtProtocolType::AppBskyActorProfile::Main>(record->value());
qDebug() << "Update pinned post" << profile.pinnedPost;
PinnedPostCache::getInstance()->update(m_accountList.at(row).did, profile.pinnedPost);

} else {
emit errorOccured(record->errorCode(), record->errorMessage());
}
record->deleteLater();
});
record->setAccount(m_accountList.at(row));
record->profile(m_accountList.at(row).did);
}

void AccountListModel::getServiceEndpoint(const QString &did, const QString &service,
std::function<void(const QString &)> callback)
{
Expand Down
1 change: 0 additions & 1 deletion app/qtquick/account/accountlistmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ class AccountListModel : public QAbstractListModel
void createSession(int row);
void refreshSession(int row, bool initial = false);
void getProfile(int row);
void getRawProfile(int row);
void getServiceEndpoint(const QString &did, const QString &service,
std::function<void(const QString &service_endpoint)> callback);
bool allAccountTried() const;
Expand Down
7 changes: 5 additions & 2 deletions app/qtquick/operation/recordoperator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ void RecordOperator::updateProfile(const QString &avatar_url, const QString &ban
old_profile->profile(m_account.did);
}

void RecordOperator::updatePostPinning(const QString &post_uri)
void RecordOperator::updatePostPinning(const QString &post_uri, const QString &post_cid)
{
if (running())
return;
Expand All @@ -816,9 +816,12 @@ void RecordOperator::updatePostPinning(const QString &post_uri)
setRunning(false);
new_profile->deleteLater();
});
ComAtprotoRepoStrongRef::Main pinned_post;
pinned_post.uri = post_uri;
pinned_post.cid = post_cid;
new_profile->setAccount(m_account);
new_profile->profile(old_record.avatar, old_record.banner, old_record.description,
old_record.displayName, post_uri, old_cid);
old_record.displayName, pinned_post, old_cid);
} else {
setProgressMessage(QString());
emit errorOccured(old_profile->errorCode(), old_profile->errorMessage());
Expand Down
2 changes: 1 addition & 1 deletion app/qtquick/operation/recordoperator.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class RecordOperator : public QObject

Q_INVOKABLE void updateProfile(const QString &avatar_url, const QString &banner_url,
const QString &description, const QString &display_name);
Q_INVOKABLE void updatePostPinning(const QString &post_uri);
Q_INVOKABLE void updatePostPinning(const QString &post_uri, const QString &post_cid);
Q_INVOKABLE void updateList(const QString &uri, const QString &avatar_url,
const QString &description, const QString &name);
Q_INVOKABLE void updateThreadGate(const QString &uri, const QString &threadgate_uri,
Expand Down
53 changes: 20 additions & 33 deletions app/qtquick/profile/userprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ void UserProfile::getProfile(const QString &did)
}
setBelongingLists(
ListItemsCache::getInstance()->getListNames(m_account.did, detail.did));
setPinnedPost(detail.pinnedPost.uri);

if (detail.associated.chat.allowIncoming == "none") {
setAssociatedChatAllow(false);
Expand Down Expand Up @@ -507,39 +508,25 @@ void UserProfile::getRawProfile()
return;
}

getRawInformation(
did(),
[=](const QString &service_endpoint, const QString &registration_date,
const QList<HistoryItem> &handle_history) {
ComAtprotoRepoGetRecordEx *record = new ComAtprotoRepoGetRecordEx(this);
connect(record, &ComAtprotoRepoGetRecordEx::finished, this, [=](bool success) {
if (success) {
AtProtocolType::AppBskyActorProfile::Main profile =
AtProtocolType::LexiconsTypeUnknown::fromQVariant<
AtProtocolType::AppBskyActorProfile::Main>(record->value());
setPinnedPost(profile.pinnedPost);
}
setRunning(false);
record->deleteLater();
});
record->setAccount(m_account);
if (!service_endpoint.isEmpty()) {
record->setService(service_endpoint);
setServiceEndpoint(service_endpoint);
} else {
// プロフィールを参照されるユーザーのサービスが参照する側と同じとは限らない(bsky.socialだったとしても)
setServiceEndpoint(QString());
}
setRegistrationDate(registration_date);
QStringList history;
for (const auto &item : handle_history) {
history.append(item.date);
history.append(item.handle);
history.append(item.endpoint);
}
setHandleHistory(history);
record->profile(did());
});
getRawInformation(did(),
[=](const QString &service_endpoint, const QString &registration_date,
const QList<HistoryItem> &handle_history) {
if (!service_endpoint.isEmpty()) {
setServiceEndpoint(service_endpoint);
} else {
// プロフィールを参照されるユーザーのサービスが参照する側と同じとは限らない(bsky.socialだったとしても)
setServiceEndpoint(QString());
}
setRegistrationDate(registration_date);
QStringList history;
for (const auto &item : handle_history) {
history.append(item.date);
history.append(item.handle);
history.append(item.endpoint);
}
setHandleHistory(history);
setRunning(false);
});
}

QString UserProfile::labelsTitle(const QString &label, const bool for_image,
Expand Down
4 changes: 2 additions & 2 deletions app/qtquick/timeline/authorfeedlistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bool AuthorFeedListModel::getLatest()
}
timeline->setAccount(account());
timeline->setLabelers(labelerDids());
timeline->getAuthorFeed(authorDid(), -1, QString(), filter_type);
timeline->getAuthorFeed(authorDid(), -1, QString(), filter_type, false);
});
return true;
}
Expand Down Expand Up @@ -78,7 +78,7 @@ bool AuthorFeedListModel::getNext()
}
timeline->setAccount(account());
timeline->setLabelers(labelerDids());
timeline->getAuthorFeed(authorDid(), -1, m_cursor, filter_type);
timeline->getAuthorFeed(authorDid(), -1, m_cursor, filter_type, false);
});
return true;
}
Expand Down
6 changes: 5 additions & 1 deletion app/qtquick/timeline/timelinelistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ QVariant TimelineListModel::item(int row, TimelineListModelRoles role) const
else if (role == PinnedRole)
return isPinnedPost(current.post.cid) && row == 0;
else if (role == PinnedByMeRole)
// return current.post.viewer.pinned;
return PinnedPostCache::getInstance()->pinned(account().did, current.post.uri);
else if (role == ThreadMutedRole)
return current.post.viewer.threadMuted;
Expand Down Expand Up @@ -385,6 +386,7 @@ void TimelineListModel::update(int row, TimelineListModelRoles role, const QVari
QVector<int>() << role << IsLikedRole << LikeCountRole);
} else if (role == PinnedByMeRole) {
qDebug() << "update Pinned by me:" << value.toString();
current.post.viewer.pinned = value.toBool();
emit dataChanged(index(row), index(row), QVector<int>() << role << PinnedRole);
} else if (role == ThreadMutedRole) {
bool muted = value.toBool();
Expand Down Expand Up @@ -610,8 +612,10 @@ bool TimelineListModel::pin(int row)

const AppBskyFeedDefs::FeedViewPost &current = m_viewPostHash.value(m_cidList.at(row));
QString pin_uri;
QString pin_cid;
if (!item(row, PinnedByMeRole).toBool()) {
pin_uri = current.post.uri;
pin_cid = current.post.cid;
}

if (runningPostPinning(row))
Expand All @@ -638,7 +642,7 @@ bool TimelineListModel::pin(int row)
});
ope->setAccount(account().service, account().did, account().handle, account().email,
account().accessJwt, account().refreshJwt);
ope->updatePostPinning(pin_uri);
ope->updatePostPinning(pin_uri, pin_cid);

return true;
}
Expand Down
6 changes: 5 additions & 1 deletion lib/atprotocol/app/bsky/feed/appbskyfeedgetauthorfeed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ AppBskyFeedGetAuthorFeed::AppBskyFeedGetAuthorFeed(QObject *parent)
}

void AppBskyFeedGetAuthorFeed::getAuthorFeed(const QString &actor, const int limit,
const QString &cursor, const QString &filter)
const QString &cursor, const QString &filter,
const bool includePins)
{
QUrlQuery url_query;
if (!actor.isEmpty()) {
Expand All @@ -25,6 +26,9 @@ void AppBskyFeedGetAuthorFeed::getAuthorFeed(const QString &actor, const int lim
if (!filter.isEmpty()) {
url_query.addQueryItem(QStringLiteral("filter"), filter);
}
if (includePins) {
url_query.addQueryItem(QStringLiteral("includePins"), "true");
}

get(QStringLiteral("xrpc/app.bsky.feed.getAuthorFeed"), url_query);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/atprotocol/app/bsky/feed/appbskyfeedgetauthorfeed.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AppBskyFeedGetAuthorFeed : public AppBskyFeedGetTimeline
explicit AppBskyFeedGetAuthorFeed(QObject *parent = nullptr);

void getAuthorFeed(const QString &actor, const int limit, const QString &cursor,
const QString &filter);
const QString &filter, const bool includePins);
};

}
Expand Down
34 changes: 23 additions & 11 deletions lib/atprotocol/lexicons.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ struct Relationship
};
}

// com.atproto.repo.strongRef
namespace ComAtprotoRepoStrongRef {
struct Main
{
QString uri; // at-uri
QString cid; // cid
};
// A URI with a content-hash fingerprint.
}

// app.bsky.actor.defs
namespace AppBskyActorDefs {
struct ProfileAssociatedChat
Expand Down Expand Up @@ -250,6 +260,7 @@ struct ProfileViewDetailed
QString createdAt; // datetime
ViewerState viewer;
QList<ComAtprotoLabelDefs::Label> labels;
ComAtprotoRepoStrongRef::Main pinnedPost;
};
struct AdultContentPref
{
Expand Down Expand Up @@ -370,16 +381,6 @@ struct Preferences
};
}

// com.atproto.repo.strongRef
namespace ComAtprotoRepoStrongRef {
struct Main
{
QString uri; // at-uri
QString cid; // cid
};
// A URI with a content-hash fingerprint.
}

// app.bsky.actor.profile
namespace AppBskyActorProfile {
enum class MainLabelsType : int {
Expand All @@ -399,8 +400,8 @@ struct Main
// application, on the overall account.
// union end : labels
ComAtprotoRepoStrongRef::Main joinedViaStarterPack;
ComAtprotoRepoStrongRef::Main pinnedPost;
QString createdAt; // datetime
QString pinnedPost; // at-uri , (Unofficial field)
};
}

Expand Down Expand Up @@ -573,6 +574,7 @@ namespace AppBskyFeedDefs {
enum class SkeletonFeedPostReasonType : int {
none,
reason_SkeletonReasonRepost,
reason_SkeletonReasonPin,
};
enum class ThreadViewPostParentType : int {
none,
Expand All @@ -589,6 +591,7 @@ enum class ThreadViewPostRepliesType : int {
enum class FeedViewPostReasonType : int {
none,
reason_ReasonRepost,
reason_ReasonPin,
};
enum class ReplyRefRootType : int {
none,
Expand Down Expand Up @@ -642,6 +645,7 @@ struct ViewerState
bool threadMuted = false;
bool replyDisabled = false;
bool embeddingDisabled = false;
bool pinned = false;
};
struct ThreadgateView
{
Expand Down Expand Up @@ -705,13 +709,17 @@ struct ReasonRepost
AppBskyActorDefs::ProfileViewBasic by;
QString indexedAt; // datetime
};
struct ReasonPin
{
};
struct FeedViewPost
{
PostView post;
ReplyRef reply;
// union start : reason
FeedViewPostReasonType reason_type = FeedViewPostReasonType::none;
ReasonRepost reason_ReasonRepost;
ReasonPin reason_ReasonPin;
// union end : reason
QString feedContext; // Context provided by feed generator that may be passed back alongside
// interactions.
Expand All @@ -736,12 +744,16 @@ struct SkeletonReasonRepost
{
QString repost; // at-uri
};
struct SkeletonReasonPin
{
};
struct SkeletonFeedPost
{
QString post; // at-uri
// union start : reason
SkeletonFeedPostReasonType reason_type = SkeletonFeedPostReasonType::none;
SkeletonReasonRepost reason_SkeletonReasonRepost;
SkeletonReasonPin reason_SkeletonReasonPin;
// union end : reason
QString feedContext; // Context that will be passed through to client and may be passed to feed
// generator back alongside interactions.
Expand Down
Loading

0 comments on commit 428b2e9

Please sign in to comment.