Skip to content

Commit 38cefcf

Browse files
committed
add bump server & pinned message push notification types
1 parent f8e19c8 commit 38cefcf

1 file changed

Lines changed: 37 additions & 22 deletions

File tree

src/pushNotifications.ts

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import notifee, {
44
AndroidVisibility,
55
} from '@notifee/react-native';
66
import env from './env';
7-
import {getUserId} from './EncryptedStore';
8-
import {dmChannelMatch, serverChannelMatch} from './UrlPatternMatchers';
9-
import {currentUrl} from './components/CustomWebView';
7+
import { getUserId } from './EncryptedStore';
8+
import { dmChannelMatch, serverChannelMatch } from './UrlPatternMatchers';
9+
import { currentUrl } from './components/CustomWebView';
1010

1111
export enum MessageType {
1212
CONTENT = 0,
@@ -15,6 +15,8 @@ export enum MessageType {
1515
KICK_USER = 3,
1616
BAN_USER = 4,
1717
STARTED_CALL = 5,
18+
BUMP_SERVER = 6,
19+
PINNED_MESSAGE = 7,
1820
}
1921

2022
const ANDROID_CHANNELS = {
@@ -64,7 +66,7 @@ export async function handlePushNotification(
6466
isBackground: boolean,
6567
) {
6668
if (!isBackground) {
67-
const {channelId} =
69+
const { channelId } =
6870
dmChannelMatch(currentUrl) || serverChannelMatch(currentUrl) || {};
6971
if (channelId && data.channelId === channelId) {
7072
return;
@@ -79,6 +81,29 @@ export async function handlePushNotification(
7981
}
8082
}
8183

84+
function getNotificationText(type: number) {
85+
if (type === MessageType.JOIN_SERVER) {
86+
return 'has joined the server.';
87+
}
88+
if (type === MessageType.LEAVE_SERVER) {
89+
return 'has left the server.';
90+
}
91+
if (type === MessageType.BAN_USER) {
92+
return 'has been banned.';
93+
}
94+
if (type === MessageType.KICK_USER) {
95+
return 'has been kicked.';
96+
}
97+
if (type === MessageType.STARTED_CALL) {
98+
return 'has started a call.';
99+
}
100+
if (type === MessageType.BUMP_SERVER) {
101+
return 'has bumped the server.';
102+
}
103+
if (type === MessageType.PINNED_MESSAGE) {
104+
return 'has pinned a message.';
105+
}
106+
}
82107
export async function showServerPushNotification(data: ServerNotificationData) {
83108
const existingNotification = await notifee
84109
.getDisplayedNotifications()
@@ -107,20 +132,9 @@ export async function showServerPushNotification(data: ServerNotificationData) {
107132

108133
const type = parseInt(data.type);
109134

110-
if (type === MessageType.JOIN_SERVER) {
111-
content = 'has joined the server.';
112-
}
113-
if (type === MessageType.LEAVE_SERVER) {
114-
content = 'has left the server.';
115-
}
116-
if (type === MessageType.BAN_USER) {
117-
content = 'has been banned.';
118-
}
119-
if (type === MessageType.KICK_USER) {
120-
content = 'has been kicked.';
121-
}
122-
if (type === MessageType.STARTED_CALL) {
123-
content = 'has started a call.';
135+
const typeText = getNotificationText(type);
136+
if (typeText) {
137+
content = typeText;
124138
}
125139

126140
let newLines = [username, content];
@@ -146,7 +160,7 @@ export async function showServerPushNotification(data: ServerNotificationData) {
146160
circularLargeIcon: true,
147161
channelId: ANDROID_CHANNELS.serverMessages,
148162
...(data.sAvatar
149-
? {largeIcon: `${env.NERIMITY_CDN}${data.sAvatar}`}
163+
? { largeIcon: `${env.NERIMITY_CDN}${data.sAvatar}` }
150164
: undefined),
151165
style: {
152166
type: AndroidStyle.INBOX,
@@ -183,8 +197,9 @@ export async function showDMNotificationData(data: DMNotificationData) {
183197
}
184198

185199
const type = parseInt(data.type);
186-
if (type === MessageType.STARTED_CALL) {
187-
newLine = 'has started a call.';
200+
const typeText = getNotificationText(type);
201+
if (typeText) {
202+
newLine = typeText;
188203
}
189204

190205
// Display a notification
@@ -207,7 +222,7 @@ export async function showDMNotificationData(data: DMNotificationData) {
207222
circularLargeIcon: true,
208223
channelId: ANDROID_CHANNELS.dmMessages,
209224
...(data.uAvatar
210-
? {largeIcon: `${env.NERIMITY_CDN}${data.uAvatar}`}
225+
? { largeIcon: `${env.NERIMITY_CDN}${data.uAvatar}` }
211226
: undefined),
212227
style: {
213228
type: AndroidStyle.INBOX,

0 commit comments

Comments
 (0)