support admin notifications

This commit is contained in:
sk 2023-01-25 18:27:57 +01:00
parent 5de23581fe
commit c12a6eaee6
12 changed files with 77 additions and 15 deletions

View File

@ -153,6 +153,8 @@ public class PushNotificationReceiver extends BroadcastReceiver{
case POLL -> R.drawable.ic_fluent_poll_24_filled;
case STATUS -> R.drawable.ic_fluent_chat_24_filled;
case UPDATE -> R.drawable.ic_fluent_history_24_filled;
case REPORT -> R.drawable.ic_fluent_warning_24_filled;
case SIGN_UP -> R.drawable.ic_fluent_person_available_24_filled;
});
}

View File

@ -2,6 +2,7 @@ package org.joinmastodon.android.fragments;
import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import com.squareup.otto.Subscribe;
@ -12,15 +13,19 @@ import org.joinmastodon.android.api.requests.markers.SaveMarkers;
import org.joinmastodon.android.api.session.AccountSessionManager;
import org.joinmastodon.android.events.PollUpdatedEvent;
import org.joinmastodon.android.events.RemoveAccountPostsEvent;
import org.joinmastodon.android.model.Account;
import org.joinmastodon.android.model.Notification;
import org.joinmastodon.android.model.PaginatedResponse;
import org.joinmastodon.android.model.Status;
import org.joinmastodon.android.ui.displayitems.AccountCardStatusDisplayItem;
import org.joinmastodon.android.ui.displayitems.AccountStatusDisplayItem;
import org.joinmastodon.android.ui.displayitems.HeaderStatusDisplayItem;
import org.joinmastodon.android.ui.displayitems.ImageStatusDisplayItem;
import org.joinmastodon.android.ui.displayitems.StatusDisplayItem;
import org.joinmastodon.android.ui.displayitems.TextStatusDisplayItem;
import org.joinmastodon.android.ui.utils.DiscoverInfoBannerHelper;
import org.joinmastodon.android.ui.utils.InsetStatusItemDecoration;
import org.joinmastodon.android.ui.utils.UiUtils;
import org.parceler.Parcels;
import java.util.ArrayList;
@ -71,6 +76,8 @@ public class NotificationsListFragment extends BaseStatusListFragment<Notificati
@Override
protected List<StatusDisplayItem> buildDisplayItems(Notification n){
Account reportTarget = n.report == null ? null : n.report.targetAccount == null ? null :
n.report.targetAccount;
String extraText=switch(n.type){
case FOLLOW -> getString(R.string.user_followed_you);
case FOLLOW_REQUEST -> getString(R.string.user_sent_follow_request);
@ -79,6 +86,8 @@ public class NotificationsListFragment extends BaseStatusListFragment<Notificati
case FAVORITE -> getString(R.string.user_favorited);
case POLL -> getString(R.string.poll_ended);
case UPDATE -> getString(R.string.sk_post_edited);
case SIGN_UP -> getString(R.string.sk_signed_up);
case REPORT -> getString(R.string.sk_reported);
};
HeaderStatusDisplayItem titleItem=extraText!=null ? new HeaderStatusDisplayItem(n.id, n.account, n.createdAt, this, accountID, n.status, extraText, n, null) : null;
if(n.status!=null){
@ -94,8 +103,13 @@ public class NotificationsListFragment extends BaseStatusListFragment<Notificati
items.add(0, titleItem);
return items;
}else if(titleItem!=null){
AccountCardStatusDisplayItem card=new AccountCardStatusDisplayItem(n.id, this, n.account, n);
return Arrays.asList(titleItem, card);
AccountCardStatusDisplayItem card=new AccountCardStatusDisplayItem(n.id, this,
reportTarget != null ? reportTarget : n.account, n);
TextStatusDisplayItem text = n.report != null && !TextUtils.isEmpty(n.report.comment) ?
new TextStatusDisplayItem(n.id, n.report.comment, this,
Status.ofFake(n.id, n.report.comment, n.createdAt), true) :
null;
return text == null ? Arrays.asList(titleItem, card) : Arrays.asList(titleItem, text, card);
}else{
return Collections.emptyList();
}
@ -164,6 +178,9 @@ public class NotificationsListFragment extends BaseStatusListFragment<Notificati
if(status.inReplyToAccountId!=null && knownAccounts.containsKey(status.inReplyToAccountId))
args.putParcelable("inReplyToAccount", Parcels.wrap(knownAccounts.get(status.inReplyToAccountId)));
Nav.go(getActivity(), ThreadFragment.class, args);
}else if(n.report != null){
String domain = AccountSessionManager.getInstance().getAccount(accountID).domain;
UiUtils.launchWebBrowser(getActivity(), "https://"+domain+"/admin/reports/"+n.report.id);
}else{
Bundle args=new Bundle();
args.putString("account", accountID);

View File

@ -42,17 +42,9 @@ public class Announcement extends BaseModel implements DisplayItemsParent {
}
public Status toStatus() {
Status s = new Status();
s.id = id;
s.mediaAttachments = List.of();
Status s = Status.ofFake(id, content, publishedAt);
s.createdAt = startsAt != null ? startsAt : publishedAt;
if (updatedAt != null) s.editedAt = updatedAt;
s.content = s.text = content;
s.spoilerText = "";
s.visibility = StatusPrivacy.PUBLIC;
s.mentions = List.of();
s.tags = List.of();
s.emojis = List.of();
return s;
}

View File

@ -18,8 +18,8 @@ public class Notification extends BaseModel implements DisplayItemsParent{
public Instant createdAt;
@RequiredField
public Account account;
public Status status;
public Report report;
@Override
public void postprocess() throws ObjectValidationException{
@ -50,6 +50,17 @@ public class Notification extends BaseModel implements DisplayItemsParent{
@SerializedName("status")
STATUS,
@SerializedName("update")
UPDATE
UPDATE,
@SerializedName("admin.sign_up")
SIGN_UP,
@SerializedName("admin.report")
REPORT
}
@Parcel
public static class Report {
public String id;
public String comment;
public Account targetAccount;
}
}

View File

@ -47,7 +47,11 @@ public class PushNotification extends BaseModel{
@SerializedName("status")
STATUS(R.string.sk_notification_type_status),
@SerializedName("update")
UPDATE(R.string.sk_notification_type_update);
UPDATE(R.string.sk_notification_type_update),
@SerializedName("admin.sign_up")
SIGN_UP(R.string.sk_sign_ups),
@SerializedName("admin.report")
REPORT(R.string.sk_new_reports);
@StringRes
public final int localizedName;

View File

@ -47,6 +47,14 @@ public class PushSubscription extends BaseModel implements Cloneable{
public boolean status;
public boolean update;
// set to true here because i didn't add any items for those to the settings
// (so i don't have to determine whether the user is an admin to show the items or not, and
// admins can still disable those through the android notifications settings)
@SerializedName("admin.sign_up")
public boolean adminSignUp = true;
@SerializedName("admin.report")
public boolean adminReport = true;
public static Alerts ofAll(){
Alerts alerts=new Alerts();
alerts.follow=alerts.favourite=alerts.reblog=alerts.mention=alerts.poll=alerts.status=alerts.update=true;
@ -63,6 +71,8 @@ public class PushSubscription extends BaseModel implements Cloneable{
", poll="+poll+
", status="+status+
", update="+update+
", adminSignUp="+adminSignUp+
", adminReport="+adminReport+
'}';
}

View File

@ -146,4 +146,18 @@ public class Status extends BaseModel implements DisplayItemsParent{
strippedText=HtmlParser.strip(content);
return strippedText;
}
public static Status ofFake(String id, String text, Instant createdAt) {
Status s = new Status();
s.id = id;
s.mediaAttachments = List.of();
s.createdAt = createdAt;
s.content = s.text = text;
s.spoilerText = "";
s.visibility = StatusPrivacy.PUBLIC;
s.mentions = List.of();
s.tags = List.of();
s.emojis = List.of();
return s;
}
}

View File

@ -326,7 +326,8 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{
extraText.setVisibility(View.VISIBLE);
extraText.setText(item.extraText);
}
more.setVisibility(item.inset ? View.GONE : View.VISIBLE);
more.setVisibility(item.inset || (item.notification != null && item.notification.report != null)
? View.GONE : View.VISIBLE);
avatar.setClickable(!item.inset);
avatar.setContentDescription(item.parentFragment.getString(R.string.avatar_description, item.user.acct));
if(currentRelationshipRequest!=null){

View File

@ -0,0 +1,3 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
<path android:pathData="M17.5 12c3.038 0 5.5 2.463 5.5 5.5 0 3.038-2.462 5.5-5.5 5.5-3.037 0-5.5-2.462-5.5-5.5 0-3.037 2.463-5.5 5.5-5.5zm-5.477 2C11.376 15.01 11 16.21 11 17.5c0 1.63 0.6 3.12 1.592 4.262-0.795 0.16-1.66 0.24-2.592 0.24-3.42 0-5.944-1.073-7.486-3.237-0.332-0.466-0.51-1.024-0.51-1.596v-0.92C2.004 15.007 3.01 14 4.253 14h7.77zm2.83 3.147c-0.194-0.196-0.51-0.196-0.706 0-0.196 0.195-0.196 0.512 0 0.707l2 2c0.195 0.195 0.512 0.195 0.707 0l4-4c0.195-0.195 0.195-0.512 0-0.707-0.195-0.196-0.512-0.196-0.707 0L16.5 18.793l-1.646-1.646zM10 2.005c2.762 0 5 2.239 5 5s-2.238 5-5 5c-2.761 0-5-2.239-5-5s2.239-5 5-5z" android:fillColor="@color/fluent_default_icon_tint"/>
</vector>

View File

@ -0,0 +1,3 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
<path android:pathData="M10.03 3.659c0.856-1.548 3.081-1.548 3.937 0l7.746 14.001c0.83 1.5-0.255 3.34-1.969 3.34H4.254c-1.715 0-2.8-1.84-1.97-3.34l7.746-14zM12.997 17c0-0.552-0.447-0.999-0.998-0.999C11.447 16.001 11 16.448 11 17s0.447 1 0.999 1c0.551 0 0.998-0.448 0.998-1zm-0.259-7.853C12.688 8.782 12.374 8.5 11.995 8.5c-0.415 0-0.75 0.336-0.75 0.75l0.004 4.502 0.007 0.102c0.05 0.366 0.364 0.648 0.743 0.648 0.415 0 0.75-0.337 0.75-0.751l-0.004-4.502-0.007-0.101z" android:fillColor="@color/fluent_default_icon_tint"/>
</vector>

View File

@ -31,6 +31,7 @@
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:paddingHorizontal="8dp"
android:paddingVertical="8dp"
android:gravity="center_vertical"

View File

@ -245,4 +245,8 @@
<string name="sk_settings_local_only_explanation">Your home instance must support local-only posting for this to work. Most modified versions of Mastodon do, but Mastodon doesnt.</string>
<string name="sk_settings_glitch_instance">Glitch local-only mode</string>
<string name="sk_settings_glitch_mode_explanation">Enable this if your home instance runs on Glitch. Not needed for Hometown or Akkoma.</string>
<string name="sk_signed_up">signed up</string>
<string name="sk_reported">reported</string>
<string name="sk_sign_ups">Users signing up</string>
<string name="sk_new_reports">New reports</string>
</resources>