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; }
|
|
|
|
|
2020-06-29 21:43:45 +00:00
|
|
|
ListBox profile_list;
|
|
|
|
|
|
|
|
Label relationship;
|
|
|
|
Widgets.TimelineFilter filter;
|
|
|
|
|
2020-07-01 10:26:32 +00:00
|
|
|
Button rs_button;
|
|
|
|
Label rs_button_label;
|
|
|
|
|
2020-07-10 14:22:38 +00:00
|
|
|
weak ListBoxRow note_row;
|
|
|
|
|
2020-06-29 21:43:45 +00:00
|
|
|
public bool exclude_replies { get; set; default = true; }
|
|
|
|
public bool only_media { get; set; default = false; }
|
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);
|
|
|
|
|
2020-06-29 21:43:45 +00:00
|
|
|
filter = new Widgets.TimelineFilter.with_profile (this);
|
|
|
|
|
2020-05-29 12:19:35 +00:00
|
|
|
var builder = new Builder.from_resource (@"$(Build.RESOURCES)ui/views/profile_header.ui");
|
2020-06-29 21:43:45 +00:00
|
|
|
profile_list = builder.get_object ("profile_list") as ListBox;
|
|
|
|
|
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;
|
|
|
|
|
2020-06-29 21:43:45 +00:00
|
|
|
profile.bind_property ("display-name", filter.title, "label", BindingFlags.SYNC_CREATE);
|
2020-05-29 12:19:35 +00:00
|
|
|
|
|
|
|
var handle = builder.get_object ("handle") as Widgets.RichLabel;
|
2020-06-29 21:43:45 +00:00
|
|
|
profile.bind_property ("acct", handle, "text", BindingFlags.SYNC_CREATE, (b, src, ref target) => {
|
|
|
|
var text = "@" + (string) src;
|
|
|
|
target.set_string (@"<span size=\"x-large\" weight=\"bold\">$text</span>");
|
2020-05-29 12:19:35 +00:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
2020-07-10 14:22:38 +00:00
|
|
|
note_row = builder.get_object ("note_row") as ListBoxRow;
|
2020-05-29 12:19:35 +00:00
|
|
|
var note = builder.get_object ("note") as Widgets.RichLabel;
|
2020-06-29 21:43:45 +00:00
|
|
|
profile.bind_property ("note", note, "text", BindingFlags.SYNC_CREATE, (b, src, ref target) => {
|
2020-07-01 10:26:32 +00:00
|
|
|
var text = Html.simplify ((string) src);
|
|
|
|
target.set_string (text);
|
|
|
|
note_row.visible = text != "";
|
2020-05-29 12:19:35 +00:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
relationship = builder.get_object ("relationship") as Label;
|
|
|
|
|
2020-06-29 21:43:45 +00:00
|
|
|
// posts_label = builder.get_object ("posts_label") as Label;
|
|
|
|
// profile.bind_property ("statuses_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;
|
|
|
|
// });
|
|
|
|
|
2020-07-01 10:26:32 +00:00
|
|
|
rs_button = builder.get_object ("rs_button") as Button;
|
|
|
|
rs_button.clicked.connect (on_rs_button_clicked);
|
|
|
|
rs_button_label = builder.get_object ("rs_button_label") as Label;
|
|
|
|
|
2020-06-29 21:43:45 +00:00
|
|
|
rebuild_fields ();
|
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-06-29 21:43:45 +00:00
|
|
|
Object (
|
|
|
|
profile: acc,
|
2020-07-28 18:30:45 +00:00
|
|
|
label: acc.acct,
|
2020-06-29 21:43:45 +00:00
|
|
|
url: @"/api/v1/accounts/$(acc.id)/statuses"
|
|
|
|
);
|
2020-05-29 12:19:35 +00:00
|
|
|
profile.get_relationship ();
|
2018-04-30 17:56:02 +00:00
|
|
|
}
|
2020-07-10 14:22:38 +00:00
|
|
|
~Profile () {
|
|
|
|
filter.destroy ();
|
|
|
|
}
|
2019-03-07 16:16:52 +00:00
|
|
|
|
2020-06-29 21:43:45 +00:00
|
|
|
public override void on_shown () {
|
|
|
|
window.header.custom_title = filter;
|
2020-07-12 09:48:29 +00:00
|
|
|
filter.valign = Align.FILL;
|
2020-07-01 10:26:32 +00:00
|
|
|
window.set_header_controls (rs_button);
|
2020-06-29 21:43:45 +00:00
|
|
|
}
|
|
|
|
public override void on_hidden () {
|
|
|
|
window.header.custom_title = null;
|
2020-07-01 10:26:32 +00:00
|
|
|
window.reset_header_controls ();
|
2020-06-29 21:43:45 +00:00
|
|
|
}
|
|
|
|
|
2020-07-01 10:26:32 +00:00
|
|
|
void on_rs_button_clicked () {
|
|
|
|
rs_button.sensitive = false;
|
2020-05-29 12:19:35 +00:00
|
|
|
profile.set_following (!profile.rs.following);
|
|
|
|
}
|
|
|
|
|
2020-06-29 21:43:45 +00:00
|
|
|
void on_rs_updated () {
|
2020-05-29 12:19:35 +00:00
|
|
|
var rs = profile.rs;
|
|
|
|
var label = "";
|
2020-07-01 10:26:32 +00:00
|
|
|
if (rs_button.sensitive = rs != null) {
|
2020-05-29 12:19:35 +00:00
|
|
|
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");
|
|
|
|
|
2020-07-01 10:26:32 +00:00
|
|
|
foreach (Widget w in new Widget[] { rs_button }) {
|
2020-05-29 12:19:35 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-07-01 10:26:32 +00:00
|
|
|
rs_button_label.label = rs.following ? _("Unfollow") : _("Follow");
|
2020-05-29 12:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
relationship.label = label;
|
2020-06-29 21:43:45 +00:00
|
|
|
relationship.visible = label != "";
|
2020-05-29 12:19:35 +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) {
|
2020-06-20 10:04:58 +00:00
|
|
|
if (page_next == null) {
|
2020-06-29 21:43:45 +00:00
|
|
|
if (exclude_replies)
|
|
|
|
req.with_param ("exclude_replies", "true");
|
|
|
|
if (only_media)
|
|
|
|
req.with_param ("only_media", "true");
|
2020-06-20 10:04:58 +00:00
|
|
|
return base.append_params (req);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return req;
|
2020-05-29 12:19:35 +00:00
|
|
|
}
|
|
|
|
|
2020-08-01 15:40:56 +00:00
|
|
|
public static void open_from_id (string id) {
|
|
|
|
var msg = new Soup.Message ("GET", @"$(accounts.active.instance)/api/v1/accounts/$id");
|
2018-06-02 08:37:28 +00:00
|
|
|
network.queue (msg, (sess, mess) => {
|
2020-06-20 10:04:58 +00:00
|
|
|
var node = network.parse_node (mess);
|
|
|
|
var acc = API.Account.from (node);
|
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
|
|
|
|
2020-06-29 21:43:45 +00:00
|
|
|
[GtkTemplate (ui = "/com/github/bleakgrey/tootle/ui/widgets/profile_field_row.ui")]
|
|
|
|
protected class Field : ListBoxRow {
|
|
|
|
|
|
|
|
[GtkChild]
|
|
|
|
Widgets.RichLabel name_label;
|
|
|
|
[GtkChild]
|
|
|
|
Widgets.RichLabel value_label;
|
|
|
|
|
|
|
|
public Field (API.AccountField field) {
|
|
|
|
name_label.text = field.name;
|
|
|
|
value_label.text = field.val;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void rebuild_fields () {
|
|
|
|
if (profile.fields != null) {
|
|
|
|
foreach (Entity e in profile.fields) {
|
|
|
|
var w = new Field (e as API.AccountField);
|
2020-07-01 10:26:32 +00:00
|
|
|
profile_list.insert (w, -1);
|
2020-06-29 21:43:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-25 13:16:57 +00:00
|
|
|
}
|