2020-06-29 21:43:45 +00:00
|
|
|
public class Tootle.API.Account : Entity, Widgetizable {
|
2020-05-29 12:19:35 +00:00
|
|
|
|
2020-06-20 10:04:58 +00:00
|
|
|
public string id { get; set; }
|
2020-05-29 12:19:35 +00:00
|
|
|
public string username { get; set; }
|
|
|
|
public string acct { get; set; }
|
|
|
|
public string? _display_name = null;
|
|
|
|
public string display_name {
|
|
|
|
set {
|
|
|
|
this._display_name = value;
|
|
|
|
}
|
|
|
|
get {
|
|
|
|
return (_display_name == null || _display_name == "") ? username : _display_name;
|
|
|
|
}
|
2018-04-14 17:18:42 +00:00
|
|
|
}
|
2020-05-29 12:19:35 +00:00
|
|
|
public string note { get; set; }
|
|
|
|
public string header { get; set; }
|
|
|
|
public string avatar { get; set; }
|
|
|
|
public string url { get; set; }
|
|
|
|
public string created_at { get; set; }
|
|
|
|
public int64 followers_count { get; set; }
|
|
|
|
public int64 following_count { get; set; }
|
2020-06-20 10:04:58 +00:00
|
|
|
public int64 statuses_count { get; set; }
|
2020-05-29 12:19:35 +00:00
|
|
|
public Relationship? rs { get; set; default = null; }
|
2020-06-29 21:43:45 +00:00
|
|
|
public Gee.ArrayList<API.AccountField>? fields { get; set; default = null; }
|
|
|
|
|
|
|
|
public string handle {
|
|
|
|
owned get {
|
|
|
|
return "@" + acct;
|
|
|
|
}
|
|
|
|
}
|
2020-05-29 12:19:35 +00:00
|
|
|
|
2020-06-20 10:04:58 +00:00
|
|
|
public static Account from (Json.Node node) throws Error {
|
|
|
|
return Entity.from_json (typeof (API.Account), node) as API.Account;
|
|
|
|
}
|
2019-03-11 14:14:37 +00:00
|
|
|
|
2020-05-29 12:19:35 +00:00
|
|
|
public bool is_self () {
|
|
|
|
return id == accounts.active.id;
|
2018-05-01 13:16:07 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 21:43:45 +00:00
|
|
|
public override Gtk.Widget to_widget () {
|
|
|
|
var status = new API.Status.from_account (this);
|
2020-07-05 07:42:00 +00:00
|
|
|
return new Widgets.Status (status);
|
2020-06-29 21:43:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 12:19:35 +00:00
|
|
|
public Request get_relationship () {
|
|
|
|
return new Request.GET ("/api/v1/accounts/relationships")
|
|
|
|
.with_account (accounts.active)
|
|
|
|
.with_param ("id", id.to_string ())
|
|
|
|
.then_parse_array (node => {
|
2020-06-20 10:04:58 +00:00
|
|
|
rs = API.Relationship.from (node);
|
2020-05-29 12:19:35 +00:00
|
|
|
})
|
|
|
|
.on_error (network.on_error)
|
|
|
|
.exec ();
|
2018-05-01 13:16:07 +00:00
|
|
|
}
|
2019-03-11 14:14:37 +00:00
|
|
|
|
2020-05-29 12:19:35 +00:00
|
|
|
public Request set_following (bool state = true) {
|
|
|
|
var action = state ? "follow" : "unfollow";
|
|
|
|
return new Request.POST (@"/api/v1/accounts/$id/$action")
|
|
|
|
.with_account (accounts.active)
|
|
|
|
.then ((sess, msg) => {
|
2020-06-20 10:04:58 +00:00
|
|
|
var node = network.parse_node (msg);
|
|
|
|
rs = API.Relationship.from (node);
|
2020-05-29 12:19:35 +00:00
|
|
|
})
|
|
|
|
.on_error (network.on_error)
|
|
|
|
.exec ();
|
2018-05-01 13:16:07 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 12:19:35 +00:00
|
|
|
public Request set_muted (bool state = true) {
|
|
|
|
var action = state ? "mute" : "unmute";
|
|
|
|
return new Request.POST (@"/api/v1/accounts/$id/$action")
|
|
|
|
.with_account (accounts.active)
|
|
|
|
.then ((sess, msg) => {
|
2020-06-20 10:04:58 +00:00
|
|
|
var node = network.parse_node (msg);
|
|
|
|
rs = API.Relationship.from (node);
|
2020-05-29 12:19:35 +00:00
|
|
|
})
|
|
|
|
.on_error (network.on_error)
|
|
|
|
.exec ();
|
2018-05-01 13:16:07 +00:00
|
|
|
}
|
2019-03-11 14:14:37 +00:00
|
|
|
|
2020-05-29 12:19:35 +00:00
|
|
|
public Request set_blocked (bool state = true) {
|
|
|
|
var action = state ? "block" : "unblock";
|
|
|
|
return new Request.POST (@"/api/v1/accounts/$id/$action")
|
|
|
|
.with_account (accounts.active)
|
|
|
|
.then ((sess, msg) => {
|
2020-06-20 10:04:58 +00:00
|
|
|
var node = network.parse_node (msg);
|
|
|
|
rs = API.Relationship.from (node);
|
2020-05-29 12:19:35 +00:00
|
|
|
})
|
|
|
|
.on_error (network.on_error)
|
|
|
|
.exec ();
|
2018-05-01 13:16:07 +00:00
|
|
|
}
|
2018-04-14 12:09:06 +00:00
|
|
|
|
|
|
|
}
|