1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 22:57:29 +00:00
This commit is contained in:
Austin Huang 2021-03-11 14:30:33 -05:00
parent b7d233b94d
commit d551969da3
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
6 changed files with 130 additions and 14 deletions

View File

@ -122,9 +122,8 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
private boolean hasStories = false; private boolean hasStories = false;
private HighlightsAdapter highlightsAdapter; private HighlightsAdapter highlightsAdapter;
private HighlightsViewModel highlightsViewModel; private HighlightsViewModel highlightsViewModel;
private MenuItem blockMenuItem; private MenuItem blockMenuItem, restrictMenuItem, chainingMenuItem;
private MenuItem restrictMenuItem; private MenuItem muteStoriesMenuItem, mutePostsMenuItem;
private MenuItem chainingMenuItem;
private boolean highlightsFetching; private boolean highlightsFetching;
private boolean postsSetupDone = false; private boolean postsSetupDone = false;
private Set<Media> selectedFeedModels; private Set<Media> selectedFeedModels;
@ -381,6 +380,25 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
restrictMenuItem.setVisible(false); restrictMenuItem.setVisible(false);
} }
} }
muteStoriesMenuItem = menu.findItem(R.id.mute_stories);
if (muteStoriesMenuItem != null) {
if (profileModel != null) {
muteStoriesMenuItem.setVisible(!Objects.equals(profileModel.getPk(), CookieUtils.getUserIdFromCookie(cookie)));
muteStoriesMenuItem.setTitle(profileModel.getFriendshipStatus().isMutingReel() ? R.string.mute_stories : R.string.unmute_stories);
} else {
muteStoriesMenuItem.setVisible(false);
}
}
mutePostsMenuItem = menu.findItem(R.id.mute_posts);
if (mutePostsMenuItem != null) {
if (profileModel != null) {
mutePostsMenuItem.setVisible(!Objects.equals(profileModel.getPk(), CookieUtils.getUserIdFromCookie(cookie)));
mutePostsMenuItem.setTitle(profileModel.getFriendshipStatus().isMuting() ? R.string.mute_posts : R.string.unmute_posts);
}
else {
mutePostsMenuItem.setVisible(false);
}
}
chainingMenuItem = menu.findItem(R.id.chaining); chainingMenuItem = menu.findItem(R.id.chaining);
if (chainingMenuItem != null) { if (chainingMenuItem != null) {
if (profileModel != null) { if (profileModel != null) {
@ -459,6 +477,48 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
NavHostFragment.findNavController(this).navigate(navDirections); NavHostFragment.findNavController(this).navigate(navDirections);
return true; return true;
} }
if (item.getItemId() == R.id.mute_stories) {
if (!isLoggedIn) return false;
final String action = profileModel.getFriendshipStatus().isMutingReel() ? "Unmute stories" : "Mute stories";
friendshipService.changeMute(
profileModel.getFriendshipStatus().isMutingReel(),
profileModel.getPk(),
true,
new ServiceCallback<FriendshipChangeResponse>() {
@Override
public void onSuccess(final FriendshipChangeResponse result) {
Log.d(TAG, action + " success: " + result);
fetchProfileDetails();
}
@Override
public void onFailure(final Throwable t) {
Log.e(TAG, "Error while performing " + action, t);
}
});
return true;
}
if (item.getItemId() == R.id.mute_posts) {
if (!isLoggedIn) return false;
final String action = profileModel.getFriendshipStatus().isMuting() ? "Unmute stories" : "Mute stories";
friendshipService.changeMute(
profileModel.getFriendshipStatus().isMuting(),
profileModel.getPk(),
false,
new ServiceCallback<FriendshipChangeResponse>() {
@Override
public void onSuccess(final FriendshipChangeResponse result) {
Log.d(TAG, action + " success: " + result);
fetchProfileDetails();
}
@Override
public void onFailure(final Throwable t) {
Log.e(TAG, "Error while performing " + action, t);
}
});
return true;
}
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@ -896,21 +956,21 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
} }
if (restrictMenuItem != null) { if (restrictMenuItem != null) {
restrictMenuItem.setVisible(true); restrictMenuItem.setVisible(true);
if (profileModel.getFriendshipStatus().isRestricted()) { restrictMenuItem.setTitle(profileModel.getFriendshipStatus().isRestricted() ? R.string.unrestrict : R.string.restrict);
restrictMenuItem.setTitle(R.string.unrestrict);
} else {
restrictMenuItem.setTitle(R.string.restrict);
}
} }
if (blockMenuItem != null) { if (blockMenuItem != null) {
blockMenuItem.setVisible(true); blockMenuItem.setVisible(true);
if (profileModel.getFriendshipStatus().isBlocking()) { blockMenuItem.setTitle(profileModel.getFriendshipStatus().isBlocking() ? R.string.unblock : R.string.block);
blockMenuItem.setTitle(R.string.unblock);
} else {
blockMenuItem.setTitle(R.string.block);
}
} }
if (chainingMenuItem != null && !Objects.equals(profileId, myId)) { if (muteStoriesMenuItem != null) {
muteStoriesMenuItem.setVisible(true);
muteStoriesMenuItem.setTitle(profileModel.getFriendshipStatus().isMutingReel() ? R.string.unmute_stories : R.string.mute_stories);
}
if (mutePostsMenuItem != null) {
mutePostsMenuItem.setVisible(true);
mutePostsMenuItem.setTitle(profileModel.getFriendshipStatus().isMuting() ? R.string.unmute_posts : R.string.mute_posts);
}
if (chainingMenuItem != null) {
chainingMenuItem.setVisible(true); chainingMenuItem.setVisible(true);
} }
return; return;

