Skip to content
This repository was archived by the owner on May 30, 2025. It is now read-only.

Commit c12a6ea

Browse files
committed
support admin notifications
1 parent 5de2358 commit c12a6ea

12 files changed

+77
-15
lines changed

mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ private void notify(Context context, PushNotification pn, String accountID, org.
153153
case POLL -> R.drawable.ic_fluent_poll_24_filled;
154154
case STATUS -> R.drawable.ic_fluent_chat_24_filled;
155155
case UPDATE -> R.drawable.ic_fluent_history_24_filled;
156+
case REPORT -> R.drawable.ic_fluent_warning_24_filled;
157+
case SIGN_UP -> R.drawable.ic_fluent_person_available_24_filled;
156158
});
157159
}
158160

mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.app.Activity;
44
import android.os.Bundle;
5+
import android.text.TextUtils;
56
import android.view.View;
67

78
import com.squareup.otto.Subscribe;
@@ -12,15 +13,19 @@
1213
import org.joinmastodon.android.api.session.AccountSessionManager;
1314
import org.joinmastodon.android.events.PollUpdatedEvent;
1415
import org.joinmastodon.android.events.RemoveAccountPostsEvent;
16+
import org.joinmastodon.android.model.Account;
1517
import org.joinmastodon.android.model.Notification;
1618
import org.joinmastodon.android.model.PaginatedResponse;
1719
import org.joinmastodon.android.model.Status;
1820
import org.joinmastodon.android.ui.displayitems.AccountCardStatusDisplayItem;
21+
import org.joinmastodon.android.ui.displayitems.AccountStatusDisplayItem;
1922
import org.joinmastodon.android.ui.displayitems.HeaderStatusDisplayItem;
2023
import org.joinmastodon.android.ui.displayitems.ImageStatusDisplayItem;
2124
import org.joinmastodon.android.ui.displayitems.StatusDisplayItem;
25+
import org.joinmastodon.android.ui.displayitems.TextStatusDisplayItem;
2226
import org.joinmastodon.android.ui.utils.DiscoverInfoBannerHelper;
2327
import org.joinmastodon.android.ui.utils.InsetStatusItemDecoration;
28+
import org.joinmastodon.android.ui.utils.UiUtils;
2429
import org.parceler.Parcels;
2530

