first iteration (and very candid) toots retrieval
This commit is contained in:
parent
7e78496214
commit
7239dfa0fa
|
@ -111,6 +111,7 @@
|
||||||
<TypeScriptCompile Include="src\app\services\auth.service.ts" />
|
<TypeScriptCompile Include="src\app\services\auth.service.ts" />
|
||||||
<TypeScriptCompile Include="src\app\services\models\api.settings.ts" />
|
<TypeScriptCompile Include="src\app\services\models\api.settings.ts" />
|
||||||
<TypeScriptCompile Include="src\app\services\models\mastodon.interfaces.ts" />
|
<TypeScriptCompile Include="src\app\services\models\mastodon.interfaces.ts" />
|
||||||
|
<TypeScriptCompile Include="src\app\services\streams.service.ts" />
|
||||||
<TypeScriptCompile Include="src\environments\environment.prod.ts" />
|
<TypeScriptCompile Include="src\environments\environment.prod.ts" />
|
||||||
<TypeScriptCompile Include="src\environments\environment.ts" />
|
<TypeScriptCompile Include="src\environments\environment.ts" />
|
||||||
<TypeScriptCompile Include="src\main.ts" />
|
<TypeScriptCompile Include="src\main.ts" />
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { BrowserModule } from "@angular/platform-browser";
|
import { BrowserModule } from "@angular/platform-browser";
|
||||||
import { FormsModule } from "@angular/forms";
|
import { FormsModule } from "@angular/forms";
|
||||||
import { HttpModule } from "@angular/http";
|
import { HttpModule } from "@angular/http";
|
||||||
import { NgModule } from "@angular/core";
|
import { NgModule, APP_INITIALIZER } from "@angular/core";
|
||||||
import { RouterModule, Routes } from "@angular/router";
|
import { RouterModule, Routes } from "@angular/router";
|
||||||
|
|
||||||
import { NgxElectronModule } from "ngx-electron";
|
import { NgxElectronModule } from "ngx-electron";
|
||||||
|
@ -15,6 +15,7 @@ import { TootComponent } from "./components/toot/toot.component";
|
||||||
import { RegisterNewAccountComponent } from "./pages/register-new-account/register-new-account.component";
|
import { RegisterNewAccountComponent } from "./pages/register-new-account/register-new-account.component";
|
||||||
import { AuthService } from "./services/auth.service";
|
import { AuthService } from "./services/auth.service";
|
||||||
import { AccountsService } from "./services/accounts.service";
|
import { AccountsService } from "./services/accounts.service";
|
||||||
|
import { StreamsService } from "./services/streams.service";
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{ path: "", redirectTo: "home", pathMatch: "full" },
|
{ path: "", redirectTo: "home", pathMatch: "full" },
|
||||||
|
@ -40,7 +41,11 @@ const routes: Routes = [
|
||||||
NgxElectronModule,
|
NgxElectronModule,
|
||||||
RouterModule.forRoot(routes)
|
RouterModule.forRoot(routes)
|
||||||
],
|
],
|
||||||
providers: [AuthService, AccountsService],
|
providers: [AuthService, AccountsService, StreamsService, { provide: APP_INITIALIZER, useFactory: settingsServiceFactory, deps: [AccountsService], multi: true }],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
})
|
})
|
||||||
export class AppModule { }
|
export class AppModule { }
|
||||||
|
|
||||||
|
function settingsServiceFactory(service: AccountsService) {
|
||||||
|
return () => service.load();
|
||||||
|
}
|
||||||
|
|
|
@ -18,17 +18,16 @@ export class LeftSideBarComponent implements OnInit, OnDestroy {
|
||||||
private readonly accountsService: AccountsService) { }
|
private readonly accountsService: AccountsService) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.accountsService.init.then(() => {
|
this.sub = this.accountsService.accountsSubject.subscribe((accounts: LocalAccount[]) => {
|
||||||
this.sub = this.accountsService.accountsSubject.subscribe((accounts: LocalAccount[]) => {
|
this.accounts.length = 0;
|
||||||
this.accounts.length = 0;
|
|
||||||
|
|
||||||
for (let acc of accounts) {
|
for (let acc of accounts) {
|
||||||
const acc1 = new AccountWrapper();
|
const accWrapper = new AccountWrapper();
|
||||||
acc1.username = acc.mastodonAccount.username;
|
console.warn(acc);
|
||||||
acc1.avatar = acc.mastodonAccount.avatar;
|
accWrapper.username = `${acc.mastodonAccount.username}@${acc.mastodonInstance.replace("https://", "")}`;
|
||||||
this.accounts.push(acc1);
|
accWrapper.avatar = acc.mastodonAccount.avatar;
|
||||||
}
|
this.accounts.push(accWrapper);
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//const acc1 = new AccountWrapper();
|
//const acc1 = new AccountWrapper();
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Component, OnInit } from "@angular/core";
|
import { Component, OnInit, Input } from "@angular/core";
|
||||||
import { Stream, TootWrapper } from "../../models/stream.models";
|
import { Stream, TootWrapper } from "../../models/stream.models";
|
||||||
import { AccountWrapper } from "../../models/account.models";
|
import { AccountWrapper } from "../../models/account.models";
|
||||||
|
|
||||||
|
@ -8,27 +8,44 @@ import { AccountWrapper } from "../../models/account.models";
|
||||||
styleUrls: ["./stream.component.css"]
|
styleUrls: ["./stream.component.css"]
|
||||||
})
|
})
|
||||||
export class StreamComponent implements OnInit {
|
export class StreamComponent implements OnInit {
|
||||||
stream: Stream;
|
private _stream: Stream;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
set stream(stream: Stream) {
|
||||||
|
console.warn(stream);
|
||||||
|
|
||||||
|
this._stream = stream;
|
||||||
|
this._stream.statuses.subscribe((toots: TootWrapper[]) => {
|
||||||
|
for (let t of toots) {
|
||||||
|
this.toots.push(t);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get stream(): Stream {
|
||||||
|
return this._stream;
|
||||||
|
}
|
||||||
|
|
||||||
toots: TootWrapper[] = [];
|
toots: TootWrapper[] = [];
|
||||||
|
|
||||||
constructor() { }
|
constructor() { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
//Stubs
|
//Stubs
|
||||||
const newStream = new Stream();
|
//const newStream = new Stream();
|
||||||
newStream.streamName = "Stream Name";
|
//newStream.streamName = "Stream Name";
|
||||||
this.stream = newStream;
|
//this.stream = newStream;
|
||||||
|
|
||||||
const acc1 = new AccountWrapper();
|
//const acc1 = new AccountWrapper();
|
||||||
acc1.username = "@mastodon.social@Gargron";
|
//acc1.username = "@mastodon.social@Gargron";
|
||||||
acc1.avatar = "https://files.mastodon.social/accounts/avatars/000/000/001/original/4df197532c6b768c.png";
|
//acc1.avatar = "https://files.mastodon.social/accounts/avatars/000/000/001/original/4df197532c6b768c.png";
|
||||||
|
|
||||||
for (let i = 0; i < 20; i++) {
|
//for (let i = 0; i < 20; i++) {
|
||||||
const newToot = new TootWrapper();
|
// const newToot = new TootWrapper();
|
||||||
newToot.account = acc1;
|
// newToot.account = acc1;
|
||||||
newToot.content = "Lorem Elsass ipsum tristique semper elit jetz gehts los lacus habitant Hans sagittis baeckeoffe condimentum id, salu bredele ch'ai libero, ftomi! hop Pfourtz ! id munster auctor, Miss Dahlias rhoncus Yo dû. Salu bissame turpis ante amet non sed gal Spätzle Gal !";
|
// newToot.content = "Lorem Elsass ipsum tristique semper elit jetz gehts los lacus habitant Hans sagittis baeckeoffe condimentum id, salu bredele ch'ai libero, ftomi! hop Pfourtz ! id munster auctor, Miss Dahlias rhoncus Yo dû. Salu bissame turpis ante amet non sed gal Spätzle Gal !";
|
||||||
this.toots.push(newToot);
|
// this.toots.push(newToot);
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
goToTop(): boolean {
|
goToTop(): boolean {
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
<div id="mam-toot-avatar">
|
<div id="mam-toot-avatar">
|
||||||
<img src="{{ toot.account.avatar }}" />
|
<img src="{{ toot.account.avatar }}" />
|
||||||
</div>
|
</div>
|
||||||
<div id="mam-toot-content">
|
<div id="mam-toot-content" innerHTML="{{toot.content}}">
|
||||||
<p>{{ toot.content }}</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
|
import { Account } from "../services/models/mastodon.interfaces";
|
||||||
|
|
||||||
|
|
||||||
export class AccountWrapper {
|
export class AccountWrapper {
|
||||||
|
constructor() {
|
||||||
|
}
|
||||||
|
|
||||||
id: number;
|
id: number;
|
||||||
username: string;
|
username: string;
|
||||||
display_name: string;
|
display_name: string;
|
||||||
|
|
|
@ -1,10 +1,75 @@
|
||||||
|
import { Http, Headers, Response } from "@angular/http";
|
||||||
|
import { BehaviorSubject } from "rxjs";
|
||||||
|
|
||||||
import { AccountWrapper } from "./account.models";
|
import { AccountWrapper } from "./account.models";
|
||||||
|
import { LocalAccount } from "../services/accounts.service";
|
||||||
|
import { ApiRoutes } from "../services/models/api.settings";
|
||||||
|
import { Account, Status } from "../services/models/mastodon.interfaces";
|
||||||
|
|
||||||
export class Stream {
|
export class Stream {
|
||||||
streamName: string;
|
private apiRoutes = new ApiRoutes();
|
||||||
|
|
||||||
|
statuses = new BehaviorSubject<TootWrapper[]>([]);
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private readonly httpService: Http,
|
||||||
|
public streamName: string,
|
||||||
|
private readonly type: StreamTypeEnum,
|
||||||
|
private readonly account: LocalAccount) {
|
||||||
|
|
||||||
|
this.retrieveToots(); //TODO change this for WebSockets
|
||||||
|
}
|
||||||
|
|
||||||
|
private retrieveToots(): void {
|
||||||
|
const route = this.getTimelineRoute();
|
||||||
|
|
||||||
|
const header = new Headers();
|
||||||
|
header.append("Authorization", `Bearer ${this.account.tokenData.access_token}`);
|
||||||
|
|
||||||
|
this.httpService.get(this.account.mastodonInstance + route, { headers: header }).toPromise()
|
||||||
|
.then((res: Response) => {
|
||||||
|
const statuses = (res.json() as Status[])
|
||||||
|
.map((status: Status) => {
|
||||||
|
return new TootWrapper(status);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.statuses.next(statuses);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private getTimelineRoute(): string {
|
||||||
|
switch (this.type) {
|
||||||
|
case StreamTypeEnum.Home:
|
||||||
|
return this.apiRoutes.getHomeTimeline;
|
||||||
|
case StreamTypeEnum.Local:
|
||||||
|
return this.apiRoutes.getPublicTimeline + `?Local=true`;
|
||||||
|
case StreamTypeEnum.Public:
|
||||||
|
return this.apiRoutes.getPublicTimeline + `?Local=false`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum StreamTypeEnum {
|
||||||
|
Home,
|
||||||
|
Public,
|
||||||
|
Local
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export class TootWrapper {
|
export class TootWrapper {
|
||||||
account: AccountWrapper;
|
constructor(status: Status) {
|
||||||
|
console.warn(status);
|
||||||
|
|
||||||
|
this.account = new AccountWrapper();
|
||||||
|
this.account.username = status.account.username;
|
||||||
|
this.account.display_name = status.account.display_name;
|
||||||
|
this.account.avatar = status.account.avatar;
|
||||||
|
|
||||||
|
this.content = status.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
account: AccountWrapper; //TODO change to Account
|
||||||
content: string;
|
content: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<div id="mam-main-display">
|
<div id="mam-main-display">
|
||||||
<div *ngFor="let s of streams" class="mam-stream-column">
|
<div *ngFor="let s of streams" class="mam-stream-column">
|
||||||
<app-stream></app-stream>
|
<app-stream [stream]="s"></app-stream>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,20 +1,32 @@
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from "@angular/core";
|
||||||
import { Stream } from 'stream';
|
|
||||||
|
import { Stream } from "../../models/stream.models";
|
||||||
|
import { StreamsService } from "../../services/streams.service";
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-streams-main-display',
|
selector: "app-streams-main-display",
|
||||||
templateUrl: './streams-main-display.component.html',
|
templateUrl: "./streams-main-display.component.html",
|
||||||
styleUrls: ['./streams-main-display.component.css']
|
styleUrls: ["./streams-main-display.component.css"]
|
||||||
})
|
})
|
||||||
export class StreamsMainDisplayComponent implements OnInit {
|
export class StreamsMainDisplayComponent implements OnInit {
|
||||||
streams: Stream[] = [];
|
streams: Stream[] = [];
|
||||||
|
|
||||||
constructor() { }
|
constructor(private readonly streamService: StreamsService) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
for (let i = 0; i < 3; i++) {
|
this.streamService.streamsSubject.subscribe((streams: Stream[]) => {
|
||||||
this.streams.push(new Stream());
|
for (let s of streams) {
|
||||||
}
|
this.streams.push(s);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//for (let i = 0; i < 3; i++) {
|
||||||
|
// this.streams.push(new Stream());
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,13 +10,16 @@ export class AccountsService {
|
||||||
private localAccountKey = "localAccounts";
|
private localAccountKey = "localAccounts";
|
||||||
private apiRoutes = new ApiRoutes();
|
private apiRoutes = new ApiRoutes();
|
||||||
|
|
||||||
accountsSubject: Subject<LocalAccount[]>;
|
accountsSubject: BehaviorSubject<LocalAccount[]>;
|
||||||
init: Promise<any>; //TODO load this service before any UI action
|
|
||||||
|
|
||||||
constructor(private readonly httpService: Http) {
|
constructor(private readonly httpService: Http) {}
|
||||||
this.init = this.getAllLocalAccount().then((accounts) => {
|
|
||||||
this.accountsSubject = new BehaviorSubject<LocalAccount[]>(accounts);
|
load(): Promise<boolean> {
|
||||||
});
|
return this.getAllLocalAccount()
|
||||||
|
.then((accounts) => {
|
||||||
|
this.accountsSubject = new BehaviorSubject<LocalAccount[]>(accounts);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addNewAccount(mastodonInstance: string, email: string, token: TokenData) {
|
addNewAccount(mastodonInstance: string, email: string, token: TokenData) {
|
||||||
|
|
|
@ -99,7 +99,7 @@ export interface Status {
|
||||||
id: string;
|
id: string;
|
||||||
uri: string;
|
uri: string;
|
||||||
url: string;
|
url: string;
|
||||||
account: string;
|
account: Account;
|
||||||
in_reply_to_id: string;
|
in_reply_to_id: string;
|
||||||
in_reply_to_account_id: string;
|
in_reply_to_account_id: string;
|
||||||
reblog: string;
|
reblog: string;
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
import { Injectable } from "@angular/core";
|
||||||
|
import { Http } from "@angular/http";
|
||||||
|
import { BehaviorSubject } from "rxjs";
|
||||||
|
|
||||||
|
import { Stream, StreamTypeEnum } from "../models/stream.models";
|
||||||
|
import { AccountsService, LocalAccount } from "./accounts.service";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class StreamsService {
|
||||||
|
streamsSubject = new BehaviorSubject<Stream[]>([]);
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private readonly httpService: Http,
|
||||||
|
private readonly accountsService: AccountsService) {
|
||||||
|
|
||||||
|
// Return home/local/public of all accounts
|
||||||
|
this.accountsService.accountsSubject
|
||||||
|
.subscribe((accounts: LocalAccount[]) => {
|
||||||
|
const streams: Stream[] = [];
|
||||||
|
for (let acc of accounts) {
|
||||||
|
const homeStream = new Stream(this.httpService, "Home", StreamTypeEnum.Home, acc);
|
||||||
|
const localStream = new Stream(this.httpService, "Local", StreamTypeEnum.Local, acc);
|
||||||
|
const publicStream = new Stream(this.httpService, "Public", StreamTypeEnum.Public, acc);
|
||||||
|
|
||||||
|
streams.push(homeStream);
|
||||||
|
streams.push(localStream);
|
||||||
|
streams.push(publicStream);
|
||||||
|
}
|
||||||
|
this.streamsSubject.next(streams);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//getStreams(): void {
|
||||||
|
// // Return home/local/public of all accounts
|
||||||
|
// this.accountsService.accountsSubject
|
||||||
|
// .map((accounts: LocalAccount[]) => {
|
||||||
|
// const streams: Stream[] = [];
|
||||||
|
// for (let acc of accounts) {
|
||||||
|
// const homeStream = new Stream(this.httpService, "Home", StreamTypeEnum.Home, acc);
|
||||||
|
// const localStream = new Stream(this.httpService, "Local", StreamTypeEnum.Local, acc);
|
||||||
|
// const publicStream = new Stream(this.httpService, "Public", StreamTypeEnum.Public, acc);
|
||||||
|
|
||||||
|
// streams.push(homeStream);
|
||||||
|
// streams.push(localStream);
|
||||||
|
// streams.push(publicStream);
|
||||||
|
// }
|
||||||
|
// this.streamsSubject.next(streams);
|
||||||
|
// });
|
||||||
|
}
|
Loading…
Reference in New Issue