diff --git a/src/App.js b/src/App.js
index 238d13b..f943e3f 100644
--- a/src/App.js
+++ b/src/App.js
@@ -37,6 +37,7 @@ const App = () => (
/>
+
);
diff --git a/src/components/users.js b/src/components/users.js
index 38dd01f..fd5e9e9 100644
--- a/src/components/users.js
+++ b/src/components/users.js
@@ -1,6 +1,8 @@
-import React, { Fragment } from "react";
+import React, { Fragment, useState } from "react";
import PersonPinIcon from "@material-ui/icons/PersonPin";
import SettingsInputComponentIcon from "@material-ui/icons/SettingsInputComponent";
+import MessageIcon from "@material-ui/icons/Message";
+import IconCancel from "@material-ui/icons/Cancel";
import {
ArrayInput,
ArrayField,
@@ -29,12 +31,108 @@ import {
regex,
useTranslate,
Pagination,
+ Button,
+ useNotify,
+ useUnselectAll,
+ required,
+ fetchStart,
+ fetchEnd,
} from "react-admin";
+import Dialog from "@material-ui/core/Dialog";
+import DialogContent from "@material-ui/core/DialogContent";
+import DialogContentText from "@material-ui/core/DialogContentText";
+import DialogTitle from "@material-ui/core/DialogTitle";
+import dataProvider from "../synapse/dataProvider.js";
const UserPagination = props => (
);
+const ServernoticesButton = ({ record, selectedIds, method = "single" }) => {
+ const [open, setOpen] = useState(false);
+ const notify = useNotify();
+ const unselectAll = useUnselectAll();
+ const translate = useTranslate();
+ const handleDialogOpen = () => setOpen(true);
+ const handleDialogClose = () => setOpen(false);
+ const handleConfirm = values => {
+ fetchStart();
+
+ if (method === "multi") {
+ console.log(method);
+ dataProvider
+ .updateMany("servernotices", { ids: selectedIds, data: values })
+ .then(({ response }) => {
+ notify("resources.servernotices.action.send_success");
+ unselectAll("users");
+ })
+ .catch(error => {
+ notify("resources.servernotices.action.send_failure", "error");
+ })
+ .finally(() => {
+ fetchEnd();
+ });
+ } else {
+ dataProvider
+ .update("servernotices", { data: { ...values, ...{ id: record.id } } })
+ .then(({ response }) => {
+ notify("resources.servernotices.action.send_success");
+ })
+ .catch(error => {
+ notify("resources.servernotices.action.send_failure", "error");
+ })
+ .finally(() => {
+ fetchEnd();
+ });
+ }
+ handleDialogClose();
+ };
+
+ const ServernoticesToolbar = props => (
+
+
+
+
+ );
+
+ return (
+
+
+
+
+ );
+};
+
const UserFilter = props => (
@@ -50,6 +148,7 @@ const UserBulkActionButtons = props => {
const translate = useTranslate();
return (
+
{
label="resources.users.action.erase"
title={translate("resources.users.helper.erase")}
/>
+
);
};
diff --git a/src/i18n/de.js b/src/i18n/de.js
index 07a83fe..cf09132 100644
--- a/src/i18n/de.js
+++ b/src/i18n/de.js
@@ -60,5 +60,21 @@ export default {
user_agent: "User Agent",
},
},
+ servernotices: {
+ name: "Serverbenachrichtigungen",
+ send: "Servernachricht versenden",
+ fields: {
+ body: "Nachricht",
+ },
+ action: {
+ send: "Sende Nachricht",
+ send_success: "Nachricht erfolgreich versendet.",
+ send_failure: "Beim Versenden ist ein Fehler aufgetreten.",
+ },
+ helper: {
+ send:
+ 'Sendet eine Serverbenachrichtigung an die ausgewählten Nutzer. Hierfür muss das Feature "Server Notices" auf dem Server aktiviert sein.',
+ },
+ },
},
};
diff --git a/src/i18n/en.js b/src/i18n/en.js
index 7bb739a..54e20c9 100644
--- a/src/i18n/en.js
+++ b/src/i18n/en.js
@@ -60,5 +60,21 @@ export default {
user_agent: "User agent",
},
},
+ servernotices: {
+ name: "Server Notices",
+ send: "Send server notices",
+ fields: {
+ body: "Nachricht",
+ },
+ action: {
+ send: "Send note",
+ send_success: "Note sent successfully.",
+ send_failure: "An error has occurred.",
+ },
+ helper: {
+ send:
+ 'Sends a server notices to the selected users. For this, the feature "Server Notices" must be activated on the server.',
+ },
+ },
},
};
diff --git a/src/synapse/dataProvider.js b/src/synapse/dataProvider.js
index 303d25c..448c225 100644
--- a/src/synapse/dataProvider.js
+++ b/src/synapse/dataProvider.js
@@ -57,6 +57,24 @@ const resourceMap = {
}),
data: "connections",
},
+ servernotices: {
+ map: s => ({
+ ...s,
+ id: s.user_id,
+ }),
+ data: "servernotices",
+ update: (id, params) => ({
+ endpoint: `/_synapse/admin/v1/send_server_notice`,
+ body: {
+ user_id: `${id}`,
+ content: {
+ msgtype: "m.text",
+ body: `${params.body}`,
+ },
+ },
+ method: "POST",
+ }),
+ },
};
function filterNullValues(key, value) {
@@ -146,7 +164,13 @@ const dataProvider = {
return jsonClient(url).then(({ headers, json }) => ({
data: json,
- total: parseInt(headers.get("content-range").split("/").pop(), 10),
+ total: parseInt(
+ headers
+ .get("content-range")
+ .split("/")
+ .pop(),
+ 10
+ ),
}));
},
@@ -157,13 +181,24 @@ const dataProvider = {
const res = resourceMap[resource];
- const homeserver_url = homeserver + res.path;
- return jsonClient(`${homeserver_url}/${params.data.id}`, {
- method: "PUT",
- body: JSON.stringify(params.data, filterNullValues),
- }).then(({ json }) => ({
- data: res.map(json),
- }));
+ if ("update" in res) {
+ const upd = res["update"](params.data.id, params.data);
+ const homeserver_url = homeserver + upd.endpoint;
+ return jsonClient(homeserver_url, {
+ method: upd.method,
+ body: JSON.stringify(upd.body),
+ }).then(({ json }) => ({
+ data: json,
+ }));
+ } else {
+ const homeserver_url = homeserver + res.path;
+ return jsonClient(`${homeserver_url}/${params.data.id}`, {
+ method: "PUT",
+ body: JSON.stringify(params.data, filterNullValues),
+ }).then(({ json }) => ({
+ data: res.map(json),
+ }));
+ }
},
updateMany: (resource, params) => {
@@ -173,15 +208,30 @@ const dataProvider = {
const res = resourceMap[resource];
- const homeserver_url = homeserver + res.path;
- return Promise.all(
- params.ids.map(id => jsonClient(`${homeserver_url}/${id}`), {
- method: "PUT",
- body: JSON.stringify(params.data, filterNullValues),
- })
- ).then(responses => ({
- data: responses.map(({ json }) => json),
- }));
+ if ("update" in res) {
+ return Promise.all(
+ params.ids.map(id => {
+ const upd = res["update"](id, params.data);
+ const homeserver_url = homeserver + upd.endpoint;
+ return jsonClient(homeserver_url, {
+ method: upd.method,
+ body: JSON.stringify(upd.body),
+ });
+ })
+ ).then(responses => ({
+ data: responses.map(({ json }) => json),
+ }));
+ } else {
+ const homeserver_url = homeserver + res.path;
+ return Promise.all(
+ params.ids.map(id => jsonClient(`${homeserver_url}/${id}`), {
+ method: "PUT",
+ body: JSON.stringify(params.data, filterNullValues),
+ })
+ ).then(responses => ({
+ data: responses.map(({ json }) => json),
+ }));
+ }
},
create: (resource, params) => {