changing timeline filters works
This commit is contained in:
parent
03ee058fe7
commit
bbf26561f6
10 changed files with 100 additions and 5 deletions
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
type Adapter interface {
|
type Adapter interface {
|
||||||
Init(Settings, *chan SocketData) error
|
Init(Settings, *chan SocketData) error
|
||||||
|
Stop()
|
||||||
Name() string
|
Name() string
|
||||||
Subscribe(string, *string) []error
|
Subscribe(string, *string) []error
|
||||||
Fetch(string, []string) error
|
Fetch(string, []string) error
|
||||||
|
|
|
@ -101,13 +101,19 @@ func (self *HonkAdapter) Init(settings Settings, data *chan SocketData) error {
|
||||||
|
|
||||||
self.token = string(buf[:])
|
self.token = string(buf[:])
|
||||||
fmt.Println(self.token)
|
fmt.Println(self.token)
|
||||||
|
|
||||||
|
self.stop = make(chan bool)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *HonkAdapter) Stop() {
|
||||||
|
close(self.stop)
|
||||||
|
}
|
||||||
|
|
||||||
func (self *HonkAdapter) Subscribe(filter string, target *string) []error {
|
func (self *HonkAdapter) Subscribe(filter string, target *string) []error {
|
||||||
|
|
||||||
if self.stop != nil {
|
if self.stop != nil {
|
||||||
close(self.stop)
|
close(self.stop)
|
||||||
self.maxId = 0
|
|
||||||
}
|
}
|
||||||
self.stop = make(chan bool)
|
self.stop = make(chan bool)
|
||||||
|
|
||||||
|
@ -117,14 +123,18 @@ func (self *HonkAdapter) Subscribe(filter string, target *string) []error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *HonkAdapter) gethonks(filter string, target *string) {
|
func (self *HonkAdapter) gethonks(filter string, target *string) {
|
||||||
|
x := self.stop
|
||||||
|
self.maxId = 0
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case _, ok := <-self.stop:
|
case _, ok := <-x:
|
||||||
if !ok {
|
if !ok {
|
||||||
|
fmt.Println("stopping! filter was " + filter)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
fmt.Println("getting honks, filter is " + filter)
|
||||||
honkForm := url.Values{
|
honkForm := url.Values{
|
||||||
"action": []string{"gethonks"},
|
"action": []string{"gethonks"},
|
||||||
"token": []string{self.token},
|
"token": []string{self.token},
|
||||||
|
|
|
@ -50,6 +50,10 @@ func (self *MastoAdapter) Init(settings Settings, data *chan SocketData) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *MastoAdapter) Stop() {
|
||||||
|
close(self.stop)
|
||||||
|
}
|
||||||
|
|
||||||
func (self *MastoAdapter) Subscribe(filter string, target *string) []error {
|
func (self *MastoAdapter) Subscribe(filter string, target *string) []error {
|
||||||
// TODO: decode separate timelines and hashtags
|
// TODO: decode separate timelines and hashtags
|
||||||
// for now, the filter is just the timeline
|
// for now, the filter is just the timeline
|
||||||
|
@ -71,7 +75,8 @@ func (self *MastoAdapter) Subscribe(filter string, target *string) []error {
|
||||||
return []error{err}
|
return []error{err}
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
for e := range self.events {
|
ee := self.events
|
||||||
|
for e := range ee {
|
||||||
log.Printf("event: %s !!!", e.Event)
|
log.Printf("event: %s !!!", e.Event)
|
||||||
switch e.Event {
|
switch e.Event {
|
||||||
case "error":
|
case "error":
|
||||||
|
|
|
@ -45,6 +45,10 @@ func (self *MisskeyAdapter) Name() string {
|
||||||
return self.nickname
|
return self.nickname
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *MisskeyAdapter) Stop() {
|
||||||
|
close(self.stop)
|
||||||
|
}
|
||||||
|
|
||||||
func (self *MisskeyAdapter) Init(settings Settings, data *chan SocketData) error {
|
func (self *MisskeyAdapter) Init(settings Settings, data *chan SocketData) error {
|
||||||
log.Print("initializing misskey adapter")
|
log.Print("initializing misskey adapter")
|
||||||
|
|
||||||
|
@ -102,9 +106,11 @@ func (self *MisskeyAdapter) poll() {
|
||||||
var notesService *n.Service
|
var notesService *n.Service
|
||||||
var timelineService *tl.Service
|
var timelineService *tl.Service
|
||||||
|
|
||||||
|
x := self.stop
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case _, ok := <-self.stop:
|
case _, ok := <-x:
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,11 @@ func (self *NostrAdapter) Init(settings Settings, data *chan SocketData) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *NostrAdapter) Stop() {
|
||||||
|
// nostr has native streaming so we don't need to do anything in this method
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (self *NostrAdapter) Subscribe(filter string, target *string) []error {
|
func (self *NostrAdapter) Subscribe(filter string, target *string) []error {
|
||||||
var filters nostr.Filters
|
var filters nostr.Filters
|
||||||
err := json.Unmarshal([]byte(filter), &filters)
|
err := json.Unmarshal([]byte(filter), &filters)
|
||||||
|
|
1
frontend/dist/index.html
vendored
1
frontend/dist/index.html
vendored
|
@ -16,6 +16,7 @@
|
||||||
<main>
|
<main>
|
||||||
<div class='uicolumn'>
|
<div class='uicolumn'>
|
||||||
<details open><summary>settings</summary><div id="settings_parent"></div></details>
|
<details open><summary>settings</summary><div id="settings_parent"></div></details>
|
||||||
|
<details open><summary>timeline-select</summary><div id="timeline_filter_parent"></div></details>
|
||||||
<details open><summary>timeline</summary><div id="timeline_parent"></div></details>
|
<details open><summary>timeline</summary><div id="timeline_parent"></div></details>
|
||||||
</div>
|
</div>
|
||||||
<div class='uicolumn'>
|
<div class='uicolumn'>
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { SettingsElement } from "./settings-element"
|
||||||
import { ProfileElement } from "./profile-element"
|
import { ProfileElement } from "./profile-element"
|
||||||
import { AuthorMessagesElement } from "./author-messages-element"
|
import { AuthorMessagesElement } from "./author-messages-element"
|
||||||
import { TimelineElement } from "./timeline-element"
|
import { TimelineElement } from "./timeline-element"
|
||||||
|
import { TimelineFilterElement } from "./timeline-filter-element"
|
||||||
import {DatagramSocket} from "./websocket"
|
import {DatagramSocket} from "./websocket"
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
|
@ -18,6 +19,7 @@ function main() {
|
||||||
customElements.define("underbbs-profile", ProfileElement);
|
customElements.define("underbbs-profile", ProfileElement);
|
||||||
customElements.define("underbbs-author-messages", AuthorMessagesElement);
|
customElements.define("underbbs-author-messages", AuthorMessagesElement);
|
||||||
customElements.define("underbbs-timeline", TimelineElement);
|
customElements.define("underbbs-timeline", TimelineElement);
|
||||||
|
customElements.define("underbbs-timeline-filter", TimelineFilterElement);
|
||||||
|
|
||||||
util._("closeErr", util.closeErr);
|
util._("closeErr", util.closeErr);
|
||||||
|
|
||||||
|
@ -40,6 +42,11 @@ function main() {
|
||||||
if (timelineParent) {
|
if (timelineParent) {
|
||||||
timelineParent.innerHTML = "<underbbs-timeline id='honkstream' data-adapter='honk' data-target='home' data-gateway=''></underbbs-timeline>";
|
timelineParent.innerHTML = "<underbbs-timeline id='honkstream' data-adapter='honk' data-target='home' data-gateway=''></underbbs-timeline>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let timelineSelectParent = util.$("timeline_filter_parent");
|
||||||
|
if (timelineSelectParent) {
|
||||||
|
timelineSelectParent.innerHTML = "<underbbs-timeline-filter data-target='honkstream' data-filters='home::home/atme::atme'></underbbs-timeline-filter>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
|
|
@ -32,6 +32,7 @@ export class TimelineElement extends HTMLElement {
|
||||||
}
|
}
|
||||||
this._timeline = next;
|
this._timeline = next;
|
||||||
this.innerHTML = `<ul class="messages_list"></ul>`;
|
this.innerHTML = `<ul class="messages_list"></ul>`;
|
||||||
|
this._messages = [];
|
||||||
if (this._subscriber) {
|
if (this._subscriber) {
|
||||||
this._subscriber.subscribe(next);
|
this._subscriber.subscribe(next);
|
||||||
}
|
}
|
||||||
|
|
55
frontend/ts/timeline-filter-element.ts
Normal file
55
frontend/ts/timeline-filter-element.ts
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
export class TimelineFilter {
|
||||||
|
public name: string = "";
|
||||||
|
public filter: string = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TimelineFilterElement extends HTMLElement {
|
||||||
|
static observedAttributes = [ "data-filters", "data-target", "data-latest" ];
|
||||||
|
|
||||||
|
private _filters: TimelineFilter[] = [];
|
||||||
|
private _target: string = "";
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.innerHTML = "<select class='filter_select'></select>"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
connectedCallback() {
|
||||||
|
this._target = this.getAttribute("data-target") ?? "";
|
||||||
|
this._filters = (this.getAttribute("data-filters") ?? "").split("/").map(f=>{
|
||||||
|
const ff = f.split("::");
|
||||||
|
return <TimelineFilter>{ name: ff[0], filter: ff[1] };
|
||||||
|
});
|
||||||
|
let html = "<select class='filter_select'>";
|
||||||
|
html += this._filters.reduce((self: string, f: TimelineFilter)=>{
|
||||||
|
self += `<option value='${f.filter}'>${f.name}</option>`;
|
||||||
|
return self;
|
||||||
|
}, "");
|
||||||
|
html += "</select>";
|
||||||
|
this.innerHTML = html;
|
||||||
|
const select = this.querySelector(".filter_select");
|
||||||
|
if (select) {
|
||||||
|
select.addEventListener("change", this.onChanges.bind(this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onChanges() {
|
||||||
|
const select = this.querySelector(".filter_select") as HTMLSelectElement;
|
||||||
|
|
||||||
|
// change target's target!
|
||||||
|
const target = document.getElementById(this._target);
|
||||||
|
if (target) {
|
||||||
|
target.setAttribute("data-target", select?.options[select.selectedIndex].value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
attributeChangedCallback(attr: string, prev: string, next: string) {
|
||||||
|
switch (attr) {
|
||||||
|
case "data-latest":
|
||||||
|
const select = this.querySelector(".filter_select") as HTMLSelectElement;
|
||||||
|
select.selectedIndex = this._filters.findIndex(f=>f.name == next);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -97,6 +97,10 @@ func (self *BBSServer) subscribeHandler(w http.ResponseWriter, r *http.Request)
|
||||||
|
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
self.logf("subscriber has disconnected")
|
self.logf("subscriber has disconnected")
|
||||||
|
for _, a := range self.subscribers[s] {
|
||||||
|
// keeps any adapter's subscription from trying to send on the data channel after we close it
|
||||||
|
a.Stop()
|
||||||
|
}
|
||||||
close(s.data)
|
close(s.data)
|
||||||
return //ctx.Err()
|
return //ctx.Err()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue