mirror of
https://framagit.org/tom79/fedilab-tube
synced 2025-05-20 05:34:26 +02:00
Fix comment issue when posting
This commit is contained in:
parent
2f773b2f0f
commit
2d33d7f970
@ -975,8 +975,10 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||||||
public void manageVIewPostActions(RetrofitPeertubeAPI.ActionType statusAction, APIResponse apiResponse) {
|
public void manageVIewPostActions(RetrofitPeertubeAPI.ActionType statusAction, APIResponse apiResponse) {
|
||||||
|
|
||||||
if (peertube.isCommentsEnabled() && statusAction == ADD_COMMENT) {
|
if (peertube.isCommentsEnabled() && statusAction == ADD_COMMENT) {
|
||||||
CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class);
|
if( apiResponse.getComments() != null && apiResponse.getComments().size() > 0 ) {
|
||||||
commentViewModel.getThread(sepiaSearch?peertubeInstance:null, videoUuid, max_id).observe(PeertubeActivity.this, this::manageVIewComment);
|
comments.add(0, apiResponse.getComments().get(0));
|
||||||
|
commentListAdapter.notifyItemInserted(0);
|
||||||
|
}
|
||||||
} else if (statusAction == RetrofitPeertubeAPI.ActionType.REPORT_ACCOUNT) {
|
} else if (statusAction == RetrofitPeertubeAPI.ActionType.REPORT_ACCOUNT) {
|
||||||
Toasty.success(PeertubeActivity.this, getString(R.string.successful_report), Toasty.LENGTH_LONG).show();
|
Toasty.success(PeertubeActivity.this, getString(R.string.successful_report), Toasty.LENGTH_LONG).show();
|
||||||
} else if (statusAction == RetrofitPeertubeAPI.ActionType.REPORT_VIDEO) {
|
} else if (statusAction == RetrofitPeertubeAPI.ActionType.REPORT_VIDEO) {
|
||||||
|
@ -17,7 +17,7 @@ package app.fedilab.fedilabtube.client;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import app.fedilab.fedilabtube.client.data.AccountData;
|
|
||||||
import app.fedilab.fedilabtube.client.data.BlockData;
|
import app.fedilab.fedilabtube.client.data.BlockData;
|
||||||
import app.fedilab.fedilabtube.client.data.CaptionData;
|
import app.fedilab.fedilabtube.client.data.CaptionData;
|
||||||
import app.fedilab.fedilabtube.client.data.ChannelData;
|
import app.fedilab.fedilabtube.client.data.ChannelData;
|
||||||
@ -332,11 +332,11 @@ public interface PeertubeService {
|
|||||||
|
|
||||||
@FormUrlEncoded
|
@FormUrlEncoded
|
||||||
@POST("videos/{id}/comment-threads")
|
@POST("videos/{id}/comment-threads")
|
||||||
Call<String> postComment(@Header("Authorization") String credentials, @Path("id") String id, @Field("text") String text);
|
Call<CommentData.CommentPosted> postComment(@Header("Authorization") String credentials, @Path("id") String id, @Field("text") String text);
|
||||||
|
|
||||||
@FormUrlEncoded
|
@FormUrlEncoded
|
||||||
@POST("videos/{id}/comments/{commentId}")
|
@POST("videos/{id}/comments/{commentId}")
|
||||||
Call<String> postReply(@Header("Authorization") String credentials, @Path("id") String id, @Path("commentId") String commentId, @Field("text") String text);
|
Call<CommentData.CommentPosted> postReply(@Header("Authorization") String credentials, @Path("id") String id, @Path("commentId") String commentId, @Field("text") String text);
|
||||||
|
|
||||||
@DELETE("videos/{id}/comments/{commentId}")
|
@DELETE("videos/{id}/comments/{commentId}")
|
||||||
Call<String> deleteComment(@Header("Authorization") String credentials, @Path("id") String id, @Path("commentId") String commentId);
|
Call<String> deleteComment(@Header("Authorization") String credentials, @Path("id") String id, @Path("commentId") String commentId);
|
||||||
|
@ -82,12 +82,12 @@ import retrofit2.converter.gson.GsonConverterFactory;
|
|||||||
@SuppressWarnings({"unused", "RedundantSuppression"})
|
@SuppressWarnings({"unused", "RedundantSuppression"})
|
||||||
public class RetrofitPeertubeAPI {
|
public class RetrofitPeertubeAPI {
|
||||||
|
|
||||||
private String finalUrl;
|
private final String finalUrl;
|
||||||
private Context _context;
|
private final Context _context;
|
||||||
private String instance;
|
private final String instance;
|
||||||
private String token;
|
private String token;
|
||||||
private Set<String> selection;
|
private Set<String> selection;
|
||||||
private String count;
|
private final String count;
|
||||||
|
|
||||||
public RetrofitPeertubeAPI(Context context) {
|
public RetrofitPeertubeAPI(Context context) {
|
||||||
_context = context;
|
_context = context;
|
||||||
@ -1232,18 +1232,22 @@ public class RetrofitPeertubeAPI {
|
|||||||
APIResponse apiResponse = new APIResponse();
|
APIResponse apiResponse = new APIResponse();
|
||||||
try {
|
try {
|
||||||
if (type == ActionType.ADD_COMMENT) {
|
if (type == ActionType.ADD_COMMENT) {
|
||||||
Call<String> stringCall = peertubeService.postComment(getToken(), videoId, text);
|
Call<CommentData.CommentPosted> commentPostedCall = peertubeService.postComment(getToken(), videoId, text);
|
||||||
Response<String> response = stringCall.execute();
|
Response<CommentData.CommentPosted> response = commentPostedCall.execute();
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful() && response.body() != null) {
|
||||||
apiResponse.setActionReturn(response.body());
|
List<CommentData.Comment> comments = new ArrayList<>();
|
||||||
|
comments.add(response.body().getComment());
|
||||||
|
apiResponse.setComments(comments);
|
||||||
} else {
|
} else {
|
||||||
setError(apiResponse, response.code(), response.errorBody());
|
setError(apiResponse, response.code(), response.errorBody());
|
||||||
}
|
}
|
||||||
} else if (type == ActionType.REPLY) {
|
} else if (type == ActionType.REPLY) {
|
||||||
Call<String> stringCall = peertubeService.postReply(getToken(), videoId, toCommentId, text);
|
Call<CommentData.CommentPosted> commentPostedCall = peertubeService.postReply(getToken(), videoId, toCommentId, text);
|
||||||
Response<String> response = stringCall.execute();
|
Response<CommentData.CommentPosted> response = commentPostedCall.execute();
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful() && response.body() != null) {
|
||||||
apiResponse.setActionReturn(response.body());
|
List<CommentData.Comment> comments = new ArrayList<>();
|
||||||
|
comments.add(response.body().getComment());
|
||||||
|
apiResponse.setComments(comments);
|
||||||
} else {
|
} else {
|
||||||
setError(apiResponse, response.code(), response.errorBody());
|
setError(apiResponse, response.code(), response.errorBody());
|
||||||
}
|
}
|
||||||
|
@ -163,6 +163,20 @@ public class CommentData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class CommentPosted{
|
||||||
|
@SerializedName("comment")
|
||||||
|
private Comment comment;
|
||||||
|
|
||||||
|
public Comment getComment() {
|
||||||
|
return comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setComment(Comment comment) {
|
||||||
|
this.comment = comment;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class NotificationComment {
|
public static class NotificationComment {
|
||||||
@SerializedName("id")
|
@SerializedName("id")
|
||||||
private String id;
|
private String id;
|
||||||
|
@ -16,6 +16,7 @@ package app.fedilab.fedilabtube.drawer;
|
|||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@ -49,7 +50,6 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import app.fedilab.fedilabtube.R;
|
import app.fedilab.fedilabtube.R;
|
||||||
import app.fedilab.fedilabtube.ShowAccountActivity;
|
|
||||||
import app.fedilab.fedilabtube.client.APIResponse;
|
import app.fedilab.fedilabtube.client.APIResponse;
|
||||||
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
||||||
import app.fedilab.fedilabtube.client.data.CommentData.Comment;
|
import app.fedilab.fedilabtube.client.data.CommentData.Comment;
|
||||||
@ -66,8 +66,8 @@ public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
|||||||
|
|
||||||
public AllCommentRemoved allCommentRemoved;
|
public AllCommentRemoved allCommentRemoved;
|
||||||
private Context context;
|
private Context context;
|
||||||
private List<Comment> comments;
|
private final List<Comment> comments;
|
||||||
private CommentListAdapter commentListAdapter;
|
private final CommentListAdapter commentListAdapter;
|
||||||
boolean isVideoOwner;
|
boolean isVideoOwner;
|
||||||
|
|
||||||
public CommentListAdapter(List<Comment> comments, boolean isVideoOwner) {
|
public CommentListAdapter(List<Comment> comments, boolean isVideoOwner) {
|
||||||
@ -131,67 +131,64 @@ public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
|||||||
popup.getMenu().findItem(R.id.action_delete).setVisible(false);
|
popup.getMenu().findItem(R.id.action_delete).setVisible(false);
|
||||||
}
|
}
|
||||||
popup.setOnMenuItemClickListener(item -> {
|
popup.setOnMenuItemClickListener(item -> {
|
||||||
switch (item.getItemId()) {
|
int itemId = item.getItemId();
|
||||||
case R.id.action_delete:
|
if (itemId == R.id.action_delete) {
|
||||||
android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context);
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
builder.setTitle(R.string.delete_comment);
|
builder.setTitle(R.string.delete_comment);
|
||||||
builder.setMessage(R.string.delete_comment_confirm);
|
builder.setMessage(R.string.delete_comment_confirm);
|
||||||
builder.setIcon(android.R.drawable.ic_dialog_alert)
|
builder.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
.setPositiveButton(R.string.delete, (dialog, which) -> {
|
.setPositiveButton(R.string.delete, (dialog, which) -> {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
new RetrofitPeertubeAPI(context).post(RetrofitPeertubeAPI.ActionType.PEERTUBEDELETECOMMENT, comment.getVideoId(), comment.getId());
|
new RetrofitPeertubeAPI(context).post(RetrofitPeertubeAPI.ActionType.PEERTUBEDELETECOMMENT, comment.getVideoId(), comment.getId());
|
||||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||||
Runnable myRunnable = () -> {
|
Runnable myRunnable = () -> {
|
||||||
comments.remove(comment);
|
comments.remove(comment);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
if (comments.size() == 0) {
|
if (comments.size() == 0) {
|
||||||
allCommentRemoved.onAllCommentRemoved();
|
allCommentRemoved.onAllCommentRemoved();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
mainHandler.post(myRunnable);
|
mainHandler.post(myRunnable);
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss())
|
.setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss())
|
||||||
.show();
|
.show();
|
||||||
break;
|
} else if (itemId == R.id.action_report) {
|
||||||
case R.id.action_report:
|
reportComment(comment);
|
||||||
reportComment(comment);
|
} else if (itemId == R.id.action_mute) {
|
||||||
break;
|
PostActionsVM viewModel = new ViewModelProvider((ViewModelStoreOwner) context).get(PostActionsVM.class);
|
||||||
case R.id.action_mute:
|
viewModel.post(MUTE, comment.getAccount().getAcct(), null).observe((LifecycleOwner) context, apiResponse -> manageVIewPostActions(MUTE, apiResponse));
|
||||||
PostActionsVM viewModel = new ViewModelProvider((ViewModelStoreOwner) context).get(PostActionsVM.class);
|
comments.remove(comment);
|
||||||
viewModel.post(MUTE, comment.getAccount().getAcct(), null).observe((LifecycleOwner) context, apiResponse -> manageVIewPostActions(MUTE, apiResponse));
|
notifyDataSetChanged();
|
||||||
comments.remove(comment);
|
if (comments.size() == 0) {
|
||||||
notifyDataSetChanged();
|
allCommentRemoved.onAllCommentRemoved();
|
||||||
if (comments.size() == 0) {
|
}
|
||||||
allCommentRemoved.onAllCommentRemoved();
|
} else if (itemId == R.id.action_remove_comments) {
|
||||||
}
|
AlertDialog.Builder builder;
|
||||||
break;
|
builder = new AlertDialog.Builder(context);
|
||||||
case R.id.action_remove_comments:
|
builder.setTitle(R.string.delete_account_comment);
|
||||||
builder = new android.app.AlertDialog.Builder(context);
|
builder.setMessage(R.string.delete_account_comment_confirm);
|
||||||
builder.setTitle(R.string.delete_account_comment);
|
builder.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
builder.setMessage(R.string.delete_account_comment_confirm);
|
.setPositiveButton(R.string.delete, (dialog, which) -> {
|
||||||
builder.setIcon(android.R.drawable.ic_dialog_alert)
|
new Thread(() -> {
|
||||||
.setPositiveButton(R.string.delete, (dialog, which) -> {
|
new RetrofitPeertubeAPI(context).post(RetrofitPeertubeAPI.ActionType.PEERTUBE_DELETE_ALL_COMMENT_FOR_ACCOUNT, comment.getAccount().getAcct(), "my-videos");
|
||||||
new Thread(() -> {
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||||
new RetrofitPeertubeAPI(context).post(RetrofitPeertubeAPI.ActionType.PEERTUBE_DELETE_ALL_COMMENT_FOR_ACCOUNT, comment.getAccount().getAcct(), "my-videos");
|
Runnable myRunnable = () -> {
|
||||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
comments.remove(comment);
|
||||||
Runnable myRunnable = () -> {
|
notifyDataSetChanged();
|
||||||
comments.remove(comment);
|
if (comments.size() == 0) {
|
||||||
notifyDataSetChanged();
|
allCommentRemoved.onAllCommentRemoved();
|
||||||
if (comments.size() == 0) {
|
}
|
||||||
allCommentRemoved.onAllCommentRemoved();
|
};
|
||||||
}
|
mainHandler.post(myRunnable);
|
||||||
};
|
}).start();
|
||||||
mainHandler.post(myRunnable);
|
|
||||||
}).start();
|
|
||||||
|
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss())
|
.setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss())
|
||||||
.show();
|
.show();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
@ -253,6 +253,10 @@ public class Helper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a default instance host name depending of the device locale
|
||||||
|
* @return peertube host String
|
||||||
|
*/
|
||||||
private static String getDefaultInstance() {
|
private static String getDefaultInstance() {
|
||||||
String lang = Locale.getDefault().getLanguage();
|
String lang = Locale.getDefault().getLanguage();
|
||||||
if (lang.contains("-")) {
|
if (lang.contains("-")) {
|
||||||
@ -331,6 +335,11 @@ public class Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert second to String formated date
|
||||||
|
* @param pTime timestamp
|
||||||
|
* @return String formatted value
|
||||||
|
*/
|
||||||
public static String secondsToString(int pTime) {
|
public static String secondsToString(int pTime) {
|
||||||
|
|
||||||
int hour = pTime / 3600;
|
int hour = pTime / 3600;
|
||||||
@ -391,6 +400,11 @@ public class Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return rounded numbers depending of the value
|
||||||
|
* @param count long
|
||||||
|
* @return String rounded value to be displayed
|
||||||
|
*/
|
||||||
public static String withSuffix(long count) {
|
public static String withSuffix(long count) {
|
||||||
if (count < 1000) return "" + count;
|
if (count < 1000) return "" + count;
|
||||||
int exp = (int) (Math.log(count) / Math.log(1000));
|
int exp = (int) (Math.log(count) / Math.log(1000));
|
||||||
@ -419,7 +433,7 @@ public class Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void loadGiF(final Context context, String url, final ImageView imageView, int round) {
|
public static void loadGiF(final Context context, String url, final ImageView imageView, int round) {
|
||||||
loadGif(context, null, url, imageView, 10);
|
loadGif(context, null, url, imageView, round);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("SameParameterValue")
|
@SuppressWarnings("SameParameterValue")
|
||||||
@ -458,6 +472,13 @@ public class Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the webview
|
||||||
|
* @param activity Current Activity
|
||||||
|
* @param webviewId int id of the webview layout
|
||||||
|
* @param rootView View the root view
|
||||||
|
* @return CustomWebview
|
||||||
|
*/
|
||||||
@SuppressLint("SetJavaScriptEnabled")
|
@SuppressLint("SetJavaScriptEnabled")
|
||||||
public static CustomWebview initializeWebview(Activity activity, int webviewId, View rootView) {
|
public static CustomWebview initializeWebview(Activity activity, int webviewId, View rootView) {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user