View File

@ -29,4 +29,9 @@ public interface FriendshipRepository {
Call<String> getList(@Path("userId") long userId, Call<String> getList(@Path("userId") long userId,
@Path("type") String type, // following or followers @Path("type") String type, // following or followers
@QueryMap(encoded = true) Map<String, String> queryParams); @QueryMap(encoded = true) Map<String, String> queryParams);
@FormUrlEncoded
@POST("/api/v1/friendships/{action}/")
Call<FriendshipChangeResponse> changeMute(@Path("action") String action,
@FieldMap Map<String, String> form);
} }

View File

@ -158,6 +158,38 @@ public class FriendshipService extends BaseService {
}); });
} }
public void changeMute(final boolean unmute,
final long targetUserId,
final boolean story, // true for story, false for posts
final ServiceCallback<FriendshipChangeResponse> callback) {
final Map<String, String> form = new HashMap<>(4);
form.put("_csrftoken", csrfToken);
form.put("_uid", String.valueOf(userId));
form.put("_uuid", deviceUuid);
form.put(story ? "target_reel_author_id" : "target_posts_author_id", String.valueOf(targetUserId));
final Call<FriendshipChangeResponse> request = repository.changeMute(unmute ?
"unmute_posts_or_story_from_follow" :
"mute_posts_or_story_from_follow",
form);
request.enqueue(new Callback<FriendshipChangeResponse>() {
@Override
public void onResponse(@NonNull final Call<FriendshipChangeResponse> call,
@NonNull final Response<FriendshipChangeResponse> response) {
if (callback != null) {
callback.onSuccess(response.body());
}
}
@Override
public void onFailure(@NonNull final Call<FriendshipChangeResponse> call,
@NonNull final Throwable t) {
if (callback != null) {
callback.onFailure(t);
}
}
});
}
public void getList(final boolean follower, public void getList(final boolean follower,
final long targetUserId, final long targetUserId,
final String maxId, final String maxId,

View File

@ -137,6 +137,7 @@ public class StoriesService extends BaseService {
final JSONArray feedStoriesReel = new JSONObject(body).getJSONArray("tray"); final JSONArray feedStoriesReel = new JSONObject(body).getJSONArray("tray");
for (int i = 0; i < feedStoriesReel.length(); ++i) { for (int i = 0; i < feedStoriesReel.length(); ++i) {
final JSONObject node = feedStoriesReel.getJSONObject(i); final JSONObject node = feedStoriesReel.getJSONObject(i);
if (node.optBoolean("hide_from_feed_unit")) continue;
final JSONObject userJson = node.getJSONObject(node.has("user") ? "user" : "owner"); final JSONObject userJson = node.getJSONObject(node.has("user") ? "user" : "owner");
try { try {
final User user = new User(userJson.getLong("pk"), final User user = new User(userJson.getLong("pk"),

View File

@ -26,4 +26,18 @@
android:title="@string/action_ayml" android:title="@string/action_ayml"
android:visible="false" android:visible="false"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/mute_stories"
android:icon="@drawable/ic_highlight_off_24"
android:title="@string/mute_stories"
android:visible="false"
app:showAsAction="never" />
<item
android:id="@+id/mute_posts"
android:icon="@drawable/ic_highlight_off_24"
android:title="@string/mute_posts"
android:visible="false"
app:showAsAction="never" />
</menu> </menu>

View File

@ -123,6 +123,10 @@
<string name="unblock">Unblock</string> <string name="unblock">Unblock</string>
<string name="restrict">Restrict</string> <string name="restrict">Restrict</string>
<string name="unrestrict">Unrestrict</string> <string name="unrestrict">Unrestrict</string>
<string name="mute_stories">Mute stories</string>
<string name="mute_posts">Mute posts</string>
<string name="unmute_stories">Unmute stories</string>
<string name="unmute_posts">Unmute posts</string>
<string name="bio_copy">Copy bio</string> <string name="bio_copy">Copy bio</string>
<string name="bio_translate">Translate bio</string> <string name="bio_translate">Translate bio</string>
<string name="status_mutual">Mutual</string> <string name="status_mutual">Mutual</string>