feedback: add the feedback as a new section at end of the page

Addresses feedback on #5542. For auto-archiving of section
to work properly on our feedback page, the new sections need to
be created at the end of the page rather than at the top.

So, adjust the feedback addition logic to make it such that the
feedback is appended to the bottom of the page.
This commit is contained in:
Kaartic Sivaraam 2024-06-09 11:21:35 +05:30
parent 8fdfb8e6dc
commit 88a0f0c58d
5 changed files with 98 additions and 50 deletions

View file

@ -78,6 +78,28 @@ class PageEditClient(
} }
/**
* Appends a new section to the wiki page
* @param pageTitle Title of the page to edit
* @param sectionTitle Title of the new section that needs to be created
* @param sectionText The page content that is to be added to the section
* @param summary Edit summary
* @return whether the edit was successful
*/
fun createNewSection(pageTitle: String, sectionTitle: String, sectionText: String, summary: String): Observable<Boolean> {
return try {
pageEditInterface.postNewSection(pageTitle, summary, sectionTitle, sectionText, csrfTokenClient.getTokenBlocking())
.map { editResponse -> editResponse.edit()!!.editSucceeded() }
} catch (throwable: Throwable) {
if (throwable is InvalidLoginTokenException) {
throw throwable
} else {
Observable.just(false)
}
}
}
/** /**
* Set new labels to Wikibase server of commons * Set new labels to Wikibase server of commons
* @param summary Edit summary * @param summary Edit summary

View file

@ -74,6 +74,16 @@ interface PageEditInterface {
@Field("token") token: String @Field("token") token: String
): Observable<Edit> ): Observable<Edit>
@FormUrlEncoded
@Headers("Cache-Control: no-cache")
@POST(MW_API_PREFIX + "action=edit&section=new")
fun postNewSection(
@Field("title") title: String,
@Field("summary") summary: String,
@Field("sectiontitle") sectionTitle: String,
@Field("text") sectionText: String,
@Field("token") token: String
): Observable<Edit>
@FormUrlEncoded @FormUrlEncoded
@Headers("Cache-Control: no-cache") @Headers("Cache-Control: no-cache")

View file

@ -12,7 +12,8 @@ import java.util.Locale;
* from feedback information * from feedback information
*/ */
public class FeedbackContentCreator { public class FeedbackContentCreator {
private StringBuilder stringBuilder; private StringBuilder sectionTextBuilder;
private StringBuilder sectionTitleBuilder;
private Feedback feedback; private Feedback feedback;
private Context context; private Context context;
@ -28,71 +29,80 @@ public class FeedbackContentCreator {
public void init() { public void init() {
// Localization is not needed here, because this ends up on a page where developers read the feedback, so English is the most convenient. // Localization is not needed here, because this ends up on a page where developers read the feedback, so English is the most convenient.
stringBuilder = new StringBuilder(); /*
stringBuilder.append("== "); * Construct the feedback section title
stringBuilder.append("Feedback from "); */
stringBuilder.append(AccountUtil.getUserName(context)); sectionTitleBuilder = new StringBuilder();
stringBuilder.append(" for version "); sectionTitleBuilder.append("Feedback from ");
stringBuilder.append(feedback.getVersion()); sectionTitleBuilder.append(AccountUtil.getUserName(context));
stringBuilder.append(" =="); sectionTitleBuilder.append(" for version ");
stringBuilder.append("\n"); sectionTitleBuilder.append(feedback.getVersion());
stringBuilder.append(feedback.getTitle());
stringBuilder.append("\n"); /*
stringBuilder.append("\n"); * Construct the feedback section text
*/
sectionTextBuilder = new StringBuilder();
sectionTextBuilder.append("\n");
sectionTextBuilder.append(feedback.getTitle());
sectionTextBuilder.append("\n");
sectionTextBuilder.append("\n");
if (feedback.getApiLevel() != null) { if (feedback.getApiLevel() != null) {
stringBuilder.append("* "); sectionTextBuilder.append("* ");
stringBuilder.append(LangCodeUtils.getLocalizedResources(context, sectionTextBuilder.append(LangCodeUtils.getLocalizedResources(context,
Locale.ENGLISH).getString(R.string.api_level)); Locale.ENGLISH).getString(R.string.api_level));
stringBuilder.append(": "); sectionTextBuilder.append(": ");
stringBuilder.append(feedback.getApiLevel()); sectionTextBuilder.append(feedback.getApiLevel());
stringBuilder.append("\n"); sectionTextBuilder.append("\n");
} }
if (feedback.getAndroidVersion() != null) { if (feedback.getAndroidVersion() != null) {
stringBuilder.append("* "); sectionTextBuilder.append("* ");
stringBuilder.append(LangCodeUtils.getLocalizedResources(context, sectionTextBuilder.append(LangCodeUtils.getLocalizedResources(context,
Locale.ENGLISH).getString(R.string.android_version)); Locale.ENGLISH).getString(R.string.android_version));
stringBuilder.append(": "); sectionTextBuilder.append(": ");
stringBuilder.append(feedback.getAndroidVersion()); sectionTextBuilder.append(feedback.getAndroidVersion());
stringBuilder.append("\n"); sectionTextBuilder.append("\n");
} }
if (feedback.getDeviceManufacturer() != null) { if (feedback.getDeviceManufacturer() != null) {
stringBuilder.append("* "); sectionTextBuilder.append("* ");
stringBuilder.append(LangCodeUtils.getLocalizedResources(context, sectionTextBuilder.append(LangCodeUtils.getLocalizedResources(context,
Locale.ENGLISH).getString(R.string.device_manufacturer)); Locale.ENGLISH).getString(R.string.device_manufacturer));
stringBuilder.append(": "); sectionTextBuilder.append(": ");
stringBuilder.append(feedback.getDeviceManufacturer()); sectionTextBuilder.append(feedback.getDeviceManufacturer());
stringBuilder.append("\n"); sectionTextBuilder.append("\n");
} }
if (feedback.getDeviceModel() != null) { if (feedback.getDeviceModel() != null) {
stringBuilder.append("* "); sectionTextBuilder.append("* ");
stringBuilder.append(LangCodeUtils.getLocalizedResources(context, sectionTextBuilder.append(LangCodeUtils.getLocalizedResources(context,
Locale.ENGLISH).getString(R.string.device_model)); Locale.ENGLISH).getString(R.string.device_model));
stringBuilder.append(": "); sectionTextBuilder.append(": ");
stringBuilder.append(feedback.getDeviceModel()); sectionTextBuilder.append(feedback.getDeviceModel());
stringBuilder.append("\n"); sectionTextBuilder.append("\n");
} }
if (feedback.getDevice() != null) { if (feedback.getDevice() != null) {
stringBuilder.append("* "); sectionTextBuilder.append("* ");
stringBuilder.append(LangCodeUtils.getLocalizedResources(context, sectionTextBuilder.append(LangCodeUtils.getLocalizedResources(context,
Locale.ENGLISH).getString(R.string.device_name)); Locale.ENGLISH).getString(R.string.device_name));
stringBuilder.append(": "); sectionTextBuilder.append(": ");
stringBuilder.append(feedback.getDevice()); sectionTextBuilder.append(feedback.getDevice());
stringBuilder.append("\n"); sectionTextBuilder.append("\n");
} }
if (feedback.getNetworkType() != null) { if (feedback.getNetworkType() != null) {
stringBuilder.append("* "); sectionTextBuilder.append("* ");
stringBuilder.append(LangCodeUtils.getLocalizedResources(context, sectionTextBuilder.append(LangCodeUtils.getLocalizedResources(context,
Locale.ENGLISH).getString(R.string.network_type)); Locale.ENGLISH).getString(R.string.network_type));
stringBuilder.append(": "); sectionTextBuilder.append(": ");
stringBuilder.append(feedback.getNetworkType()); sectionTextBuilder.append(feedback.getNetworkType());
stringBuilder.append("\n"); sectionTextBuilder.append("\n");
} }
stringBuilder.append("~~~~"); sectionTextBuilder.append("~~~~");
stringBuilder.append("\n"); sectionTextBuilder.append("\n");
} }
@Override public String getSectionText() {
public String toString() { return sectionTextBuilder.toString();
return stringBuilder.toString(); }
public String getSectionTitle() {
return sectionTitleBuilder.toString();
} }
} }

View file

@ -153,8 +153,13 @@ public class MoreBottomSheetFragment extends BottomSheetDialogFragment {
void uploadFeedback(final Feedback feedback) { void uploadFeedback(final Feedback feedback) {
final FeedbackContentCreator feedbackContentCreator = new FeedbackContentCreator(getContext(), feedback); final FeedbackContentCreator feedbackContentCreator = new FeedbackContentCreator(getContext(), feedback);
Single<Boolean> single = final Single<Boolean> single =
pageEditClient.prependEdit("Commons:Mobile_app/Feedback", feedbackContentCreator.toString(), "Summary") pageEditClient.createNewSection(
"Commons:Mobile_app/Feedback",
feedbackContentCreator.getSectionTitle(),
feedbackContentCreator.getSectionText(),
"Summary"
)
.flatMapSingle(result -> Single.just(result)) .flatMapSingle(result -> Single.just(result))
.firstOrError(); .firstOrError();

View file

@ -34,7 +34,8 @@ class FeedbackContentCreatorUnitTests {
fun testToString() { fun testToString() {
feedback = Feedback("123", "apiLevel", "title", "androidVersion", "deviceModel", "mfg", "deviceName", "wifi") feedback = Feedback("123", "apiLevel", "title", "androidVersion", "deviceModel", "mfg", "deviceName", "wifi")
creator = FeedbackContentCreator(context, feedback) creator = FeedbackContentCreator(context, feedback)
Assert.assertNotNull(creator.toString()) Assert.assertNotNull(creator.getSectionText())
Assert.assertNotNull(creator.getSectionTitle())
} }
} }