2631
import java.util.ArrayList;
@@ -71,6 +76,8 @@ public void onRefresh() {
7176

7277
@Override
7378
protected List<StatusDisplayItem> buildDisplayItems(Notification n){
79+
Account reportTarget = n.report == null ? null : n.report.targetAccount == null ? null :
80+
n.report.targetAccount;
7481
String extraText=switch(n.type){
7582
case FOLLOW -> getString(R.string.user_followed_you);
7683
case FOLLOW_REQUEST -> getString(R.string.user_sent_follow_request);
@@ -79,6 +86,8 @@ protected List<StatusDisplayItem> buildDisplayItems(Notification n){
7986
case FAVORITE -> getString(R.string.user_favorited);
8087
case POLL -> getString(R.string.poll_ended);
8188
case UPDATE -> getString(R.string.sk_post_edited);
89+
case SIGN_UP -> getString(R.string.sk_signed_up);
90+
case REPORT -> getString(R.string.sk_reported);
8291
};
8392
HeaderStatusDisplayItem titleItem=extraText!=null ? new HeaderStatusDisplayItem(n.id, n.account, n.createdAt, this, accountID, n.status, extraText, n, null) : null;
8493
if(n.status!=null){
@@ -94,8 +103,13 @@ protected List<StatusDisplayItem> buildDisplayItems(Notification n){
94103
items.add(0, titleItem);
95104
return items;
96105
}else if(titleItem!=null){
97-
AccountCardStatusDisplayItem card=new AccountCardStatusDisplayItem(n.id, this, n.account, n);
98-
return Arrays.asList(titleItem, card);
106+
AccountCardStatusDisplayItem card=new AccountCardStatusDisplayItem(n.id, this,
107+
reportTarget != null ? reportTarget : n.account, n);
108+
TextStatusDisplayItem text = n.report != null && !TextUtils.isEmpty(n.report.comment) ?
109+
new TextStatusDisplayItem(n.id, n.report.comment, this,
110+
Status.ofFake(n.id, n.report.comment, n.createdAt), true) :
111+
null;
112+
return text == null ? Arrays.asList(titleItem, card) : Arrays.asList(titleItem, text, card);
99113
}else{
100114
return Collections.emptyList();
101115
}
@@ -164,6 +178,9 @@ public void onItemClick(String id){
164178
if(status.inReplyToAccountId!=null && knownAccounts.containsKey(status.inReplyToAccountId))
165179
args.putParcelable("inReplyToAccount", Parcels.wrap(knownAccounts.get(status.inReplyToAccountId)));
166180
Nav.go(getActivity(), ThreadFragment.class, args);
181+
}else if(n.report != null){
182+
String domain = AccountSessionManager.getInstance().getAccount(accountID).domain;
183+
UiUtils.launchWebBrowser(getActivity(), "https://"+domain+"/admin/reports/"+n.report.id);
167184
}else{
168185
Bundle args=new Bundle();
169186
args.putString("account", accountID);

mastodon/src/main/java/org/joinmastodon/android/model/Announcement.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,9 @@ public String toString() {
4242
}
4343

4444
public Status toStatus() {
45-
Status s = new Status();
46-
s.id = id;
47-
s.mediaAttachments = List.of();
45+
Status s = Status.ofFake(id, content, publishedAt);
4846
s.createdAt = startsAt != null ? startsAt : publishedAt;
4947
if (updatedAt != null) s.editedAt = updatedAt;
50-
s.content = s.text = content;
51-
s.spoilerText = "";
52-
s.visibility = StatusPrivacy.PUBLIC;
53-
s.mentions = List.of();
54-
s.tags = List.of();
55-
s.emojis = List.of();
5648
return s;
5749
}
5850

mastodon/src/main/java/org/joinmastodon/android/model/Notification.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public class Notification extends BaseModel implements DisplayItemsParent{
1818
public Instant createdAt;
1919
@RequiredField
2020
public Account account;
21-
2221
public Status status;
22+
public Report report;
2323

2424
@Override
2525
public void postprocess() throws ObjectValidationException{
@@ -50,6 +50,17 @@ public enum Type{
5050
@SerializedName("status")
5151
STATUS,
5252
@SerializedName("update")
53-
UPDATE
53+
UPDATE,
54+
@SerializedName("admin.sign_up")
55+
SIGN_UP,
56+
@SerializedName("admin.report")
57+
REPORT
58+
}
59+
60+
@Parcel
61+
public static class Report {
62+
public String id;
63+
public String comment;
64+
public Account targetAccount;
5465
}
5566
}

mastodon/src/main/java/org/joinmastodon/android/model/PushNotification.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ public enum Type{
4747
@SerializedName("status")
4848
STATUS(R.string.sk_notification_type_status),
4949
@SerializedName("update")
50-
UPDATE(R.string.sk_notification_type_update);
50+
UPDATE(R.string.sk_notification_type_update),
51+
@SerializedName("admin.sign_up")
52+
SIGN_UP(R.string.sk_sign_ups),
53+
@SerializedName("admin.report")
54+
REPORT(R.string.sk_new_reports);
5155

5256
@StringRes
5357
public final int localizedName;

mastodon/src/main/java/org/joinmastodon/android/model/PushSubscription.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ public static class Alerts implements Cloneable{
4747
public boolean status;
4848
public boolean update;
4949

50+
// set to true here because i didn't add any items for those to the settings
51+
// (so i don't have to determine whether the user is an admin to show the items or not, and
52+
// admins can still disable those through the android notifications settings)
53+
@SerializedName("admin.sign_up")
54+
public boolean adminSignUp = true;
55+
@SerializedName("admin.report")
56+
public boolean adminReport = true;
57+
5058
public static Alerts ofAll(){
5159
Alerts alerts=new Alerts();
5260
alerts.follow=alerts.favourite=alerts.reblog=alerts.mention=alerts.poll=alerts.status=alerts.update=true;
@@ -63,6 +71,8 @@ public String toString(){
6371
", poll="+poll+
6472
", status="+status+
6573
", update="+update+
74+
", adminSignUp="+adminSignUp+
75+
", adminReport="+adminReport+
6676
'}';
6777
}
6878

mastodon/src/main/java/org/joinmastodon/android/model/Status.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,18 @@ public String getStrippedText(){
146146
strippedText=HtmlParser.strip(content);
147147
return strippedText;
148148
}
149+
150+
public static Status ofFake(String id, String text, Instant createdAt) {
151+
Status s = new Status();
152+
s.id = id;
153+
s.mediaAttachments = List.of();
154+
s.createdAt = createdAt;
155+
s.content = s.text = text;
156+
s.spoilerText = "";
157+
s.visibility = StatusPrivacy.PUBLIC;
158+
s.mentions = List.of();
159+
s.tags = List.of();
160+
s.emojis = List.of();
161+
return s;
162+
}
149163
}

mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ else if (item.status != null && item.status.editedAt != null)
326326
extraText.setVisibility(View.VISIBLE);
327327
extraText.setText(item.extraText);
328328
}
329-
more.setVisibility(item.inset ? View.GONE : View.VISIBLE);
329+
more.setVisibility(item.inset || (item.notification != null && item.notification.report != null)
330+
? View.GONE : View.VISIBLE);
330331
avatar.setClickable(!item.inset);
331332
avatar.setContentDescription(item.parentFragment.getString(R.string.avatar_description, item.user.acct));
332333
if(currentRelationshipRequest!=null){
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
2+
<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"/>
3+
</vector>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
2+
<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"/>
3+
</vector>

0 commit comments

Comments
 (0)