~james/core

core/api/org_tangled/feedgetTimeline.go -rw-r--r-- 5.2 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 15 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT.

package org_tangled

// schema: org.tangled.feed.getTimeline

import (
	"context"
	"encoding/json"
	"fmt"

	"github.com/bluesky-social/indigo/lex/util"
)

const (
	FeedGetTimelineNSID = "org.tangled.feed.getTimeline"
)

// FeedGetTimeline_FollowEvent is a "followEvent" in the org.tangled.feed.getTimeline schema.
//
// A user followed another user.
//
// RECORDTYPE: FeedGetTimeline_FollowEvent
type FeedGetTimeline_FollowEvent struct {
	LexiconTypeID string                         `json:"$type,const=org.tangled.feed.getTimeline#followEvent" cborgen:"$type,const=org.tangled.feed.getTimeline#followEvent"`
	Actor         *ActorDefs_ProfileViewBasic    `json:"actor" cborgen:"actor"`
	Cid           string                         `json:"cid" cborgen:"cid"`
	Subject       *ActorDefs_ProfileViewDetailed `json:"subject" cborgen:"subject"`
	Uri           string                         `json:"uri" cborgen:"uri"`
}

// FeedGetTimeline_Output is the output of a org.tangled.feed.getTimeline call.
type FeedGetTimeline_Output struct {
	Cursor *string                         `json:"cursor,omitempty" cborgen:"cursor,omitempty"`
	Feed   []*FeedGetTimeline_TimelineItem `json:"feed" cborgen:"feed"`
}

// FeedGetTimeline_RepoEvent is a "repoEvent" in the org.tangled.feed.getTimeline schema.
//
// A repository was created (or forked). The actor is repo.owner.
//
// RECORDTYPE: FeedGetTimeline_RepoEvent
type FeedGetTimeline_RepoEvent struct {
	LexiconTypeID string                  `json:"$type,const=org.tangled.feed.getTimeline#repoEvent" cborgen:"$type,const=org.tangled.feed.getTimeline#repoEvent"`
	Cid           string                  `json:"cid" cborgen:"cid"`
	Repo          *RepoDefs_RepoViewBasic `json:"repo" cborgen:"repo"`
	// source: Fork parent, present only if this repo is a fork.
	Source *RepoDefs_RepoViewBasic `json:"source,omitempty" cborgen:"source,omitempty"`
	Uri    string                  `json:"uri" cborgen:"uri"`
}

// FeedGetTimeline_StarEvent is a "starEvent" in the org.tangled.feed.getTimeline schema.
//
// A repository was starred.
//
// RECORDTYPE: FeedGetTimeline_StarEvent
type FeedGetTimeline_StarEvent struct {
	LexiconTypeID string `json:"$type,const=org.tangled.feed.getTimeline#starEvent" cborgen:"$type,const=org.tangled.feed.getTimeline#starEvent"`
	// actor: Who starred.
	Actor *ActorDefs_ProfileViewBasic `json:"actor" cborgen:"actor"`
	Cid   string                      `json:"cid" cborgen:"cid"`
	// repo: The starred repo.
	Repo *RepoDefs_RepoViewBasic `json:"repo" cborgen:"repo"`
	Uri  string                  `json:"uri" cborgen:"uri"`
}

// FeedGetTimeline_TimelineItem is a "timelineItem" in the org.tangled.feed.getTimeline schema.
type FeedGetTimeline_TimelineItem struct {
	Event   *FeedGetTimeline_TimelineItem_Event `json:"event" cborgen:"event"`
	EventAt string                              `json:"eventAt" cborgen:"eventAt"`
}

type FeedGetTimeline_TimelineItem_Event struct {
	FeedGetTimeline_RepoEvent   *FeedGetTimeline_RepoEvent
	FeedGetTimeline_StarEvent   *FeedGetTimeline_StarEvent
	FeedGetTimeline_FollowEvent *FeedGetTimeline_FollowEvent
}

func (t *FeedGetTimeline_TimelineItem_Event) MarshalJSON() ([]byte, error) {
	if t.FeedGetTimeline_RepoEvent != nil {
		t.FeedGetTimeline_RepoEvent.LexiconTypeID = "org.tangled.feed.getTimeline#repoEvent"
		return json.Marshal(t.FeedGetTimeline_RepoEvent)
	}
	if t.FeedGetTimeline_StarEvent != nil {
		t.FeedGetTimeline_StarEvent.LexiconTypeID = "org.tangled.feed.getTimeline#starEvent"
		return json.Marshal(t.FeedGetTimeline_StarEvent)
	}
	if t.FeedGetTimeline_FollowEvent != nil {
		t.FeedGetTimeline_FollowEvent.LexiconTypeID = "org.tangled.feed.getTimeline#followEvent"
		return json.Marshal(t.FeedGetTimeline_FollowEvent)
	}
	return nil, fmt.Errorf("cannot marshal empty enum")
}
func (t *FeedGetTimeline_TimelineItem_Event) UnmarshalJSON(b []byte) error {
	typ, err := util.TypeExtract(b)
	if err != nil {
		return err
	}

	switch typ {
	case "org.tangled.feed.getTimeline#repoEvent":
		t.FeedGetTimeline_RepoEvent = new(FeedGetTimeline_RepoEvent)
		return json.Unmarshal(b, t.FeedGetTimeline_RepoEvent)
	case "org.tangled.feed.getTimeline#starEvent":
		t.FeedGetTimeline_StarEvent = new(FeedGetTimeline_StarEvent)
		return json.Unmarshal(b, t.FeedGetTimeline_StarEvent)
	case "org.tangled.feed.getTimeline#followEvent":
		t.FeedGetTimeline_FollowEvent = new(FeedGetTimeline_FollowEvent)
		return json.Unmarshal(b, t.FeedGetTimeline_FollowEvent)

	default:
		return nil
	}
}

// FeedGetTimeline calls the XRPC method "org.tangled.feed.getTimeline".
//
// viewer: TODO: deprecate this and use auth instead.
func FeedGetTimeline(ctx context.Context, c util.LexClient, cursor string, followingOnly bool, limit int64, viewer string) (*FeedGetTimeline_Output, error) {
	var out FeedGetTimeline_Output

	params := map[string]interface{}{}
	if cursor != "" {
		params["cursor"] = cursor
	}
	if followingOnly {
		params["followingOnly"] = followingOnly
	}
	if limit != 0 {
		params["limit"] = limit
	}
	if viewer != "" {
		params["viewer"] = viewer
	}
	if err := c.LexDo(ctx, util.Query, "", "org.tangled.feed.getTimeline", params, nil, &out); err != nil {
		return nil, err
	}

	return &out, nil
}