address cross site query fail situation

This commit is contained in:
doubaniux 2020-10-25 15:47:25 +01:00
parent 1465220a5a
commit 677851c420
6 changed files with 26 additions and 6 deletions

View file

@ -146,13 +146,24 @@ class UserOwnedEntity(models.Model):
# this is guaranteed by models
id_list = []
for entity in user_owned_entities:
# none_index tracks those failed cross site id query
none_index = []
for (i, entity) in enumerate(user_owned_entities):
if entity.owner.mastodon_site == request_user.mastodon_site:
id_list.append(entity.owner.mastodon_id)
else:
# TODO there could be many requests therefore make the pulling asynchronized
id_list.append(get_cross_site_id(
entity.owner, request_user.mastodon_site, token))
cross_site_id = get_cross_site_id(
entity.owner, request_user.mastodon_site, token)
if not cross_site_id is None:
id_list.append(cross_site_id)
else:
none_index.append(i)
# populate those query-failed None postions
# to ensure the consistency of the orders of
# the three(id_list, user_owned_entities, relationships)
id_list.append(request_user.mastodon_id)
# Mastodon request
relationships = get_relationships(
@ -169,7 +180,7 @@ class UserOwnedEntity(models.Model):
available_entities = [
e for i, e in enumerate(user_owned_entities)
if ((e.is_private == True and i in following_index) or e.is_private == False or e.owner == request_user)
and not i in mute_block_blocked_index
and not i in mute_block_blocked_index and not i in none_index
]
return available_entities

View file

@ -768,6 +768,7 @@ select::placeholder {
.footer__link {
margin: 0 12px;
white-space: nowrap;
}
@media (max-width: 575.98px) {

File diff suppressed because one or more lines are too long

View file

@ -26,6 +26,7 @@
&__link
margin: 0 12px
white-space: nowrap
// Small devices (landscape phones, 576px and up)
@media (max-width: $small-devices)

View file

@ -155,6 +155,8 @@ def get_cross_site_id(target_user, target_site, token):
except ObjectDoesNotExist:
cross_site_id = get_site_id(
target_user.username, target_site, token)
if not cross_site_id:
return None
cross_site_info = CrossSiteUserInfo.objects.create(
uid=f"{target_user.username}@{target_user.mastodon_site}",
target_site=target_site,

View file

@ -65,10 +65,15 @@
let domain = selected.val();
Cookies.set('mastodon_domain', domain);
{% if debug %}
location.href = "https://" + domain + "/oauth/authorize?client_id=" + client_id +
"&scope=read+write&redirect_uri=http://{{ request.get_host }}{% url 'users:OAuth2_login' %}" +
"&response_type=code";
{% else %}
location.href = "https://" + domain + "/oauth/authorize?client_id=" + client_id +
"&scope=read+write&redirect_uri=https://{{ request.get_host }}{% url 'users:OAuth2_login' %}" +
"&response_type=code";
{% endif %}
});
</script>
{% endif %}