feat: update instance account info on start
This commit is contained in:
parent
5eb82025a1
commit
bb38f7ff0e
|
@ -36,6 +36,16 @@ public class Tooth.SecretAccountStore : AccountStore {
|
||||||
secrets.foreach (item => {
|
secrets.foreach (item => {
|
||||||
var account = secret_to_account (item);
|
var account = secret_to_account (item);
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
|
new Request.GET (@"/api/v1/accounts/$(account.id)")
|
||||||
|
.with_account (account)
|
||||||
|
.then ((sess, msg) => {
|
||||||
|
var node = network.parse_node (msg);
|
||||||
|
var acc = API.Account.from (node);
|
||||||
|
|
||||||
|
account.display_name = acc.display_name;
|
||||||
|
account.avatar = acc.avatar;
|
||||||
|
})
|
||||||
|
.exec ();
|
||||||
saved.add (account);
|
saved.add (account);
|
||||||
account.added ();
|
account.added ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,15 +79,25 @@ public class Tooth.Views.Sidebar : Box, AccountHolder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Binding sidebar_display_name;
|
||||||
|
private Binding sidebar_handle_short;
|
||||||
|
private Binding sidebar_avatar;
|
||||||
|
private ulong sidebar_private_signal;
|
||||||
protected virtual void on_account_changed (InstanceAccount? account) {
|
protected virtual void on_account_changed (InstanceAccount? account) {
|
||||||
|
if (this.account != null) {
|
||||||
|
sidebar_display_name.unbind();
|
||||||
|
sidebar_handle_short.unbind();
|
||||||
|
sidebar_avatar.unbind();
|
||||||
|
this.account.disconnect(sidebar_private_signal);
|
||||||
|
}
|
||||||
|
|
||||||
this.account = account;
|
this.account = account;
|
||||||
accounts_button.active = false;
|
accounts_button.active = false;
|
||||||
|
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
this.account.bind_property("display-name", title, "label", BindingFlags.SYNC_CREATE);
|
sidebar_private_signal = this.account.notify["locked"].connect(() => {
|
||||||
this.account.notify["locked"].connect(() => {
|
|
||||||
uint indx;
|
uint indx;
|
||||||
var found = this.account.known_places.find (Mastodon.Account.PLACE_FOLLOW_REQUESTS, out indx);
|
var found = this.account.known_places.find (Mastodon.Account.PLACE_FOLLOW_REQUESTS, out indx);
|
||||||
|
|
||||||
if (this.account.locked == false && found == true) {
|
if (this.account.locked == false && found == true) {
|
||||||
this.account.known_places.remove(indx);
|
this.account.known_places.remove(indx);
|
||||||
|
@ -95,14 +105,15 @@ public class Tooth.Views.Sidebar : Box, AccountHolder {
|
||||||
this.account.known_places.append(Mastodon.Account.PLACE_FOLLOW_REQUESTS);
|
this.account.known_places.append(Mastodon.Account.PLACE_FOLLOW_REQUESTS);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
sidebar_display_name = this.account.bind_property("display-name", title, "label", BindingFlags.SYNC_CREATE);
|
||||||
|
sidebar_handle_short = this.account.bind_property("handle_short", subtitle, "label", BindingFlags.SYNC_CREATE);
|
||||||
|
sidebar_avatar = this.account.bind_property("avatar", avatar, "avatar-url", BindingFlags.SYNC_CREATE);
|
||||||
// FIXME: Wrapping
|
// FIXME: Wrapping
|
||||||
// this.account.notify["display-name"].connect(() => {
|
// this.account.notify["display-name"].connect(() => {
|
||||||
// title.instance_emojis = this.account.emojis_map;
|
// title.instance_emojis = this.account.emojis_map;
|
||||||
// title.label = this.account.display_name;
|
// title.label = this.account.display_name;
|
||||||
// });
|
// });
|
||||||
this.account.bind_property("handle_short", subtitle, "label", BindingFlags.SYNC_CREATE);
|
|
||||||
this.bind_property("account", avatar, "account", BindingFlags.SYNC_CREATE);
|
|
||||||
account_items.model = account.known_places;
|
account_items.model = account.known_places;
|
||||||
} else {
|
} else {
|
||||||
saved_accounts.unselect_all ();
|
saved_accounts.unselect_all ();
|
||||||
|
@ -184,12 +195,22 @@ public class Tooth.Views.Sidebar : Box, AccountHolder {
|
||||||
[GtkChild] unowned Widgets.Avatar avatar;
|
[GtkChild] unowned Widgets.Avatar avatar;
|
||||||
[GtkChild] unowned Button forget;
|
[GtkChild] unowned Button forget;
|
||||||
|
|
||||||
|
private Binding switcher_display_name;
|
||||||
|
private Binding switcher_handle;
|
||||||
|
private Binding switcher_avatar;
|
||||||
public AccountRow (InstanceAccount? _account) {
|
public AccountRow (InstanceAccount? _account) {
|
||||||
|
if (account != null) {
|
||||||
|
switcher_display_name.unbind();
|
||||||
|
switcher_handle.unbind();
|
||||||
|
switcher_avatar.unbind();
|
||||||
|
}
|
||||||
|
|
||||||
account = _account;
|
account = _account;
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
title = account.display_name;
|
|
||||||
subtitle = account.handle;
|
switcher_display_name = this.account.bind_property("display-name", this, "title", BindingFlags.SYNC_CREATE);
|
||||||
avatar.account = account;
|
switcher_handle = this.account.bind_property("handle", this, "subtitle", BindingFlags.SYNC_CREATE);
|
||||||
|
switcher_avatar = this.account.bind_property("avatar", avatar, "avatar-url", BindingFlags.SYNC_CREATE);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
title = _("Add Account");
|
title = _("Add Account");
|
||||||
|
|
|
@ -15,6 +15,7 @@ public class Tooth.Widgets.Avatar : Button {
|
||||||
protected Adw.Avatar? avatar {
|
protected Adw.Avatar? avatar {
|
||||||
get { return child as Adw.Avatar; }
|
get { return child as Adw.Avatar; }
|
||||||
}
|
}
|
||||||
|
public string? avatar_url { get; set; }
|
||||||
|
|
||||||
construct {
|
construct {
|
||||||
child = new Adw.Avatar (48, null, true);
|
child = new Adw.Avatar (48, null, true);
|
||||||
|
@ -25,9 +26,16 @@ public class Tooth.Widgets.Avatar : Button {
|
||||||
add_css_class ("ttl-flat-button");
|
add_css_class ("ttl-flat-button");
|
||||||
|
|
||||||
notify["account"].connect (on_invalidated);
|
notify["account"].connect (on_invalidated);
|
||||||
|
notify["avatar-url"].connect (on_avatar_url_change);
|
||||||
on_invalidated ();
|
on_invalidated ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void on_avatar_url_change () {
|
||||||
|
if (avatar_url == null) return;
|
||||||
|
|
||||||
|
image_cache.request_paintable (avatar_url, on_cache_response);
|
||||||
|
}
|
||||||
|
|
||||||
void on_invalidated () {
|
void on_invalidated () {
|
||||||
if (account == null) {
|
if (account == null) {
|
||||||
avatar.text = "d";
|
avatar.text = "d";
|
||||||
|
|
Loading…
Reference in New Issue