Skip to content

Commit

Permalink
display feed icons
Browse files Browse the repository at this point in the history
  • Loading branch information
trinidz committed Nov 18, 2024
1 parent 559a268 commit 6cce51a
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 172 deletions.
44 changes: 15 additions & 29 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func getLocalFollows() nostr.Tags {
}

for _, savedEnt := range savedEnts {
localFollows = append(localFollows, nostr.Tag{"p", savedEnt.PublicKey})
localFollows = append(localFollows, nostr.Tag{"p", savedEnt.PubKey})
}

return localFollows
Expand Down Expand Up @@ -191,24 +191,7 @@ func deleteRemoteFollow(pubkeyHex string) nostr.Tags {
return nil
}

func getRelayListFromFile(filePath string) []string {
file, err := os.ReadFile(filePath)
if err != nil {
log.Fatalf("Failed to read file: %s", err)
}

var relayList []string
if err := json.Unmarshal(file, &relayList); err != nil {
log.Fatalf("Failed to parse JSON: %s", err)
}

for i, relay := range relayList {
relayList[i] = "wss://" + strings.TrimSpace(relay)
}
return relayList
}

// TRUE if a rsslay feedUrl already exists in bookmark note
// TRUE if a rsslay feedUrl already exists in bookmark event
func feedExists(pubkeyHex, privKeyHex, feedUrl string) (bool, error) {
var bookMarkTags nostr.Tags

Expand Down Expand Up @@ -402,12 +385,12 @@ func deleteEntityInBookmarkEvent(pubKeyORfeedUrl string) error {

//delete related notes
if err := deleteLocalEvents(nostr.Filter{
Authors: []string{rsslayEntity.PublicKey},
Authors: []string{rsslayEntity.PubKey},
Kinds: []int{nostr.KindTextNote, nostr.KindProfileMetadata}}); err != nil {
log.Printf("[ERROR] deleting feed events: %s", err)
}

npub, err := nip19.EncodePublicKey(rsslayEntity.PublicKey)
npub, err := nip19.EncodePublicKey(rsslayEntity.PubKey)
if err != nil {
log.Printf("[ERROR] %s", err)
return err
Expand All @@ -430,7 +413,7 @@ func deleteEntityInBookmarkEvent(pubKeyORfeedUrl string) error {
}

// return all saved FeedURL entries
func getSavedEntries() ([]Entry, error) {
func getSavedEntries() ([]GUIEntry, error) {

var bookMarkTags nostr.Tags
var rsslayEntity Entity
Expand All @@ -443,10 +426,10 @@ func getSavedEntries() ([]Entry, error) {
bookMarkEvts, err := getLocalEvents(bookmarkFilter)
if err != nil {
log.Printf("[ERROR] GetLocalEvent %s", err)
return []Entry{}, err
return []GUIEntry{}, err
}

localEntries := make([]Entry, 0)
localEntries := make([]GUIEntry, 0)
if len(bookMarkEvts) > 0 {
bookMarkTags = bookMarkEvts[0].Tags.GetAll([]string{s.RsslayTagKey})
for _, tag := range bookMarkTags {
Expand All @@ -455,11 +438,14 @@ func getSavedEntries() ([]Entry, error) {
log.Printf("[ERROR] %s", err)
}

npub, _ := nip19.EncodePublicKey(rsslayEntity.PublicKey)
localEntries = append(localEntries, Entry{
PubKey: rsslayEntity.PublicKey,
npub, _ := nip19.EncodePublicKey(rsslayEntity.PubKey)
localEntries = append(localEntries, GUIEntry{
BookmarkEntity: Entity{
PubKey: rsslayEntity.PubKey,
URL: rsslayEntity.URL,
ImageURL: rsslayEntity.ImageURL,
LastUpdate: rsslayEntity.LastUpdate},
NPubKey: npub,
Url: rsslayEntity.URL,
})
}
} else {
Expand Down Expand Up @@ -605,7 +591,7 @@ func updateFollowListEvent(followAction FollowManagment) {
currentOneHopNetwork = append(currentOneHopNetwork, localFollows...)
case Delete:
//reducedFollows := deleteRemoteFollow(followAction.FollowEntity.PublicKey)
reducedFollows := deleteLocalFollow(followAction.FollowEntity.PublicKey)
reducedFollows := deleteLocalFollow(followAction.FollowEntity.PubKey)
if reducedFollows != nil {
currentOneHopNetwork = append(currentOneHopNetwork, reducedFollows...)
} else {
Expand Down
8 changes: 4 additions & 4 deletions feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,18 +360,18 @@ func updateAllFeeds() {
return
}
for _, currentEntity := range currentEntities {
parsedFeed, entity := parseFeedForPubkey(currentEntity.PublicKey, s.DeleteFailingFeeds)
parsedFeed, entity := parseFeedForPubkey(currentEntity.PubKey, s.DeleteFailingFeeds)
if parsedFeed == nil {
return
}

if err := createMetadataNote(currentEntity.PublicKey, currentEntity.PrivateKey, parsedFeed, s.DefaultProfilePicUrl); err != nil {
if err := createMetadataNote(currentEntity.PubKey, currentEntity.PrivateKey, parsedFeed, s.DefaultProfilePicUrl); err != nil {
log.Printf("[ERROR] could not create metadata note: %s", err)
}

for _, item := range parsedFeed.Items {
defaultCreatedAt := time.Unix(time.Now().Unix(), 0)
evt := feedItemToNote(currentEntity.PublicKey, item, parsedFeed, defaultCreatedAt, entity.URL, s.MaxContentLength)
evt := feedItemToNote(currentEntity.PubKey, item, parsedFeed, defaultCreatedAt, entity.URL, s.MaxContentLength)
if entity.LastUpdate < evt.CreatedAt.Time().Unix() {
if err := evt.Sign(entity.PrivateKey); err != nil {
log.Printf("[ERROR] %s", err)
Expand All @@ -392,7 +392,7 @@ func updateAllFeeds() {
}
}

if err := updateEntityInBookmarkEvent(entity.PublicKey, latestCreatedAt); err != nil {
if err := updateEntityInBookmarkEvent(entity.PubKey, latestCreatedAt); err != nil {
log.Printf("[ERROR] feed entity %s not updated", entity.URL)
}

Expand Down
Loading

0 comments on commit 6cce51a

Please sign in to comment.