2018-05-05 15:38:01 +00:00
|
|
|
public class Tootle.Status {
|
2018-04-14 12:09:06 +00:00
|
|
|
|
2018-10-23 10:05:24 +00:00
|
|
|
public signal void updated ();
|
2018-05-01 13:53:46 +00:00
|
|
|
|
2018-04-21 09:21:03 +00:00
|
|
|
public Account account;
|
2018-04-14 12:09:06 +00:00
|
|
|
public int64 id;
|
|
|
|
public string uri;
|
|
|
|
public string url;
|
2018-04-23 16:43:29 +00:00
|
|
|
public string? spoiler_text;
|
2018-04-14 12:09:06 +00:00
|
|
|
public string content;
|
2018-10-24 10:50:40 +00:00
|
|
|
public int64 replies_count;
|
2018-04-14 12:09:06 +00:00
|
|
|
public int64 reblogs_count;
|
|
|
|
public int64 favourites_count;
|
2018-10-24 12:01:32 +00:00
|
|
|
public string created_at;
|
2018-05-22 13:18:39 +00:00
|
|
|
public bool reblogged = false;
|
|
|
|
public bool favorited = false;
|
|
|
|
public bool sensitive = false;
|
|
|
|
public bool muted = false;
|
2018-10-24 09:00:40 +00:00
|
|
|
public bool pinned = false;
|
2018-05-11 11:28:49 +00:00
|
|
|
public StatusVisibility visibility;
|
2018-04-21 09:21:03 +00:00
|
|
|
public Status? reblog;
|
2018-05-02 12:28:46 +00:00
|
|
|
public Mention[]? mentions;
|
2018-05-04 20:57:31 +00:00
|
|
|
public Attachment[]? attachments;
|
2018-04-14 12:09:06 +00:00
|
|
|
|
2018-10-23 10:05:24 +00:00
|
|
|
public Status (int64 _id) {
|
|
|
|
id = _id;
|
2018-04-14 12:09:06 +00:00
|
|
|
}
|
2018-04-29 10:58:45 +00:00
|
|
|
|
2018-10-23 10:05:24 +00:00
|
|
|
public Status get_formal () {
|
2018-04-29 10:58:45 +00:00
|
|
|
return reblog != null ? reblog : this;
|
|
|
|
}
|
2018-04-14 12:09:06 +00:00
|
|
|
|
2018-10-24 12:01:32 +00:00
|
|
|
public static Status parse (Json.Object obj) {
|
2018-04-14 12:09:06 +00:00
|
|
|
var id = int64.parse (obj.get_string_member ("id"));
|
|
|
|
var status = new Status (id);
|
|
|
|
|
2018-05-03 08:11:31 +00:00
|
|
|
status.account = Account.parse (obj.get_object_member ("account"));
|
2018-04-14 12:09:06 +00:00
|
|
|
status.uri = obj.get_string_member ("uri");
|
2018-05-02 12:00:43 +00:00
|
|
|
status.created_at = obj.get_string_member ("created_at");
|
2018-10-24 10:50:40 +00:00
|
|
|
status.replies_count = obj.get_int_member ("replies_count");
|
2018-04-14 12:09:06 +00:00
|
|
|
status.reblogs_count = obj.get_int_member ("reblogs_count");
|
|
|
|
status.favourites_count = obj.get_int_member ("favourites_count");
|
2018-05-30 19:49:16 +00:00
|
|
|
status.content = Html.simplify ( obj.get_string_member ("content"));
|
2018-05-04 20:57:31 +00:00
|
|
|
status.sensitive = obj.get_boolean_member ("sensitive");
|
2018-05-11 11:28:49 +00:00
|
|
|
status.visibility = StatusVisibility.from_string (obj.get_string_member ("visibility"));
|
2018-05-04 20:57:31 +00:00
|
|
|
|
2018-07-08 00:47:35 +00:00
|
|
|
if (obj.has_member ("url"))
|
|
|
|
status.url = obj.get_string_member ("url");
|
|
|
|
else
|
|
|
|
status.url = obj.get_string_member ("uri").replace ("/activity", "");
|
|
|
|
|
2018-05-04 20:57:31 +00:00
|
|
|
var spoiler = obj.get_string_member ("spoiler_text");
|
|
|
|
if (spoiler != "")
|
2018-05-30 19:49:16 +00:00
|
|
|
status.spoiler_text = Html.simplify (spoiler);
|
2018-05-04 20:57:31 +00:00
|
|
|
|
2018-05-22 13:18:39 +00:00
|
|
|
if (obj.has_member ("reblogged"))
|
2018-05-04 20:57:31 +00:00
|
|
|
status.reblogged = obj.get_boolean_member ("reblogged");
|
2018-05-22 13:18:39 +00:00
|
|
|
if (obj.has_member ("favourited"))
|
2018-05-04 20:57:31 +00:00
|
|
|
status.favorited = obj.get_boolean_member ("favourited");
|
2018-05-22 13:18:39 +00:00
|
|
|
if (obj.has_member ("muted"))
|
|
|
|
status.muted = obj.get_boolean_member ("muted");
|
2018-10-24 09:00:40 +00:00
|
|
|
if (obj.has_member ("pinned"))
|
|
|
|
status.pinned = obj.get_boolean_member ("pinned");
|
2018-05-04 20:57:31 +00:00
|
|
|
|
2018-05-22 13:18:39 +00:00
|
|
|
if (obj.has_member ("reblog") && obj.get_null_member("reblog") != true)
|
2018-05-04 20:57:31 +00:00
|
|
|
status.reblog = Status.parse (obj.get_object_member ("reblog"));
|
2018-04-28 16:27:10 +00:00
|
|
|
|
|
|
|
Mention[]? _mentions = {};
|
|
|
|
obj.get_array_member ("mentions").foreach_element ((array, i, node) => {
|
|
|
|
var object = node.get_object ();
|
|
|
|
if (object != null)
|
|
|
|
_mentions += Mention.parse (object);
|
|
|
|
});
|
|
|
|
if (_mentions.length > 0)
|
|
|
|
status.mentions = _mentions;
|
2018-05-04 20:57:31 +00:00
|
|
|
|
|
|
|
Attachment[]? _attachments = {};
|
|
|
|
obj.get_array_member ("media_attachments").foreach_element ((array, i, node) => {
|
|
|
|
var object = node.get_object ();
|
|
|
|
if (object != null)
|
|
|
|
_attachments += Attachment.parse (object);
|
|
|
|
});
|
|
|
|
if (_attachments.length > 0)
|
|
|
|
status.attachments = _attachments;
|
2018-04-14 12:09:06 +00:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
2018-05-01 13:53:46 +00:00
|
|
|
|
2018-10-30 15:57:37 +00:00
|
|
|
public Json.Node? serialize () {
|
|
|
|
var builder = new Json.Builder ();
|
|
|
|
builder.begin_object ();
|
|
|
|
builder.set_member_name ("id");
|
|
|
|
builder.add_string_value (id.to_string ());
|
|
|
|
builder.set_member_name ("uri");
|
|
|
|
builder.add_string_value (uri);
|
|
|
|
builder.set_member_name ("url");
|
|
|
|
builder.add_string_value (url);
|
|
|
|
builder.set_member_name ("content");
|
|
|
|
builder.add_string_value (content);
|
|
|
|
builder.set_member_name ("created_at");
|
|
|
|
builder.add_string_value (created_at);
|
|
|
|
builder.set_member_name ("visibility");
|
|
|
|
builder.add_string_value (visibility.to_string ());
|
|
|
|
builder.set_member_name ("sensitive");
|
|
|
|
builder.add_boolean_value (sensitive);
|
|
|
|
builder.set_member_name ("sensitive");
|
|
|
|
builder.add_boolean_value (sensitive);
|
|
|
|
builder.set_member_name ("replies_count");
|
|
|
|
builder.add_int_value (replies_count);
|
|
|
|
builder.set_member_name ("favourites_count");
|
|
|
|
builder.add_int_value (favourites_count);
|
|
|
|
builder.set_member_name ("reblogs_count");
|
|
|
|
builder.add_int_value (reblogs_count);
|
|
|
|
builder.set_member_name ("account");
|
|
|
|
builder.add_value (account.serialize ());
|
|
|
|
|
|
|
|
if (spoiler_text != null) {
|
|
|
|
builder.set_member_name ("spoiler_text");
|
|
|
|
builder.add_string_value (spoiler_text);
|
|
|
|
}
|
|
|
|
if (reblog != null) {
|
|
|
|
builder.set_member_name ("reblog");
|
|
|
|
builder.add_value (reblog.serialize ());
|
|
|
|
}
|
|
|
|
if (attachments != null) {
|
|
|
|
builder.set_member_name ("media_attachments");
|
|
|
|
builder.begin_array ();
|
|
|
|
foreach (Attachment attachment in attachments)
|
|
|
|
builder.add_value (attachment.serialize ());
|
|
|
|
builder.end_array ();
|
|
|
|
}
|
|
|
|
if (mentions != null) {
|
|
|
|
builder.set_member_name ("mentions");
|
|
|
|
builder.begin_array ();
|
|
|
|
foreach (Mention mention in mentions)
|
|
|
|
builder.add_value (mention.serialize ());
|
|
|
|
builder.end_array ();
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.end_object ();
|
|
|
|
return builder.get_root ();
|
|
|
|
}
|
|
|
|
|
2018-05-21 15:23:31 +00:00
|
|
|
public bool is_owned (){
|
2018-10-23 10:05:24 +00:00
|
|
|
return get_formal ().account.id == accounts.current.id;
|
2018-05-21 15:23:31 +00:00
|
|
|
}
|
|
|
|
|
2018-06-06 14:49:13 +00:00
|
|
|
public string get_reply_mentions () {
|
|
|
|
var result = "";
|
|
|
|
if (account.acct != accounts.current.acct)
|
|
|
|
result = "@%s ".printf (account.acct);
|
|
|
|
|
|
|
|
if (mentions != null) {
|
2018-07-11 17:13:52 +00:00
|
|
|
foreach (var mention in mentions) {
|
|
|
|
var equals_current = mention.acct == accounts.current.acct;
|
|
|
|
var already_mentioned = mention.acct in result;
|
|
|
|
|
|
|
|
if (!equals_current && ! already_mentioned)
|
2018-06-06 14:49:13 +00:00
|
|
|
result += "@%s ".printf (mention.acct);
|
2018-07-11 17:13:52 +00:00
|
|
|
}
|
2018-06-06 14:49:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-10-24 12:01:32 +00:00
|
|
|
public void set_reblogged (bool rebl = true) {
|
2018-05-01 13:53:46 +00:00
|
|
|
var action = rebl ? "reblog" : "unreblog";
|
2018-10-24 10:50:40 +00:00
|
|
|
var msg = new Soup.Message ("POST", "%s/api/v1/statuses/%lld/%s".printf (accounts.formal.instance, id, action));
|
2018-05-01 13:53:46 +00:00
|
|
|
msg.priority = Soup.MessagePriority.HIGH;
|
|
|
|
msg.finished.connect (() => {
|
|
|
|
reblogged = rebl;
|
|
|
|
updated ();
|
2018-10-24 10:50:40 +00:00
|
|
|
if (rebl)
|
2018-10-23 10:05:24 +00:00
|
|
|
app.toast (_("Boosted!"));
|
2018-05-01 13:53:46 +00:00
|
|
|
else
|
2018-10-23 10:05:24 +00:00
|
|
|
app.toast (_("Removed boost"));
|
2018-05-01 13:53:46 +00:00
|
|
|
});
|
2018-10-23 10:05:24 +00:00
|
|
|
network.queue (msg);
|
2018-05-01 13:53:46 +00:00
|
|
|
}
|
|
|
|
|
2018-10-24 12:01:32 +00:00
|
|
|
public void set_favorited (bool fav = true) {
|
2018-05-01 13:53:46 +00:00
|
|
|
var action = fav ? "favourite" : "unfavourite";
|
2018-10-24 10:50:40 +00:00
|
|
|
var msg = new Soup.Message ("POST", "%s/api/v1/statuses/%lld/%s".printf (accounts.formal.instance, id, action));
|
2018-05-01 13:53:46 +00:00
|
|
|
msg.priority = Soup.MessagePriority.HIGH;
|
|
|
|
msg.finished.connect (() => {
|
|
|
|
favorited = fav;
|
|
|
|
updated ();
|
2018-10-23 10:05:24 +00:00
|
|
|
if (fav)
|
|
|
|
app.toast (_("Favorited!"));
|
2018-05-01 13:53:46 +00:00
|
|
|
else
|
2018-10-23 10:05:24 +00:00
|
|
|
app.toast (_("Removed from favorites"));
|
2018-05-01 13:53:46 +00:00
|
|
|
});
|
2018-10-23 10:05:24 +00:00
|
|
|
network.queue (msg);
|
2018-05-01 13:53:46 +00:00
|
|
|
}
|
2018-05-22 12:47:25 +00:00
|
|
|
|
2018-10-24 12:01:32 +00:00
|
|
|
public void set_muted (bool mute = true) {
|
2018-05-22 13:18:39 +00:00
|
|
|
var action = mute ? "mute" : "unmute";
|
2018-10-24 10:50:40 +00:00
|
|
|
var msg = new Soup.Message ("POST", "%s/api/v1/statuses/%lld/%s".printf (accounts.formal.instance, id, action));
|
2018-05-22 13:18:39 +00:00
|
|
|
msg.priority = Soup.MessagePriority.HIGH;
|
|
|
|
msg.finished.connect (() => {
|
|
|
|
muted = mute;
|
|
|
|
updated ();
|
|
|
|
if (mute)
|
2018-10-30 16:24:29 +00:00
|
|
|
app.toast (_("Muted!"));
|
2018-05-22 13:18:39 +00:00
|
|
|
else
|
2018-10-23 10:05:24 +00:00
|
|
|
app.toast (_("Conversation unmuted"));
|
2018-05-22 13:18:39 +00:00
|
|
|
});
|
2018-10-23 10:05:24 +00:00
|
|
|
network.queue (msg);
|
2018-05-22 13:18:39 +00:00
|
|
|
}
|
|
|
|
|
2018-10-24 12:01:32 +00:00
|
|
|
public void set_pinned (bool pin = true) {
|
2018-10-24 09:00:40 +00:00
|
|
|
var action = pin ? "pin" : "unpin";
|
2018-10-24 10:50:40 +00:00
|
|
|
var msg = new Soup.Message ("POST", "%s/api/v1/statuses/%lld/%s".printf (accounts.formal.instance, id, action));
|
2018-10-24 09:00:40 +00:00
|
|
|
msg.priority = Soup.MessagePriority.HIGH;
|
|
|
|
msg.finished.connect (() => {
|
|
|
|
pinned = pin;
|
|
|
|
updated ();
|
|
|
|
if (pin)
|
2018-10-30 16:24:29 +00:00
|
|
|
app.toast (_("Pinned!"));
|
2018-10-24 09:00:40 +00:00
|
|
|
else
|
2018-10-30 16:24:29 +00:00
|
|
|
app.toast (_("Unpinned from profile"));
|
2018-10-24 09:00:40 +00:00
|
|
|
});
|
2018-10-24 09:29:36 +00:00
|
|
|
network.queue (msg);
|
2018-10-24 09:00:40 +00:00
|
|
|
}
|
|
|
|
|
2018-10-24 12:01:32 +00:00
|
|
|
public Soup.Message poof (bool show_toast = true) {
|
2018-10-24 10:50:40 +00:00
|
|
|
var msg = new Soup.Message ("DELETE", "%s/api/v1/statuses/%lld".printf (accounts.formal.instance, id));
|
2018-05-22 12:47:25 +00:00
|
|
|
msg.priority = Soup.MessagePriority.HIGH;
|
|
|
|
msg.finished.connect (() => {
|
2018-10-24 12:01:32 +00:00
|
|
|
if (show_toast)
|
|
|
|
app.toast (_("Poof!"));
|
2018-10-24 10:50:40 +00:00
|
|
|
network.status_removed (id);
|
2018-05-22 12:47:25 +00:00
|
|
|
});
|
2018-10-23 10:05:24 +00:00
|
|
|
network.queue (msg);
|
2018-10-24 12:01:32 +00:00
|
|
|
return msg;
|
2018-05-22 12:47:25 +00:00
|
|
|
}
|
2018-04-14 12:09:06 +00:00
|
|
|
|
|
|
|
}
|