From 550e7d04155db3cc2d96d69585ed0c84f6b79d5d Mon Sep 17 00:00:00 2001 From: Romain de Laage Date: Fri, 14 Oct 2022 17:18:44 +0200 Subject: [PATCH] Add matrix bot support --- database/migrations.go | 11 +++++ go.mod | 1 + go.sum | 2 + integration/integration.go | 13 ++++++ integration/matrixbot/matrixbot.go | 51 ++++++++++++++++++++++ locale/translations/de_DE.json | 5 +++ locale/translations/el_EL.json | 5 +++ locale/translations/en_US.json | 5 +++ locale/translations/es_ES.json | 5 +++ locale/translations/fi_FI.json | 5 +++ locale/translations/fr_FR.json | 5 +++ locale/translations/hi_IN.json | 5 +++ locale/translations/it_IT.json | 5 +++ locale/translations/ja_JP.json | 5 +++ locale/translations/nl_NL.json | 5 +++ locale/translations/pl_PL.json | 5 +++ locale/translations/pt_BR.json | 5 +++ locale/translations/ru_RU.json | 5 +++ locale/translations/tr_TR.json | 5 +++ locale/translations/uk_UA.json | 5 +++ locale/translations/zh_CN.json | 5 +++ locale/translations/zh_TW.json | 5 +++ model/integration.go | 5 +++ reader/processor/processor.go | 13 ++++++ storage/integration.go | 40 ++++++++++++++--- template/templates/views/integrations.html | 23 ++++++++++ ui/form/integration.go | 15 +++++++ ui/integration_show.go | 5 +++ 28 files changed, 259 insertions(+), 5 deletions(-) create mode 100644 integration/matrixbot/matrixbot.go diff --git a/database/migrations.go b/database/migrations.go index af83888c..82780125 100644 --- a/database/migrations.go +++ b/database/migrations.go @@ -622,4 +622,15 @@ var migrations = []func(tx *sql.Tx) error{ `) return }, + func(tx *sql.Tx) (err error) { + sql := ` + ALTER TABLE integrations ADD COLUMN matrix_bot_enabled bool default 'f'; + ALTER TABLE integrations ADD COLUMN matrix_bot_user text default ''; + ALTER TABLE integrations ADD COLUMN matrix_bot_password text default ''; + ALTER TABLE integrations ADD COLUMN matrix_bot_url text default ''; + ALTER TABLE integrations ADD COLUMN matrix_bot_chat_id text default ''; + ` + _, err = tx.Exec(sql) + return + }, } diff --git a/go.mod b/go.mod index 709850ac..ebecac45 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ module miniflux.app require ( github.com/PuerkitoBio/goquery v1.8.0 github.com/coreos/go-oidc v2.2.1+incompatible + github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible github.com/gorilla/mux v1.8.0 github.com/lib/pq v1.10.7 diff --git a/go.sum b/go.sum index 13f61f97..61e2a82a 100644 --- a/go.sum +++ b/go.sum @@ -206,6 +206,8 @@ github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/magiconair/properties v1.7.4-0.20170902060319-8d7837e64d3c/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8r4Fzarl4+Y3K5hjothkVW5z7T1dUM11U= +github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s= github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2/go.mod h1:0KeJpeMD6o+O4hW7qJOT7vyQPKrWmj26uf5wMc/IiIs= github.com/mattn/go-colorable v0.0.0-20170327083344-ded68f7a9561/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.0.10-0.20170816031813-ad5389df28cd/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= diff --git a/integration/integration.go b/integration/integration.go index 79e58dac..c86ebae5 100644 --- a/integration/integration.go +++ b/integration/integration.go @@ -9,6 +9,7 @@ import ( "miniflux.app/integration/espial" "miniflux.app/integration/instapaper" "miniflux.app/integration/linkding" + "miniflux.app/integration/matrixbot" "miniflux.app/integration/nunuxkeeper" "miniflux.app/integration/pinboard" "miniflux.app/integration/pocket" @@ -110,6 +111,18 @@ func SendEntry(entry *model.Entry, integration *model.Integration) { } } +// PushEntries pushes an entry array to third-party providers during feed refreshes. +func PushEntries(entries model.Entries, integration *model.Integration) { + if integration.MatrixBotEnabled { + logger.Debug("[Integration] Sending %d entries for User #%d to Matrix", len(entries), integration.UserID) + + err := matrixbot.PushEntries(entries, integration.MatrixBotURL, integration.MatrixBotUser, integration.MatrixBotPassword, integration.MatrixBotChatID) + if err != nil { + logger.Error("[Integration] push entries to matrix bot failed: %v", err) + } + } +} + // PushEntry pushes an entry to third-party providers during feed refreshes. func PushEntry(entry *model.Entry, integration *model.Integration) { if integration.TelegramBotEnabled { diff --git a/integration/matrixbot/matrixbot.go b/integration/matrixbot/matrixbot.go new file mode 100644 index 00000000..35ec1763 --- /dev/null +++ b/integration/matrixbot/matrixbot.go @@ -0,0 +1,51 @@ +// Copyright 2021 Frédéric Guillot. All rights reserved. +// Use of this source code is governed by the Apache 2.0 +// license that can be found in the LICENSE file. + +package matrixbot // import "miniflux.app/integration/matrixbot" + +import ( + "fmt" + + "miniflux.app/logger" + "miniflux.app/model" + + "github.com/matrix-org/gomatrix" +) + +// PushEntry pushes entries to matrix chat using integration settings provided +func PushEntries(entries model.Entries, serverURL, botLogin, botPassword, chatID string) error { + bot, err := gomatrix.NewClient(serverURL, "", "") + if err != nil { + return fmt.Errorf("matrixbot: bot creation failed: %w", err) + } + + resp, err := bot.Login(&gomatrix.ReqLogin{ + Type: "m.login.password", + User: botLogin, + Password: botPassword, + }) + + if err != nil { + logger.Debug("matrixbot: login failed: %w", err) + return fmt.Errorf("matrixbot: login failed, please check your credentials or turn on debug mode") + } + + bot.SetCredentials(resp.UserID, resp.AccessToken) + defer func() { + bot.Logout() + bot.ClearCredentials() + }() + + message := "" + for _, entry := range entries { + message = message + entry.Title + " " + entry.URL + "\n" + } + + if _, err = bot.SendText(chatID, message); err != nil { + logger.Debug("matrixbot: sending message failed: %w", err) + return fmt.Errorf("matrixbot: sending message failed, turn on debug mode for more informations") + } + + return nil +} diff --git a/locale/translations/de_DE.json b/locale/translations/de_DE.json index 3ef47a17..e8f0871e 100644 --- a/locale/translations/de_DE.json +++ b/locale/translations/de_DE.json @@ -355,6 +355,11 @@ "form.integration.linkding_activate": "Artikel in Linkding speichern", "form.integration.linkding_endpoint": "Linkding API-Endpunkt", "form.integration.linkding_api_key": "Linkding API-Schlüssel", + "form.integration.matrix_bot_activate": "Neue Artikel in die Matrix übertragen", + "form.integration.matrix_bot_user": "Benutzername für Matrix", + "form.integration.matrix_bot_password": "Passwort für Matrix-Benutzer", + "form.integration.matrix_bot_url": "URL des Matrix-Servers", + "form.integration.matrix_bot_chat_id": "ID des Matrix-Raums", "form.api_key.label.description": "API-Schlüsselbezeichnung", "form.submit.loading": "Lade...", "form.submit.saving": "Speichern...", diff --git a/locale/translations/el_EL.json b/locale/translations/el_EL.json index bc9e77a2..cf6c8a7a 100644 --- a/locale/translations/el_EL.json +++ b/locale/translations/el_EL.json @@ -355,6 +355,11 @@ "form.integration.linkding_activate": "Αποθήκευση άρθρων στο Linkding", "form.integration.linkding_endpoint": "Τελικό σημείο Linkding API", "form.integration.linkding_api_key": "Κλειδί API Linkding", + "form.integration.matrix_bot_activate": "Μεταφορά νέων άρθρων στο Matrix", + "form.integration.matrix_bot_user": "Όνομα χρήστη για το Matrix", + "form.integration.matrix_bot_password": "Κωδικός πρόσβασης για τον χρήστη Matrix", + "form.integration.matrix_bot_url": "URL διακομιστή Matrix", + "form.integration.matrix_bot_chat_id": "Αναγνωριστικό της αίθουσας Matrix", "form.api_key.label.description": "Ετικέτα κλειδιού API", "form.submit.loading": "Φόρτωση...", "form.submit.saving": "Αποθήκευση...", diff --git a/locale/translations/en_US.json b/locale/translations/en_US.json index b993744b..e7ffb8d8 100644 --- a/locale/translations/en_US.json +++ b/locale/translations/en_US.json @@ -355,6 +355,11 @@ "form.integration.linkding_activate": "Save articles to Linkding", "form.integration.linkding_endpoint": "Linkding API Endpoint", "form.integration.linkding_api_key": "Linkding API key", + "form.integration.matrix_bot_activate": "Push new articles to Matrix", + "form.integration.matrix_bot_user": "Username for Matrix", + "form.integration.matrix_bot_password": "Password for Matrix user", + "form.integration.matrix_bot_url": "Matrix server URL", + "form.integration.matrix_bot_chat_id": "ID of Matrix Room", "form.api_key.label.description": "API Key Label", "form.submit.loading": "Loading...", "form.submit.saving": "Saving...", diff --git a/locale/translations/es_ES.json b/locale/translations/es_ES.json index 6b14c96d..e9478ca9 100644 --- a/locale/translations/es_ES.json +++ b/locale/translations/es_ES.json @@ -355,6 +355,11 @@ "form.integration.linkding_activate": "Guardar artículos a Linkding", "form.integration.linkding_endpoint": "Extremo de API de Linkding", "form.integration.linkding_api_key": "Clave de API de Linkding", + "form.integration.matrix_bot_activate": "Transferir nuevos artículos a Matrix", + "form.integration.matrix_bot_user": "Nombre de usuario para Matrix", + "form.integration.matrix_bot_password": "Contraseña para el usuario de Matrix", + "form.integration.matrix_bot_url": "URL del servidor de Matrix", + "form.integration.matrix_bot_chat_id": "ID de la sala de Matrix", "form.api_key.label.description": "Etiqueta de clave API", "form.submit.loading": "Cargando...", "form.submit.saving": "Guardando...", diff --git a/locale/translations/fi_FI.json b/locale/translations/fi_FI.json index cea9970f..916a699f 100644 --- a/locale/translations/fi_FI.json +++ b/locale/translations/fi_FI.json @@ -355,6 +355,11 @@ "form.integration.linkding_activate": "Tallenna artikkelit Linkkiin", "form.integration.linkding_endpoint": "Linkding API-päätepiste", "form.integration.linkding_api_key": "Linkding API-avain", + "form.integration.matrix_bot_activate": "Siirrä uudet artikkelit Matrixiin", + "form.integration.matrix_bot_user": "Matrixin käyttäjätunnus", + "form.integration.matrix_bot_password": "Matrix-käyttäjän salasana", + "form.integration.matrix_bot_url": "Matrix-palvelimen URL-osoite", + "form.integration.matrix_bot_chat_id": "Matrix-huoneen tunnus", "form.api_key.label.description": "API Key Label", "form.submit.loading": "Ladataan...", "form.submit.saving": "Tallennetaan...", diff --git a/locale/translations/fr_FR.json b/locale/translations/fr_FR.json index 4ad16d59..0d8d5064 100644 --- a/locale/translations/fr_FR.json +++ b/locale/translations/fr_FR.json @@ -355,6 +355,11 @@ "form.integration.linkding_activate": "Sauvegarder les articles vers Linkding", "form.integration.linkding_endpoint": "URL de l'API de Linkding", "form.integration.linkding_api_key": "Clé d'API de Linkding", + "form.integration.matrix_bot_activate": "Envoyer les nouveaux articles vers Matrix", + "form.integration.matrix_bot_user": "Nom de l'utilisateur Matrix", + "form.integration.matrix_bot_password": "Mot de passe de l'utilisateur Matrix", + "form.integration.matrix_bot_url": "URL du serveur Matrix", + "form.integration.matrix_bot_chat_id": "Identifiant de la salle Matrix", "form.api_key.label.description": "Libellé de la clé d'API", "form.submit.loading": "Chargement...", "form.submit.saving": "Sauvegarde en cours...", diff --git a/locale/translations/hi_IN.json b/locale/translations/hi_IN.json index d44bc99e..8eda024b 100644 --- a/locale/translations/hi_IN.json +++ b/locale/translations/hi_IN.json @@ -355,6 +355,11 @@ "form.integration.linkding_activate": "लिंक्डिन में विषयवस्तु सहेजें", "form.integration.linkding_endpoint": "लिंकिंग एपीआई समापन बिंदु", "form.integration.linkding_api_key": "लिंकिंग एपीआई कुंजी", + "form.integration.matrix_bot_activate": "नए लेखों को मैट्रिक्स में स्थानांतरित करें", + "form.integration.matrix_bot_user": "मैट्रिक्स के लिए उपयोगकर्ता नाम", + "form.integration.matrix_bot_password": "मैट्रिक्स उपयोगकर्ता के लिए पासवर्ड", + "form.integration.matrix_bot_url": "मैट्रिक्स सर्वर URL", + "form.integration.matrix_bot_chat_id": "मैट्रिक्स रूम की आईडी", "form.api_key.label.description": "एपीआई कुंजी लेबल", "form.submit.loading": "लोड हो रहा है...", "form.submit.saving": "सहेजा जा रहा है...", diff --git a/locale/translations/it_IT.json b/locale/translations/it_IT.json index c22ade55..9fb164bb 100644 --- a/locale/translations/it_IT.json +++ b/locale/translations/it_IT.json @@ -355,6 +355,11 @@ "form.integration.linkding_activate": "Salva gli articoli su Linkding", "form.integration.linkding_endpoint": "Endpoint dell'API di Linkding", "form.integration.linkding_api_key": "API key dell'account Linkding", + "form.integration.matrix_bot_activate": "Trasferimento di nuovi articoli a Matrix", + "form.integration.matrix_bot_user": "Nome utente per Matrix", + "form.integration.matrix_bot_password": "Password per l'utente Matrix", + "form.integration.matrix_bot_url": "URL del server Matrix", + "form.integration.matrix_bot_chat_id": "ID della stanza Matrix", "form.api_key.label.description": "Etichetta chiave API", "form.submit.loading": "Caricamento in corso...", "form.submit.saving": "Salvataggio in corso...", diff --git a/locale/translations/ja_JP.json b/locale/translations/ja_JP.json index 08a95266..4ef636d3 100644 --- a/locale/translations/ja_JP.json +++ b/locale/translations/ja_JP.json @@ -355,6 +355,11 @@ "form.integration.linkding_activate": "Linkding に記事を保存する", "form.integration.linkding_endpoint": "Linkding の API Endpoint", "form.integration.linkding_api_key": "Linkding の API key", + "form.integration.matrix_bot_activate": "新しい記事をMatrixに転送する", + "form.integration.matrix_bot_user": "Matrixのユーザー名", + "form.integration.matrix_bot_password": "Matrixユーザ用パスワード", + "form.integration.matrix_bot_url": "MatrixサーバーのURL", + "form.integration.matrix_bot_chat_id": "MatrixルームのID", "form.api_key.label.description": "APIキーラベル", "form.submit.loading": "読み込み中…", "form.submit.saving": "保存中…", diff --git a/locale/translations/nl_NL.json b/locale/translations/nl_NL.json index 4ca58f4d..6234ee3f 100644 --- a/locale/translations/nl_NL.json +++ b/locale/translations/nl_NL.json @@ -355,6 +355,11 @@ "form.integration.linkding_activate": "Opslaan naar Linkding", "form.integration.linkding_endpoint": "Linkding URL", "form.integration.linkding_api_key": "Linkding API-sleutel", + "form.integration.matrix_bot_activate": "Nieuwe artikelen overbrengen naar Matrix", + "form.integration.matrix_bot_user": "Gebruikersnaam voor Matrix", + "form.integration.matrix_bot_password": "Wachtwoord voor Matrix-gebruiker", + "form.integration.matrix_bot_url": "URL van de Matrix-server", + "form.integration.matrix_bot_chat_id": "ID van Matrix-kamer", "form.api_key.label.description": "API-sleutellabel", "form.submit.loading": "Laden...", "form.submit.saving": "Opslaag...", diff --git a/locale/translations/pl_PL.json b/locale/translations/pl_PL.json index da9d949e..e69b7c42 100644 --- a/locale/translations/pl_PL.json +++ b/locale/translations/pl_PL.json @@ -357,6 +357,11 @@ "form.integration.linkding_activate": "Zapisz artykuły do Linkding", "form.integration.linkding_endpoint": "Linkding URL", "form.integration.linkding_api_key": "Linkding API key", + "form.integration.matrix_bot_activate": "Przenieś nowe artykuły do Matrix", + "form.integration.matrix_bot_user": "Nazwa użytkownika dla Matrix", + "form.integration.matrix_bot_password": "Hasło dla użytkownika Matrix", + "form.integration.matrix_bot_url": "URL serwera Matrix", + "form.integration.matrix_bot_chat_id": "Identyfikator pokoju Matrix", "form.api_key.label.description": "Etykieta klucza API", "form.submit.loading": "Ładowanie...", "form.submit.saving": "Zapisywanie...", diff --git a/locale/translations/pt_BR.json b/locale/translations/pt_BR.json index 91f9c743..58f9f9cf 100644 --- a/locale/translations/pt_BR.json +++ b/locale/translations/pt_BR.json @@ -355,6 +355,11 @@ "form.integration.linkding_activate": "Salvar itens no Linkding", "form.integration.linkding_endpoint": "Endpoint de API do Linkding", "form.integration.linkding_api_key": "Chave de API do Linkding", + "form.integration.matrix_bot_activate": "Transferir novos artigos para o Matrix", + "form.integration.matrix_bot_user": "Nome de utilizador para Matrix", + "form.integration.matrix_bot_password": "Palavra-passe para utilizador da Matrix", + "form.integration.matrix_bot_url": "URL do servidor Matrix", + "form.integration.matrix_bot_chat_id": "Identificação da sala Matrix", "form.api_key.label.description": "Etiqueta da chave de API", "form.submit.loading": "Carregando...", "form.submit.saving": "Salvando...", diff --git a/locale/translations/ru_RU.json b/locale/translations/ru_RU.json index f9f8234d..76f4387f 100644 --- a/locale/translations/ru_RU.json +++ b/locale/translations/ru_RU.json @@ -357,6 +357,11 @@ "form.integration.linkding_activate": "Сохранять статьи в Linkding", "form.integration.linkding_endpoint": "Конечная точка Linkding API", "form.integration.linkding_api_key": "Linkding API key", + "form.integration.matrix_bot_activate": "Перенос новых статей в Матрицу", + "form.integration.matrix_bot_user": "Имя пользователя для Matrix", + "form.integration.matrix_bot_password": "Пароль для пользователя Matrix", + "form.integration.matrix_bot_url": "URL сервера Матрицы", + "form.integration.matrix_bot_chat_id": "ID комнаты Матрицы", "form.api_key.label.description": "Описание API-ключа", "form.submit.loading": "Загрузка…", "form.submit.saving": "Сохранение…", diff --git a/locale/translations/tr_TR.json b/locale/translations/tr_TR.json index 5d7f07ae..5a30cba6 100644 --- a/locale/translations/tr_TR.json +++ b/locale/translations/tr_TR.json @@ -355,6 +355,11 @@ "form.integration.linkding_activate": "Makaleleri Linkding'e kaydet", "form.integration.linkding_endpoint": "Linkding API Uç Noktası", "form.integration.linkding_api_key": "Linkding API Anahtarı", + "form.integration.matrix_bot_activate": "Yeni makaleleri Matrix'e aktarın", + "form.integration.matrix_bot_user": "Matrix için Kullanıcı Adı", + "form.integration.matrix_bot_password": "Matrix kullanıcısı için şifre", + "form.integration.matrix_bot_url": "Matris sunucusu URL'si", + "form.integration.matrix_bot_chat_id": "Matris odasının kimliği", "form.api_key.label.description": "API Anahtar Etiketi", "form.submit.loading": "Yükleniyor...", "form.submit.saving": "Kaydediliyor...", diff --git a/locale/translations/uk_UA.json b/locale/translations/uk_UA.json index 52e1c054..9ae8dccb 100644 --- a/locale/translations/uk_UA.json +++ b/locale/translations/uk_UA.json @@ -354,6 +354,11 @@ "form.integration.linkding_activate": "Зберігати статті до Linkding", "form.integration.linkding_endpoint": "Linkding API Endpoint", "form.integration.linkding_api_key": "Ключ API Linkding", + "form.integration.matrix_bot_activate": "Перенесення нових статей в Матрицю", + "form.integration.matrix_bot_user": "Ім'я користувача для Matrix", + "form.integration.matrix_bot_password": "Пароль для користувача Matrix", + "form.integration.matrix_bot_url": "URL-адреса сервера Матриці", + "form.integration.matrix_bot_chat_id": "Ідентифікатор кімнати Матриці", "form.api_key.label.description": "Назва ключа API", "form.submit.loading": "Завантаження...", "form.submit.saving": "Зберігаю...", diff --git a/locale/translations/zh_CN.json b/locale/translations/zh_CN.json index 3ccdea7d..19c227d1 100644 --- a/locale/translations/zh_CN.json +++ b/locale/translations/zh_CN.json @@ -353,6 +353,11 @@ "form.integration.linkding_activate": "保存文章到 Linkding", "form.integration.linkding_endpoint": "Linkding API 端点", "form.integration.linkding_api_key": "Linkding API 密钥", + "form.integration.matrix_bot_activate": "将新文章转移到 Matrix", + "form.integration.matrix_bot_user": "矩阵的用户名", + "form.integration.matrix_bot_password": "矩阵用户密码", + "form.integration.matrix_bot_url": "矩阵服务器 URL", + "form.integration.matrix_bot_chat_id": "Matrix房间ID", "form.api_key.label.description": "API密钥标签", "form.submit.loading": "载入中…", "form.submit.saving": "保存中…", diff --git a/locale/translations/zh_TW.json b/locale/translations/zh_TW.json index e046e7f1..37f7cdc0 100644 --- a/locale/translations/zh_TW.json +++ b/locale/translations/zh_TW.json @@ -355,6 +355,11 @@ "form.integration.linkding_activate": "儲存文章到 Linkding", "form.integration.linkding_endpoint": "Linkding API 端點", "form.integration.linkding_api_key": "Linkding API 金鑰", + "form.integration.matrix_bot_activate": "將新文章轉移到 Matrix", + "form.integration.matrix_bot_user": "矩陣的用戶名", + "form.integration.matrix_bot_password": "矩陣用戶密碼", + "form.integration.matrix_bot_url": "矩陣服務器 URL", + "form.integration.matrix_bot_chat_id": "Matrix房間ID", "form.api_key.label.description": "API金鑰標籤", "form.submit.loading": "載入中…", "form.submit.saving": "儲存中…", diff --git a/model/integration.go b/model/integration.go index 794e64ef..8124d667 100644 --- a/model/integration.go +++ b/model/integration.go @@ -43,4 +43,9 @@ type Integration struct { LinkdingEnabled bool LinkdingURL string LinkdingAPIKey string + MatrixBotEnabled bool + MatrixBotUser string + MatrixBotPassword string + MatrixBotURL string + MatrixBotChatID string } diff --git a/reader/processor/processor.go b/reader/processor/processor.go index 26b5b87e..5beaaf20 100644 --- a/reader/processor/processor.go +++ b/reader/processor/processor.go @@ -41,6 +41,9 @@ var ( func ProcessFeedEntries(store *storage.Storage, feed *model.Feed, user *model.User) { var filteredEntries model.Entries + // array used for bulk push + entriesToPush := model.Entries{} + for _, entry := range feed.Entries { logger.Debug("[Processor] Processing entry %q from feed %q", entry.URL, feed.FeedURL) @@ -93,6 +96,7 @@ func ProcessFeedEntries(store *storage.Storage, feed *model.Feed, user *model.Us go func() { integration.PushEntry(localEntry, intg) }() + entriesToPush = append(entriesToPush, localEntry) } } @@ -100,6 +104,15 @@ func ProcessFeedEntries(store *storage.Storage, feed *model.Feed, user *model.Us filteredEntries = append(filteredEntries, entry) } + intg, err := store.Integration(feed.UserID) + if err != nil { + logger.Error("[Processor] Get integrations for user %d failed: %v; the refresh process will go on, but no integrations will run this time.", feed.UserID, err) + } else if intg != nil { + go func() { + integration.PushEntries(entriesToPush, intg) + }() + } + feed.Entries = filteredEntries } diff --git a/storage/integration.go b/storage/integration.go index dd391730..71ed83c0 100644 --- a/storage/integration.go +++ b/storage/integration.go @@ -146,7 +146,12 @@ func (s *Storage) Integration(userID int64) (*model.Integration, error) { telegram_bot_chat_id, linkding_enabled, linkding_url, - linkding_api_key + linkding_api_key, + matrix_bot_enabled, + matrix_bot_user, + matrix_bot_password, + matrix_bot_url, + matrix_bot_chat_id FROM integrations WHERE @@ -191,6 +196,11 @@ func (s *Storage) Integration(userID int64) (*model.Integration, error) { &integration.LinkdingEnabled, &integration.LinkdingURL, &integration.LinkdingAPIKey, + &integration.MatrixBotEnabled, + &integration.MatrixBotUser, + &integration.MatrixBotPassword, + &integration.MatrixBotURL, + &integration.MatrixBotChatID, ) switch { case err == sql.ErrNoRows: @@ -249,9 +259,14 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error { espial_tags=$33, linkding_enabled=$34, linkding_url=$35, - linkding_api_key=$36 + linkding_api_key=$36, + matrix_bot_enabled=$37, + matrix_bot_user=$38, + matrix_bot_password=$39, + matrix_bot_url=$40, + matrix_bot_chat_id=$41 WHERE - user_id=$37 + user_id=$42 ` _, err = s.db.Exec( query, @@ -291,6 +306,11 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error { integration.LinkdingEnabled, integration.LinkdingURL, integration.LinkdingAPIKey, + integration.MatrixBotEnabled, + integration.MatrixBotUser, + integration.MatrixBotPassword, + integration.MatrixBotURL, + integration.MatrixBotChatID, integration.UserID, ) } else { @@ -333,9 +353,14 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error { espial_tags=$33, linkding_enabled=$34, linkding_url=$35, - linkding_api_key=$36 + linkding_api_key=$36, + matrix_bot_enabled=$37, + matrix_bot_user=$38, + matrix_bot_password=$39, + matrix_bot_url=$40, + matrix_bot_chat_id=$41 WHERE - user_id=$37 + user_id=$42 ` _, err = s.db.Exec( query, @@ -375,6 +400,11 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error { integration.LinkdingEnabled, integration.LinkdingURL, integration.LinkdingAPIKey, + integration.MatrixBotEnabled, + integration.MatrixBotUser, + integration.MatrixBotPassword, + integration.MatrixBotURL, + integration.MatrixBotChatID, integration.UserID, ) } diff --git a/template/templates/views/integrations.html b/template/templates/views/integrations.html index b16cd865..8bb615d4 100644 --- a/template/templates/views/integrations.html +++ b/template/templates/views/integrations.html @@ -214,6 +214,29 @@ +

Matrix Bot

+
+ + + + + + + + + + + + + + +
+ +
+
+

{{ t "page.integration.bookmarklet" }}

diff --git a/ui/form/integration.go b/ui/form/integration.go index 3efb2763..07ad856a 100644 --- a/ui/form/integration.go +++ b/ui/form/integration.go @@ -48,6 +48,11 @@ type IntegrationForm struct { LinkdingEnabled bool LinkdingURL string LinkdingAPIKey string + MatrixBotEnabled bool + MatrixBotUser string + MatrixBotPassword string + MatrixBotURL string + MatrixBotChatID string } // Merge copy form values to the model. @@ -86,6 +91,11 @@ func (i IntegrationForm) Merge(integration *model.Integration) { integration.LinkdingEnabled = i.LinkdingEnabled integration.LinkdingURL = i.LinkdingURL integration.LinkdingAPIKey = i.LinkdingAPIKey + integration.MatrixBotEnabled = i.MatrixBotEnabled + integration.MatrixBotUser = i.MatrixBotUser + integration.MatrixBotPassword = i.MatrixBotPassword + integration.MatrixBotURL = i.MatrixBotURL + integration.MatrixBotChatID = i.MatrixBotChatID } // NewIntegrationForm returns a new IntegrationForm. @@ -127,5 +137,10 @@ func NewIntegrationForm(r *http.Request) *IntegrationForm { LinkdingEnabled: r.FormValue("linkding_enabled") == "1", LinkdingURL: r.FormValue("linkding_url"), LinkdingAPIKey: r.FormValue("linkding_api_key"), + MatrixBotEnabled: r.FormValue("matrix_bot_enabled") == "1", + MatrixBotUser: r.FormValue("matrix_bot_user"), + MatrixBotPassword: r.FormValue("matrix_bot_password"), + MatrixBotURL: r.FormValue("matrix_bot_url"), + MatrixBotChatID: r.FormValue("matrix_bot_chat_id"), } } diff --git a/ui/integration_show.go b/ui/integration_show.go index 949ddb55..afd0bfd5 100644 --- a/ui/integration_show.go +++ b/ui/integration_show.go @@ -63,6 +63,11 @@ func (h *handler) showIntegrationPage(w http.ResponseWriter, r *http.Request) { LinkdingEnabled: integration.LinkdingEnabled, LinkdingURL: integration.LinkdingURL, LinkdingAPIKey: integration.LinkdingAPIKey, + MatrixBotEnabled: integration.MatrixBotEnabled, + MatrixBotUser: integration.MatrixBotUser, + MatrixBotPassword: integration.MatrixBotPassword, + MatrixBotURL: integration.MatrixBotURL, + MatrixBotChatID: integration.MatrixBotChatID, } sess := session.New(h.store, request.SessionID(r))