From a44510ff17ac6e099ceed9401a62d6d66366c73d Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Mon, 23 Aug 2021 15:04:09 +0300
Subject: ActivityPub: send Update event on user profile updates
---
src/main/java/com/juick/ActivityPubManager.java | 23 +++++++++++++
.../juick/service/activities/ActivityListener.java | 3 ++
.../juick/service/activities/UpdateUserEvent.java | 40 ++++++++++++++++++++++
src/main/java/com/juick/www/api/Users.java | 2 ++
.../java/com/juick/www/controllers/Settings.java | 5 +++
5 files changed, 73 insertions(+)
create mode 100644 src/main/java/com/juick/service/activities/UpdateUserEvent.java
diff --git a/src/main/java/com/juick/ActivityPubManager.java b/src/main/java/com/juick/ActivityPubManager.java
index cb4d0b54..1e97a54e 100644
--- a/src/main/java/com/juick/ActivityPubManager.java
+++ b/src/main/java/com/juick/ActivityPubManager.java
@@ -217,6 +217,29 @@ public class ActivityPubManager implements ActivityListener, NotificationListene
}
}
}
+
+ @Override
+ public void processUpdateUserEvent(UpdateUserEvent event) {
+ User user = event.getUser();
+ String userUri = personUri(user);
+ Person me = (Person) signatureManager.getContext(URI.create(userUri)).get();
+ socialService.getFollowers(user).forEach(acct -> {
+ try {
+ Person follower = (Person) signatureManager.getContext(URI.create(acct)).orElseThrow();
+ Update update = new Update();
+ update.setId(userUri + "#update");
+ update.setActor(me.getId());
+ update.setObject(new Context(userUri));
+ logger.info("Update to follower {}", follower.getId());
+ signatureManager.post(me, follower, update);
+ } catch (NoSuchElementException e) {
+ logger.warn("Person not verified: {}", acct);
+ } catch (IOException | NoSuchAlgorithmException e) {
+ logger.warn("activitypub exception", e);
+ }
+ });
+ }
+
private void processMessage(Message msg) {
if (MessageUtils.isPM(msg) || msg.isService()) {
return;
diff --git a/src/main/java/com/juick/service/activities/ActivityListener.java b/src/main/java/com/juick/service/activities/ActivityListener.java
index d3ce1eaf..3dcd123c 100644
--- a/src/main/java/com/juick/service/activities/ActivityListener.java
+++ b/src/main/java/com/juick/service/activities/ActivityListener.java
@@ -42,4 +42,7 @@ public interface ActivityListener {
@Async
@EventListener
void processUpdateEvent(UpdateEvent event);
+ @Async
+ @EventListener
+ void processUpdateUserEvent(UpdateUserEvent event);
}
diff --git a/src/main/java/com/juick/service/activities/UpdateUserEvent.java b/src/main/java/com/juick/service/activities/UpdateUserEvent.java
new file mode 100644
index 00000000..5294ea64
--- /dev/null
+++ b/src/main/java/com/juick/service/activities/UpdateUserEvent.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2008-2021, Juick
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see
Your info is updated.
", visitor.getName()); } + applicationEventPublisher.publishEvent(new UpdateUserEvent(this, visitor)); break; case "jid-del": // FIXME: stop using ugnich-csv in parameters -- cgit v1.2.3