make each notification type toggleable
This commit is contained in:
parent
486230a335
commit
3bf81ee0fa
@ -17,8 +17,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { showNotification } from "@api/Notifications";
|
import { showNotification } from "@api/Notifications";
|
||||||
|
import { definePluginSettings } from "@api/settings";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { FluxDispatcher, UserUtils } from "@webpack/common";
|
import { FluxDispatcher, UserUtils } from "@webpack/common";
|
||||||
import { User } from "discord-types/general";
|
import { User } from "discord-types/general";
|
||||||
|
|
||||||
@ -42,6 +43,100 @@ interface RelationshipPayload {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const settings = definePluginSettings({
|
||||||
|
friend: {
|
||||||
|
type: OptionType.SELECT,
|
||||||
|
description: "Show a notification when a friend is added or removed",
|
||||||
|
options: [{
|
||||||
|
label: "Friend added and removed",
|
||||||
|
value: "ALL",
|
||||||
|
default: true,
|
||||||
|
}, {
|
||||||
|
label: "Only When added",
|
||||||
|
value: "CREATE",
|
||||||
|
}, {
|
||||||
|
label: "Only when removed",
|
||||||
|
value: "REMOVE",
|
||||||
|
}, {
|
||||||
|
label: "No notifications",
|
||||||
|
value: "NONE",
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
outgoingRequest: {
|
||||||
|
type: OptionType.SELECT,
|
||||||
|
description: "Show a notification when you send or cancel a friend request",
|
||||||
|
options: [{
|
||||||
|
label: "Request sent and cancelled",
|
||||||
|
value: "ALL",
|
||||||
|
default: true,
|
||||||
|
}, {
|
||||||
|
label: "Only when sent",
|
||||||
|
value: "CREATE",
|
||||||
|
}, {
|
||||||
|
label: "Only when cancelled",
|
||||||
|
value: "REMOVE",
|
||||||
|
}, {
|
||||||
|
label: "No notifications",
|
||||||
|
value: "NONE",
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
incomingRequest: {
|
||||||
|
type: OptionType.SELECT,
|
||||||
|
description: "Show a notification when an incoming request is received or cancelled",
|
||||||
|
options: [{
|
||||||
|
label: "Request received and cancelled",
|
||||||
|
value: "ALL",
|
||||||
|
default: true,
|
||||||
|
}, {
|
||||||
|
label: "Only when received",
|
||||||
|
value: "CREATE",
|
||||||
|
}, {
|
||||||
|
label: "Only when cancelled",
|
||||||
|
value: "REMOVE",
|
||||||
|
}, {
|
||||||
|
label: "No notifications",
|
||||||
|
value: "NONE",
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
block: {
|
||||||
|
type: OptionType.SELECT,
|
||||||
|
description: "Show a notification when you block or unblock a user",
|
||||||
|
options: [{
|
||||||
|
label: "Blocked and Unblocked",
|
||||||
|
value: "ALL",
|
||||||
|
default: true,
|
||||||
|
}, {
|
||||||
|
label: "Only when blocking",
|
||||||
|
value: "CREATE",
|
||||||
|
}, {
|
||||||
|
label: "Only when unblocking",
|
||||||
|
value: "REMOVE",
|
||||||
|
}, {
|
||||||
|
label: "No notifications",
|
||||||
|
value: "NONE",
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default definePlugin({
|
||||||
|
name: "RelationshipNotifier",
|
||||||
|
authors: [Devs.Megu],
|
||||||
|
description: "Receive notifications for friend requests, removals, blocks, etc.",
|
||||||
|
settings,
|
||||||
|
|
||||||
|
start() {
|
||||||
|
FluxDispatcher.subscribe("RELATIONSHIP_ADD", onRelationshipUpdate);
|
||||||
|
FluxDispatcher.subscribe("RELATIONSHIP_UPDATE", onRelationshipUpdate);
|
||||||
|
FluxDispatcher.subscribe("RELATIONSHIP_REMOVE", onRelationshipRemove);
|
||||||
|
},
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
FluxDispatcher.unsubscribe("RELATIONSHIP_ADD", onRelationshipUpdate);
|
||||||
|
FluxDispatcher.unsubscribe("RELATIONSHIP_UPDATE", onRelationshipUpdate);
|
||||||
|
FluxDispatcher.unsubscribe("RELATIONSHIP_REMOVE", onRelationshipRemove);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
async function onRelationshipUpdate({ relationship }: RelationshipPayload) {
|
async function onRelationshipUpdate({ relationship }: RelationshipPayload) {
|
||||||
if (!relationship.id) return;
|
if (!relationship.id) return;
|
||||||
const user = await UserUtils.fetchUser(relationship.id);
|
const user = await UserUtils.fetchUser(relationship.id);
|
||||||
@ -56,6 +151,7 @@ async function onRelationshipUpdate({ relationship }: RelationshipPayload) {
|
|||||||
|
|
||||||
switch (relationship.type) {
|
switch (relationship.type) {
|
||||||
case RelationshipType.FRIEND: {
|
case RelationshipType.FRIEND: {
|
||||||
|
if (!["ALL", "CREATE"].includes(settings.store.friend)) break;
|
||||||
showNotification({
|
showNotification({
|
||||||
title: "Friend Added",
|
title: "Friend Added",
|
||||||
body: `${user.username} is now your friend.`,
|
body: `${user.username} is now your friend.`,
|
||||||
@ -65,6 +161,7 @@ async function onRelationshipUpdate({ relationship }: RelationshipPayload) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RelationshipType.PENDING_INCOMING: {
|
case RelationshipType.PENDING_INCOMING: {
|
||||||
|
if (!["ALL", "CREATE"].includes(settings.store.incomingRequest)) break;
|
||||||
showNotification({
|
showNotification({
|
||||||
title: "Friend Request Received",
|
title: "Friend Request Received",
|
||||||
body: `${user.username} sent you a friend request.`,
|
body: `${user.username} sent you a friend request.`,
|
||||||
@ -74,6 +171,7 @@ async function onRelationshipUpdate({ relationship }: RelationshipPayload) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RelationshipType.PENDING_OUTGOING: {
|
case RelationshipType.PENDING_OUTGOING: {
|
||||||
|
if (!["ALL", "CREATE"].includes(settings.store.outgoingRequest)) break;
|
||||||
showNotification({
|
showNotification({
|
||||||
title: "Friend Request Sent",
|
title: "Friend Request Sent",
|
||||||
body: `You sent a friend request to ${user.username}`,
|
body: `You sent a friend request to ${user.username}`,
|
||||||
@ -83,6 +181,7 @@ async function onRelationshipUpdate({ relationship }: RelationshipPayload) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RelationshipType.BLOCKED: {
|
case RelationshipType.BLOCKED: {
|
||||||
|
if (!["ALL", "CREATE"].includes(settings.store.block)) break;
|
||||||
showNotification({
|
showNotification({
|
||||||
title: "User Blocked",
|
title: "User Blocked",
|
||||||
body: `You just blocked ${user.username}`,
|
body: `You just blocked ${user.username}`,
|
||||||
@ -108,6 +207,7 @@ async function onRelationshipRemove({ relationship }: RelationshipPayload) {
|
|||||||
|
|
||||||
switch (relationship.type) {
|
switch (relationship.type) {
|
||||||
case RelationshipType.FRIEND: {
|
case RelationshipType.FRIEND: {
|
||||||
|
if (!["ALL", "REMOVE"].includes(settings.store.friend)) break;
|
||||||
showNotification({
|
showNotification({
|
||||||
title: "Friend Removed",
|
title: "Friend Removed",
|
||||||
body: `${user.username} is no longer on your friends list.`,
|
body: `${user.username} is no longer on your friends list.`,
|
||||||
@ -117,6 +217,7 @@ async function onRelationshipRemove({ relationship }: RelationshipPayload) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RelationshipType.PENDING_INCOMING: {
|
case RelationshipType.PENDING_INCOMING: {
|
||||||
|
if (!["ALL", "REMOVE"].includes(settings.store.incomingRequest)) break;
|
||||||
showNotification({
|
showNotification({
|
||||||
title: "Friend Request Cancelled",
|
title: "Friend Request Cancelled",
|
||||||
body: `${user.username} cancelled their friend request.`,
|
body: `${user.username} cancelled their friend request.`,
|
||||||
@ -126,6 +227,7 @@ async function onRelationshipRemove({ relationship }: RelationshipPayload) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RelationshipType.PENDING_OUTGOING: {
|
case RelationshipType.PENDING_OUTGOING: {
|
||||||
|
if (!["ALL", "REMOVE"].includes(settings.store.outgoingRequest)) break;
|
||||||
showNotification({
|
showNotification({
|
||||||
title: "Friend Request Cancelled",
|
title: "Friend Request Cancelled",
|
||||||
body: `You cancelled your friend request to ${user.username}`,
|
body: `You cancelled your friend request to ${user.username}`,
|
||||||
@ -135,6 +237,7 @@ async function onRelationshipRemove({ relationship }: RelationshipPayload) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RelationshipType.BLOCKED: {
|
case RelationshipType.BLOCKED: {
|
||||||
|
if (!["ALL", "REMOVE"].includes(settings.store.block)) break;
|
||||||
showNotification({
|
showNotification({
|
||||||
title: "User Unblocked",
|
title: "User Unblocked",
|
||||||
body: `You just unblocked ${user.username}`,
|
body: `You just unblocked ${user.username}`,
|
||||||
@ -145,21 +248,3 @@ async function onRelationshipRemove({ relationship }: RelationshipPayload) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default definePlugin({
|
|
||||||
name: "RelationshipNotifier",
|
|
||||||
authors: [Devs.Megu],
|
|
||||||
description: "Receive notifications for friend requests, removals, blocks, etc.",
|
|
||||||
|
|
||||||
start() {
|
|
||||||
FluxDispatcher.subscribe("RELATIONSHIP_ADD", onRelationshipUpdate);
|
|
||||||
FluxDispatcher.subscribe("RELATIONSHIP_UPDATE", onRelationshipUpdate);
|
|
||||||
FluxDispatcher.subscribe("RELATIONSHIP_REMOVE", onRelationshipRemove);
|
|
||||||
},
|
|
||||||
|
|
||||||
stop() {
|
|
||||||
FluxDispatcher.unsubscribe("RELATIONSHIP_ADD", onRelationshipUpdate);
|
|
||||||
FluxDispatcher.unsubscribe("RELATIONSHIP_UPDATE", onRelationshipUpdate);
|
|
||||||
FluxDispatcher.unsubscribe("RELATIONSHIP_REMOVE", onRelationshipRemove);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
Loading…
Reference in New Issue
Block a user