diff options
author | Iaroslav <yavoloh@mail.ru> | 2021-10-23 19:13:55 +0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-23 19:43:55 +0530 |
commit | 591a9a4ca229dcda6e54d4e24f79dfef14d0acc5 (patch) | |
tree | 8676eb01fe567fb96c8220459746d55cc3dbf12a /docs | |
parent | fix for #286 with fallback (#738) (diff) | |
download | ferdium-recipes-591a9a4ca229dcda6e54d4e24f79dfef14d0acc5.tar.gz ferdium-recipes-591a9a4ca229dcda6e54d4e24f79dfef14d0acc5.tar.zst ferdium-recipes-591a9a4ca229dcda6e54d4e24f79dfef14d0acc5.zip |
Add setDialogTitle feature to api, WhatsApp and Telegram (#750)
Co-authored-by: Vijay A <vraravam@users.noreply.github.com>
Diffstat (limited to 'docs')
-rw-r--r-- | docs/frontend_api.md | 16 | ||||
-rw-r--r-- | docs/integration.md | 48 |
2 files changed, 50 insertions, 14 deletions
diff --git a/docs/frontend_api.md b/docs/frontend_api.md index aa1070b..bd0bfef 100644 --- a/docs/frontend_api.md +++ b/docs/frontend_api.md | |||
@@ -34,6 +34,22 @@ Ferdi.setBadge(4, 2); | |||
34 | Ferdi.setBadge(3); | 34 | Ferdi.setBadge(3); |
35 | ``` | 35 | ``` |
36 | 36 | ||
37 | ### setDialogTitle(title) | ||
38 | |||
39 | Sets the active dialog title to the app title | ||
40 | |||
41 | #### Arguments | ||
42 | |||
43 | 1. `string` title | ||
44 | |||
45 | - sets the active dialog title eg. WhatsApp contact name | ||
46 | |||
47 | #### Usage | ||
48 | |||
49 | ```js | ||
50 | Ferdi.setDialogTitle('Dialog title'); | ||
51 | ``` | ||
52 | |||
37 | ### injectCSS(pathToCssFile) | 53 | ### injectCSS(pathToCssFile) |
38 | 54 | ||
39 | Injects the contents of one or more CSS files into the current webview | 55 | Injects the contents of one or more CSS files into the current webview |
diff --git a/docs/integration.md b/docs/integration.md index 08164fc..acbc6b5 100644 --- a/docs/integration.md +++ b/docs/integration.md | |||
@@ -87,26 +87,26 @@ Please note that the fields `id`, `name`, `version` and `config` are mandatory. | |||
87 | This is your "backend" code. Right now the options are very limited and most of the services don't need a custom handling here. If your service is relatively straight forward and has a static URL eg. _messenger.com_, _`[TEAMID]`.slack.com_ or _web.skype.com_ all you need to do to return the Ferdi Class: | 87 | This is your "backend" code. Right now the options are very limited and most of the services don't need a custom handling here. If your service is relatively straight forward and has a static URL eg. _messenger.com_, _`[TEAMID]`.slack.com_ or _web.skype.com_ all you need to do to return the Ferdi Class: |
88 | 88 | ||
89 | ```js | 89 | ```js |
90 | module.exports = (Ferdi) => Ferdi; | 90 | module.exports = Ferdi => Ferdi; |
91 | ``` | 91 | ``` |
92 | 92 | ||
93 | If your service can be hosted on custom servers, you can validate the given URL to detect if it's your server and not e.g. google.com. To enable validation you can override the function `validateServer` | 93 | If your service can be hosted on custom servers, you can validate the given URL to detect if it's your server and not e.g. google.com. To enable validation you can override the function `validateServer` |
94 | 94 | ||
95 | ```js | 95 | ```js |
96 | // RocketChat integration | 96 | // RocketChat integration |
97 | module.exports = (Ferdi) => | 97 | module.exports = Ferdi => |
98 | class RocketChat extends Ferdi { | 98 | class RocketChat extends Ferdi { |
99 | async validateUrl(url) { | 99 | async validateUrl(url) { |
100 | try { | 100 | try { |
101 | const resp = await window.fetch(`${url}/api/info`, { | 101 | const resp = await window.fetch(`${url}/api/info`, { |
102 | method: "GET", | 102 | method: 'GET', |
103 | headers: { | 103 | headers: { |
104 | "Content-Type": "application/json", | 104 | 'Content-Type': 'application/json', |
105 | }, | 105 | }, |
106 | }); | 106 | }); |
107 | const data = await resp.json(); | 107 | const data = await resp.json(); |
108 | 108 | ||
109 | return Object.hasOwnProperty.call(data, "version"); | 109 | return Object.hasOwnProperty.call(data, 'version'); |
110 | } catch (err) { | 110 | } catch (err) { |
111 | console.error(err); | 111 | console.error(err); |
112 | } | 112 | } |
@@ -147,24 +147,44 @@ overrideUserAgent() { | |||
147 | 147 | ||
148 | ### webview.js | 148 | ### webview.js |
149 | 149 | ||
150 | The `webview.js` is the actual script that will be loaded into the webview. Here you can do whatever you want to do in order perfectly integrate the service into Ferdi. For convenience, we have provided a very simple set of functions to set unread message badges (`Ferdi.setBadge()`) and inject CSS files (`Ferdi.injectCSS()`). | 150 | The `webview.js` is the actual script that will be loaded into the webview. Here you can do whatever you want to do in order perfectly integrate the service into Ferdi. For convenience, we have provided a very simple set of functions to set unread message badges (`Ferdi.setBadge()`), set active dialog title (`Ferdi.setDialogTitle()`) and inject CSS files (`Ferdi.injectCSS()`). |
151 | 151 | ||
152 | ```js | 152 | ```js |
153 | // orat.io integration | 153 | // telegram integration |
154 | module.exports = (Ferdi) => { | 154 | module.exports = Ferdi => { |
155 | const getMessages = () => { | 155 | const getMessages = () => { |
156 | let direct = 0; | 156 | let direct = 0; |
157 | let indirect = 0; | 157 | let indirect = 0; |
158 | const FerdiData = document.querySelector("#FerdiMessages").dataset; | 158 | const elements = document.querySelectorAll('.rp'); |
159 | if (FerdiData) { | 159 | for (const element of elements) { |
160 | direct = FerdiData.direct; | 160 | const subtitleBadge = element.querySelector('.dialog-subtitle-badge'); |
161 | indirect = FerdiData.indirect; | 161 | if (subtitleBadge) { |
162 | const parsedValue = Ferdi.safeParseInt(subtitleBadge.textContent); | ||
163 | if (element.dataset.peerId > 0) { | ||
164 | direct += parsedValue; | ||
165 | } else { | ||
166 | indirect += parsedValue; | ||
167 | } | ||
168 | } | ||
162 | } | 169 | } |
163 | 170 | ||
164 | Ferdi.setBadge(direct, indirect); | 171 | Ferdi.setBadge(direct, indirect); |
165 | } | 172 | }; |
173 | |||
174 | const getActiveDialogTitle = () => { | ||
175 | const element = document.querySelector('.top .peer-title'); | ||
176 | |||
177 | Ferdi.setDialogTitle(element ? element.textContent : ''); | ||
178 | }; | ||
179 | |||
180 | const loopFunc = () => { | ||
181 | getMessages(); | ||
182 | getActiveDialogTitle(); | ||
183 | }; | ||
184 | |||
185 | Ferdi.loop(loopFunc); | ||
166 | 186 | ||
167 | Ferdi.loop(getMessages); | 187 | Ferdi.injectCSS(_path.default.join(__dirname, 'service.css')); |
168 | }; | 188 | }; |
169 | ``` | 189 | ``` |
170 | 190 | ||