mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-26 00:27:30 +00:00
Allow toggling approval requirement in group
This commit is contained in:
parent
10c6902c83
commit
17709c176c
@ -94,41 +94,6 @@ public class DirectMessageSettingsFragment extends Fragment implements ConfirmDi
|
|||||||
viewModel = new ViewModelProvider(this).get(DirectSettingsViewModel.class);
|
viewModel = new ViewModelProvider(this).get(DirectSettingsViewModel.class);
|
||||||
viewModel.setViewer(inboxViewModel.getViewer());
|
viewModel.setViewer(inboxViewModel.getViewer());
|
||||||
viewModel.setThread(first.get());
|
viewModel.setThread(first.get());
|
||||||
// basicClickListener = v -> {
|
|
||||||
// final Object tag = v.getTag();
|
|
||||||
// if (tag instanceof ProfileModel) {
|
|
||||||
// ProfileModel model = (ProfileModel) tag;
|
|
||||||
// final Bundle bundle = new Bundle();
|
|
||||||
// bundle.putString("username", "@" + model.getUsername());
|
|
||||||
// NavHostFragment.findNavController(this).navigate(R.id.action_global_profileFragment, bundle);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// clickListener = v -> {
|
|
||||||
// final Object tag = v.getTag();
|
|
||||||
// if (tag instanceof ProfileModel) {
|
|
||||||
// ProfileModel model = (ProfileModel) tag;
|
|
||||||
// final Context context = getContext();
|
|
||||||
// if (context == null) return;
|
|
||||||
// final ArrayAdapter<String> adapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, new String[]{
|
|
||||||
// getString(R.string.open_profile),
|
|
||||||
// getString(R.string.dms_action_kick),
|
|
||||||
// });
|
|
||||||
// final DialogInterface.OnClickListener clickListener = (d, w) -> {
|
|
||||||
// if (w == 0) {
|
|
||||||
// final Bundle bundle = new Bundle();
|
|
||||||
// bundle.putString("username", "@" + model.getUsername());
|
|
||||||
// NavHostFragment.findNavController(this).navigate(R.id.action_global_profileFragment, bundle);
|
|
||||||
// } else if (w == 1) {
|
|
||||||
// new ChangeSettings(titleText.getText().toString()).execute("remove_users", model.getId());
|
|
||||||
// onRefresh();
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// new AlertDialog.Builder(context)
|
|
||||||
// .setAdapter(adapter, clickListener)
|
|
||||||
// .show();
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -327,7 +292,8 @@ public class DirectMessageSettingsFragment extends Fragment implements ConfirmDi
|
|||||||
binding.approvalRequiredLabel.setVisibility(View.VISIBLE);
|
binding.approvalRequiredLabel.setVisibility(View.VISIBLE);
|
||||||
binding.approvalRequiredLabel.setOnClickListener(v -> binding.approvalRequired.toggle());
|
binding.approvalRequiredLabel.setOnClickListener(v -> binding.approvalRequired.toggle());
|
||||||
binding.approvalRequired.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
binding.approvalRequired.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||||
|
final LiveData<Resource<Object>> resourceLiveData = isChecked ? viewModel.approvalRequired() : viewModel.approvalNotRequired();
|
||||||
|
handleSwitchChangeResource(resourceLiveData, buttonView);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,4 +112,19 @@ public interface DirectMessagesRepository {
|
|||||||
@POST("/api/v1/direct_v2/threads/{threadId}/deny_participant_requests/")
|
@POST("/api/v1/direct_v2/threads/{threadId}/deny_participant_requests/")
|
||||||
Call<DirectThreadDetailsChangeResponse> declineParticipantRequests(@Path("threadId") String threadId,
|
Call<DirectThreadDetailsChangeResponse> declineParticipantRequests(@Path("threadId") String threadId,
|
||||||
@FieldMap final Map<String, String> form);
|
@FieldMap final Map<String, String> form);
|
||||||
|
|
||||||
|
@FormUrlEncoded
|
||||||
|
@POST("/api/v1/direct_v2/threads/{threadId}/approval_required_for_new_members/")
|
||||||
|
Call<DirectThreadDetailsChangeResponse> approvalRequired(@Path("threadId") String threadId,
|
||||||
|
@FieldMap final Map<String, String> form);
|
||||||
|
|
||||||
|
@FormUrlEncoded
|
||||||
|
@POST("/api/v1/direct_v2/threads/{threadId}/approval_not_required_for_new_members/")
|
||||||
|
Call<DirectThreadDetailsChangeResponse> approvalNotRequired(@Path("threadId") String threadId,
|
||||||
|
@FieldMap final Map<String, String> form);
|
||||||
|
|
||||||
|
@FormUrlEncoded
|
||||||
|
@POST("/api/v1/direct_v2/threads/{threadId}/leave/")
|
||||||
|
Call<DirectThreadDetailsChangeResponse> leave(@Path("threadId") String threadId,
|
||||||
|
@FieldMap final Map<String, String> form);
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public class DirectThread implements Serializable {
|
|||||||
private final boolean isSpam;
|
private final boolean isSpam;
|
||||||
private final DirectItem lastPermanentItem;
|
private final DirectItem lastPermanentItem;
|
||||||
private final DirectThreadDirectStory directStory;
|
private final DirectThreadDirectStory directStory;
|
||||||
private final boolean approvalRequiredForNewMembers;
|
private boolean approvalRequiredForNewMembers;
|
||||||
|
|
||||||
public DirectThread(final String threadId,
|
public DirectThread(final String threadId,
|
||||||
final String threadV2Id,
|
final String threadV2Id,
|
||||||
@ -245,6 +245,10 @@ public class DirectThread implements Serializable {
|
|||||||
return approvalRequiredForNewMembers;
|
return approvalRequiredForNewMembers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setApprovalRequiredForNewMembers(final boolean approvalRequiredForNewMembers) {
|
||||||
|
this.approvalRequiredForNewMembers = approvalRequiredForNewMembers;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public DirectItem getFirstDirectItem() {
|
public DirectItem getFirstDirectItem() {
|
||||||
DirectItem firstItem = null;
|
DirectItem firstItem = null;
|
||||||
|
@ -508,6 +508,36 @@ public class DirectSettingsViewModel extends AndroidViewModel {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LiveData<Resource<Object>> approvalRequired() {
|
||||||
|
final MutableLiveData<Resource<Object>> data = new MutableLiveData<>();
|
||||||
|
data.postValue(Resource.loading(null));
|
||||||
|
if (thread.isApprovalRequiredForNewMembers()) {
|
||||||
|
data.postValue(Resource.success(new Object()));
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
final Call<DirectThreadDetailsChangeResponse> request = directMessagesService.approvalRequired(thread.getThreadId());
|
||||||
|
handleDetailsChangeRequest(data, request, () -> {
|
||||||
|
thread.setApprovalRequiredForNewMembers(true);
|
||||||
|
approvalRequiredToJoin.postValue(true);
|
||||||
|
});
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<Resource<Object>> approvalNotRequired() {
|
||||||
|
final MutableLiveData<Resource<Object>> data = new MutableLiveData<>();
|
||||||
|
data.postValue(Resource.loading(null));
|
||||||
|
if (!thread.isApprovalRequiredForNewMembers()) {
|
||||||
|
data.postValue(Resource.success(new Object()));
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
final Call<DirectThreadDetailsChangeResponse> request = directMessagesService.approvalNotRequired(thread.getThreadId());
|
||||||
|
handleDetailsChangeRequest(data, request, () -> {
|
||||||
|
thread.setApprovalRequiredForNewMembers(false);
|
||||||
|
approvalRequiredToJoin.postValue(false);
|
||||||
|
});
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
private interface OnSuccessAction {
|
private interface OnSuccessAction {
|
||||||
void onSuccess();
|
void onSuccess();
|
||||||
}
|
}
|
||||||
|
@ -377,4 +377,28 @@ public class DirectMessagesService extends BaseService {
|
|||||||
);
|
);
|
||||||
return repository.declineParticipantRequests(threadId, form);
|
return repository.declineParticipantRequests(threadId, form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Call<DirectThreadDetailsChangeResponse> approvalRequired(@NonNull final String threadId) {
|
||||||
|
final ImmutableMap<String, String> form = ImmutableMap.of(
|
||||||
|
"_csrftoken", csrfToken,
|
||||||
|
"_uuid", deviceUuid
|
||||||
|
);
|
||||||
|
return repository.approvalRequired(threadId, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Call<DirectThreadDetailsChangeResponse> approvalNotRequired(@NonNull final String threadId) {
|
||||||
|
final ImmutableMap<String, String> form = ImmutableMap.of(
|
||||||
|
"_csrftoken", csrfToken,
|
||||||
|
"_uuid", deviceUuid
|
||||||
|
);
|
||||||
|
return repository.approvalNotRequired(threadId, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Call<DirectThreadDetailsChangeResponse> leave(@NonNull final String threadId) {
|
||||||
|
final ImmutableMap<String, String> form = ImmutableMap.of(
|
||||||
|
"_csrftoken", csrfToken,
|
||||||
|
"_uuid", deviceUuid
|
||||||
|
);
|
||||||
|
return repository.leave(threadId, form);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user