Improve federation of accounts with Peertube

This commit is contained in:
stom79 2018-10-20 18:13:22 +02:00
parent 0fb906dc1b
commit ccfe6e368c
4 changed files with 20 additions and 12 deletions

View File

@ -16,12 +16,9 @@ package fr.gouv.etalab.mastodon.client;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
@ -35,10 +32,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.client.Entities.*;
import fr.gouv.etalab.mastodon.client.Entities.Error;
@ -650,7 +644,6 @@ public class API {
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
String response = httpsConnection.get(String.format("https://"+instance+"/api/v1/videos/%s", videoId), 60, null, null);
Log.v(Helper.TAG,"response: " + response);
JSONObject jsonObject = new JSONObject(response);
peertube = parseSinglePeertube(context, instance, jsonObject);
} catch (HttpsConnection.HttpsConnectionException e) {
@ -1580,9 +1573,6 @@ public class API {
*/
public Results search(String query) {
//A fix for peertube and account
if( query.startsWith("http") && query.split("@").length > 2)
query = "@"+query.split("@")[1] +"@"+ query.split("@")[2];
HashMap<String, String> params = new HashMap<>();
params.put("q", query);
try {
@ -2854,6 +2844,7 @@ public class API {
account.setUsername(resobj.get("name").toString());
account.setAcct(resobj.get("name").toString() + "@"+ resobj.get("host").toString());
account.setDisplay_name(resobj.get("displayName").toString());
account.setHost(resobj.get("host").toString());
if( resobj.has("createdAt") )
account.setCreated_at(Helper.mstStringToDate(context, resobj.get("createdAt").toString()));
else

View File

@ -90,7 +90,7 @@ public class Account implements Parcelable {
private HashMap<String, SpannableString> fieldsSpan = new HashMap<>();
private List<Emojis> emojis;
private Account account;
private String host;
public followAction getFollowType() {
@ -150,6 +150,14 @@ public class Account implements Parcelable {
this.fieldsVerified = fieldsVerified;
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public enum followAction{
FOLLOW,
@ -166,6 +174,7 @@ public class Account implements Parcelable {
username = in.readString();
acct = in.readString();
display_name = in.readString();
host = in.readString();
locked = in.readByte() != 0;
followers_count = in.readInt();
following_count = in.readInt();
@ -379,6 +388,7 @@ public class Account implements Parcelable {
dest.writeString(username);
dest.writeString(acct);
dest.writeString(display_name);
dest.writeString(host);
dest.writeByte((byte) (locked ? 1 : 0));
dest.writeInt(followers_count);
dest.writeInt(following_count);

View File

@ -21,6 +21,7 @@ import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -113,10 +114,12 @@ public class PeertubeAdapter extends RecyclerView.Adapter implements OnListActio
Bundle b = new Bundle();
String finalUrl = "https://" + instance + peertube.getEmbedPath();
Pattern link = Pattern.compile("(https?:\\/\\/[\\da-z\\.-]+\\.[a-z\\.]{2,10})\\/videos\\/embed\\/(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})$");
Log.v(Helper.TAG,"finalUrl: "+finalUrl);
Matcher matcherLink = link.matcher(finalUrl);
if( matcherLink.find()) {
String url = matcherLink.group(1) + "/videos/watch/" + matcherLink.group(2);
b.putString("peertubeLinkToFetch", url);
Log.v(Helper.TAG,"peertube_instance: "+matcherLink.group(1).replace("https://","").replace("http://",""));
b.putString("peertube_instance", matcherLink.group(1).replace("https://","").replace("http://",""));
b.putString("video_id", matcherLink.group(2));
}

View File

@ -217,7 +217,11 @@ public class CrossActions {
@Override
protected Void doInBackground(Void... voids) {
API api = new API(contextReference.get(), account.getInstance(), account.getToken());
String url = "https://" + remoteAccount.getInstance() + "/@" + remoteAccount.getAcct();
String url;
if( remoteAccount.getHost() != null && remoteAccount.getAcct().split("@").length > 1) //Peertube compatibility
url = "https://" + remoteAccount.getHost() + "/accounts/" + remoteAccount.getAcct().split("@")[0];
else
url = "https://" + remoteAccount.getInstance() + "/@" + remoteAccount.getAcct();
response = api.search(url);
return null;
}