display user bio in profile window

This commit is contained in:
ouwou 2021-05-26 02:50:22 -04:00
parent 5d8209cf10
commit 484e21e693
5 changed files with 51 additions and 5 deletions

View File

@ -58,6 +58,8 @@ void from_json(const nlohmann::json &j, UserData &m) {
JS_O("mobile", m.IsMobile);
JS_ON("nsfw_allowed", m.IsNSFWAllowed);
JS_ON("phone", m.Phone);
JS_ON("bio", m.Bio);
JS_ON("banner", m.BannerHash);
}
void to_json(nlohmann::json &j, const UserData &m) {

View File

@ -52,6 +52,9 @@ struct UserData {
std::optional<bool> IsMobile;
std::optional<bool> IsNSFWAllowed; // null
std::optional<std::string> Phone; // null?
// for now (unserialized)
std::optional<std::string> BannerHash; // null
std::optional<std::string> Bio; // null
friend void from_json(const nlohmann::json &j, UserData &m);
friend void to_json(nlohmann::json &j, const UserData &m);

View File

@ -158,6 +158,25 @@ NotesContainer::type_signal_update_note NotesContainer::signal_update_note() {
return m_signal_update_note;
}
BioContainer::BioContainer()
: Gtk::Box(Gtk::ORIENTATION_VERTICAL) {
m_label.set_markup("<b>ABOUT ME</b>");
m_label.set_halign(Gtk::ALIGN_START);
m_bio.set_halign(Gtk::ALIGN_START);
m_bio.set_line_wrap(true);
m_bio.set_line_wrap_mode(Pango::WRAP_WORD_CHAR);
m_label.show();
m_bio.show();
add(m_label);
add(m_bio);
}
void BioContainer::SetBio(const std::string &bio) {
m_bio.set_text(bio);
}
ProfileUserInfoPane::ProfileUserInfoPane(Snowflake ID)
: Gtk::Box(Gtk::ORIENTATION_VERTICAL)
, UserID(ID) {
@ -194,12 +213,23 @@ ProfileUserInfoPane::ProfileUserInfoPane(Snowflake ID)
m_conns.set_halign(Gtk::ALIGN_START);
m_conns.set_hexpand(true);
m_created.show();
m_note.show();
m_conns.show();
add(m_created);
add(m_bio);
add(m_note);
add(m_conns);
show_all_children();
}
void ProfileUserInfoPane::SetConnections(const std::vector<ConnectionData> &connections) {
m_conns.SetConnections(connections);
void ProfileUserInfoPane::SetProfile(const UserProfileData &data) {
if (data.User.Bio.has_value() && *data.User.Bio != "") {
m_bio.SetBio(*data.User.Bio);
m_bio.show();
} else {
m_bio.hide();
}
m_conns.SetConnections(data.ConnectedAccounts);
}

View File

@ -39,16 +39,27 @@ public:
type_signal_update_note signal_update_note();
};
class BioContainer : public Gtk::Box {
public:
BioContainer();
void SetBio(const std::string &bio);
private:
Gtk::Label m_label;
Gtk::Label m_bio;
};
class ProfileUserInfoPane : public Gtk::Box {
public:
ProfileUserInfoPane(Snowflake ID);
void SetConnections(const std::vector<ConnectionData> &connections);
void SetProfile(const UserProfileData &data);
Snowflake UserID;
private:
Gtk::Label m_created;
BioContainer m_bio;
NotesContainer m_note;
ConnectionsContainer m_conns;
};

View File

@ -96,7 +96,7 @@ ProfileWindow::ProfileWindow(Snowflake user_id)
}
void ProfileWindow::OnFetchProfile(const UserProfileData &data) {
m_pane_info.SetConnections(data.ConnectedAccounts);
m_pane_info.SetProfile(data);
m_pane_guilds.SetMutualGuilds(data.MutualGuilds);
for (auto child : m_badges.get_children())