2018-04-25 13:16:57 +00:00
|
|
|
using Gtk;
|
|
|
|
|
2019-03-11 14:14:37 +00:00
|
|
|
public class Tootle.Views.Profile : Views.Timeline {
|
2019-03-07 16:16:52 +00:00
|
|
|
|
2020-05-29 12:19:35 +00:00
|
|
|
public API.Account profile { get; construct set; }
|
|
|
|
|
|
|
|
protected RadioButton filter_all;
|
|
|
|
protected RadioButton filter_replies;
|
|
|
|
protected RadioButton filter_media;
|
2019-03-07 16:16:52 +00:00
|
|
|
|
2018-10-24 10:50:40 +00:00
|
|
|
protected Label relationship;
|
|
|
|
protected Box actions;
|
2020-05-29 12:19:35 +00:00
|
|
|
protected Button follow_button;
|
|
|
|
protected MenuButton options_button;
|
2019-03-07 16:16:52 +00:00
|
|
|
|
2020-05-29 12:19:35 +00:00
|
|
|
protected Label posts_label;
|
|
|
|
protected Label following_label;
|
|
|
|
protected Label followers_label;
|
|
|
|
protected RadioButton posts_tab;
|
|
|
|
protected RadioButton following_tab;
|
|
|
|
protected RadioButton followers_tab;
|
2019-03-07 16:16:52 +00:00
|
|
|
|
2018-10-24 09:29:36 +00:00
|
|
|
construct {
|
2020-05-29 12:19:35 +00:00
|
|
|
profile.notify["rs"].connect (on_rs_updated);
|
|
|
|
|
|
|
|
var builder = new Builder.from_resource (@"$(Build.RESOURCES)ui/views/profile_header.ui");
|
2020-06-02 09:35:29 +00:00
|
|
|
var hdr = builder.get_object ("grid") as Grid;
|
|
|
|
column_view.pack_start (hdr, false, false, 0);
|
|
|
|
column_view.reorder_child (hdr, 0);
|
2020-05-29 12:19:35 +00:00
|
|
|
|
|
|
|
var avatar = builder.get_object ("avatar") as Widgets.Avatar;
|
|
|
|
avatar.url = profile.avatar;
|
|
|
|
|
|
|
|
var name = builder.get_object ("name") as Widgets.RichLabel;
|
|
|
|
profile.bind_property ("display-name", name, "label", BindingFlags.SYNC_CREATE, (b, src, ref target) => {
|
|
|
|
var label = (string) src;
|
|
|
|
target.set_string (@"<span size='x-large' weight='bold'>$label</span>");
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
var handle = builder.get_object ("handle") as Widgets.RichLabel;
|
|
|
|
profile.bind_property ("acct", handle, "label", BindingFlags.SYNC_CREATE, (b, src, ref target) => {
|
|
|
|
target.set_string ("@" + (string) src);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
var note = builder.get_object ("note") as Widgets.RichLabel;
|
|
|
|
profile.bind_property ("note", note, "label", BindingFlags.SYNC_CREATE, (b, src, ref target) => {
|
|
|
|
target.set_string (Html.simplify ((string) src));
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
actions = builder.get_object ("actions") as Box;
|
|
|
|
follow_button = builder.get_object ("follow_button") as Button;
|
|
|
|
follow_button.clicked.connect (on_follow_button_clicked);
|
|
|
|
options_button = builder.get_object ("options_button") as MenuButton;
|
|
|
|
relationship = builder.get_object ("relationship") as Label;
|
|
|
|
|
|
|
|
posts_label = builder.get_object ("posts_label") as Label;
|
|
|
|
profile.bind_property ("posts_count", posts_label, "label", BindingFlags.SYNC_CREATE, (b, src, ref target) => {
|
|
|
|
var val = (int64) src;
|
|
|
|
target.set_string (_("%s Posts").printf (@"<b>$val</b>"));
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
following_label = builder.get_object ("following_label") as Label;
|
|
|
|
profile.bind_property ("following_count", following_label, "label", BindingFlags.SYNC_CREATE, (b, src, ref target) => {
|
|
|
|
var val = (int64) src;
|
|
|
|
target.set_string (_("%s Follows").printf (@"<b>$val</b>"));
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
followers_label = builder.get_object ("followers_label") as Label;
|
|
|
|
profile.bind_property ("followers_count", followers_label, "label", BindingFlags.SYNC_CREATE, (b, src, ref target) => {
|
|
|
|
var val = (int64) src;
|
|
|
|
target.set_string (_("%s Followers").printf (@"<b>$val</b>"));
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
filter_all = builder.get_object ("filter_all") as RadioButton;
|
|
|
|
filter_all.toggled.connect (on_refresh);
|
|
|
|
filter_replies = builder.get_object ("filter_replies") as RadioButton;
|
|
|
|
filter_replies.toggled.connect (on_refresh);
|
|
|
|
filter_media = builder.get_object ("filter_media") as RadioButton;
|
|
|
|
filter_media.toggled.connect (on_refresh);
|
|
|
|
|
|
|
|
posts_tab = builder.get_object ("posts_tab") as RadioButton;
|
|
|
|
posts_tab.toggled.connect (() => {
|
|
|
|
if (posts_tab.active) on_refresh ();
|
|
|
|
});
|
|
|
|
following_tab = builder.get_object ("following_tab") as RadioButton;
|
|
|
|
following_tab.toggled.connect (() => {
|
|
|
|
if (following_tab.active) on_refresh ();
|
|
|
|
});
|
|
|
|
followers_tab = builder.get_object ("followers_tab") as RadioButton;
|
|
|
|
followers_tab.toggled.connect (() => {
|
|
|
|
if (followers_tab.active) on_refresh ();
|
|
|
|
});
|
2018-04-25 13:16:57 +00:00
|
|
|
}
|
2019-03-07 16:16:52 +00:00
|
|
|
|
2019-03-11 14:14:37 +00:00
|
|
|
public Profile (API.Account acc) {
|
2020-05-29 12:19:35 +00:00
|
|
|
Object (profile: acc);
|
|
|
|
profile.get_relationship ();
|
2018-04-30 17:56:02 +00:00
|
|
|
}
|
2019-03-07 16:16:52 +00:00
|
|
|
|
2020-05-29 12:19:35 +00:00
|
|
|
protected void on_follow_button_clicked () {
|
|
|
|
actions.sensitive = false;
|
|
|
|
profile.set_following (!profile.rs.following);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void on_rs_updated () {
|
|
|
|
var rs = profile.rs;
|
|
|
|
var label = "";
|
|
|
|
if (actions.sensitive = rs != null) {
|
|
|
|
if (rs.requested)
|
|
|
|
label = _("Sent follow request");
|
|
|
|
else if (rs.followed_by && rs.following)
|
|
|
|
label = _("Mutually follows you");
|
|
|
|
else if (rs.followed_by)
|
|
|
|
label = _("Follows you");
|
|
|
|
|
|
|
|
foreach (Widget w in new Widget[] { follow_button, options_button }) {
|
|
|
|
var ctx = w.get_style_context ();
|
|
|
|
ctx.remove_class (STYLE_CLASS_SUGGESTED_ACTION);
|
|
|
|
ctx.remove_class (STYLE_CLASS_DESTRUCTIVE_ACTION);
|
|
|
|
ctx.add_class (rs.following ? STYLE_CLASS_DESTRUCTIVE_ACTION : STYLE_CLASS_SUGGESTED_ACTION);
|
|
|
|
}
|
|
|
|
|
|
|
|
var label2 = "";
|
|
|
|
if (rs.followed_by && !rs.following)
|
|
|
|
label2 = _("Follow back");
|
|
|
|
else if (rs.following)
|
|
|
|
label2 = _("Unfollow");
|
|
|
|
else
|
|
|
|
label2 = _("Follow");
|
|
|
|
|
|
|
|
follow_button.label = label2;
|
|
|
|
}
|
|
|
|
|
|
|
|
relationship.label = label;
|
|
|
|
}
|
2019-03-07 16:16:52 +00:00
|
|
|
|
2020-06-03 12:41:21 +00:00
|
|
|
public override string get_req_url () {
|
2018-05-19 12:21:03 +00:00
|
|
|
if (page_next != null)
|
|
|
|
return page_next;
|
2019-03-07 16:16:52 +00:00
|
|
|
|
2020-05-29 12:19:35 +00:00
|
|
|
if (following_tab.active)
|
|
|
|
return @"/api/v1/accounts/$(profile.id)/following";
|
|
|
|
else if (followers_tab.active)
|
|
|
|
return @"/api/v1/accounts/$(profile.id)/followers";
|
|
|
|
else
|
|
|
|
return @"/api/v1/accounts/$(profile.id)/statuses";
|
2018-04-26 14:05:03 +00:00
|
|
|
}
|
2019-03-07 16:16:52 +00:00
|
|
|
|
2020-05-29 12:19:35 +00:00
|
|
|
public override Request append_params (Request req) {
|
|
|
|
req.with_param ("exclude_replies", (!filter_replies.active).to_string ());
|
|
|
|
req.with_param ("only_media", filter_media.active.to_string ());
|
|
|
|
return base.append_params (req);
|
|
|
|
}
|
|
|
|
|
2020-05-30 16:24:11 +00:00
|
|
|
public override GLib.Object? to_entity (Json.Object? json) {
|
|
|
|
if (posts_tab.active)
|
|
|
|
return new API.Status (json);
|
|
|
|
else {
|
|
|
|
var account = new API.Account (json);
|
|
|
|
return new API.Status.from_account (account);
|
|
|
|
}
|
2018-05-09 15:59:58 +00:00
|
|
|
}
|
2019-03-07 16:16:52 +00:00
|
|
|
|
2018-04-28 16:27:10 +00:00
|
|
|
public static void open_from_id (int64 id){
|
2020-05-29 12:19:35 +00:00
|
|
|
var url = "%s/api/v1/accounts/%lld".printf (accounts.active.instance, id);
|
2018-10-27 08:29:25 +00:00
|
|
|
var msg = new Soup.Message ("GET", url);
|
2018-05-01 13:16:07 +00:00
|
|
|
msg.priority = Soup.MessagePriority.HIGH;
|
2018-06-02 08:37:28 +00:00
|
|
|
network.queue (msg, (sess, mess) => {
|
2019-03-17 10:26:55 +00:00
|
|
|
var root = network.parse (mess);
|
2020-05-29 12:19:35 +00:00
|
|
|
var acc = new API.Account (root);
|
2019-03-17 10:26:55 +00:00
|
|
|
window.open_view (new Views.Profile (acc));
|
|
|
|
}, (status, reason) => {
|
|
|
|
network.on_error (status, reason);
|
2018-04-28 16:41:35 +00:00
|
|
|
});
|
|
|
|
}
|
2019-03-07 16:16:52 +00:00
|
|
|
|
2018-04-25 13:16:57 +00:00
|
|
|
}
|