From 9d2909aa126c754be8f8ce96646aa10d17fc97ce Mon Sep 17 00:00:00 2001 From: PhilReact Date: Sat, 21 Oct 2023 18:36:37 +0300 Subject: [PATCH] add to followlist --- .../friends-view/save-settings-qdn.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/core/src/components/friends-view/save-settings-qdn.js b/core/src/components/friends-view/save-settings-qdn.js index 86647a06..b2e558a5 100644 --- a/core/src/components/friends-view/save-settings-qdn.js +++ b/core/src/components/friends-view/save-settings-qdn.js @@ -158,6 +158,37 @@ class SaveSettingsQdn extends connect(store)(LitElement) { return decryptedDataToBase64; } + async getMyFollowedNames() { + + let myFollowedNames = [] + try { + myFollowedNames = await parentEpml.request('apiCall', { + url: `/lists/followedNames?apiKey=${this.myNode.apiKey}` + }) + } catch (error) { + + } + + return myFollowedNames + } + + async followNames(names) { + let items = names + let namesJsonString = JSON.stringify({ "items": items }) + + let ret = await parentEpml.request('apiCall', { + url: `/lists/followedNames?apiKey=${this.myNode.apiKey}`, + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: `${namesJsonString}` + }) + + + return ret + } + async setValues(response, resource) { this.settingsRawData = response; const rawDataTimestamp = resource.updated; @@ -179,6 +210,14 @@ class SaveSettingsQdn extends connect(store)(LitElement) { ) { const friendList = userLists[0]; const copyPayload = [...friendList]; + const onlyNames = copyPayload.map((item)=> item.name) + const followedList = await this.getMyFollowedNames() + + const namesNotInFollowedList = onlyNames.filter(name => !followedList.includes(name)); + if(namesNotInFollowedList.length > 0){ + await this.followNames(namesNotInFollowedList) + + } localStorage.setItem( 'friends-my-friend-list',