creation of a dedicated mastodon service
This commit is contained in:
parent
97015ba0fe
commit
756e36f2f7
|
@ -17,7 +17,6 @@ import { StreamComponent } from "./components/stream/stream.component";
|
|||
import { StreamsSelectionFooterComponent } from "./components/streams-selection-footer/streams-selection-footer.component";
|
||||
import { RegisterNewAccountComponent } from "./pages/register-new-account/register-new-account.component";
|
||||
import { AuthService } from "./services/auth.service";
|
||||
import { AccountsService } from "./services/accounts.service";
|
||||
import { StreamingService } from "./services/streaming.service";
|
||||
import { RegisteredAppsState } from "./states/registered-apps.state";
|
||||
import { AccountsState } from "./states/accounts.state";
|
||||
|
@ -28,6 +27,7 @@ import { ColumnsEditorComponent } from './components/floating-column/columns-edi
|
|||
import { MessageEditorComponent } from './components/floating-column/message-editor/message-editor.component';
|
||||
import { StreamsState } from "./states/streams.state";
|
||||
import { StatusComponent } from "./components/stream/status/status.component";
|
||||
import { MastodonService } from "./services/mastodon.service";
|
||||
|
||||
const routes: Routes = [
|
||||
{ path: "", redirectTo: "home", pathMatch: "full" },
|
||||
|
@ -65,11 +65,7 @@ const routes: Routes = [
|
|||
]),
|
||||
NgxsStoragePluginModule.forRoot()
|
||||
],
|
||||
providers: [AuthService, NavigationService, AccountsService, StreamingService, { provide: APP_INITIALIZER, useFactory: settingsServiceFactory, deps: [AccountsService], multi: true }],
|
||||
providers: [AuthService, NavigationService, MastodonService, StreamingService],
|
||||
bootstrap: [AppComponent]
|
||||
})
|
||||
export class AppModule { }
|
||||
|
||||
function settingsServiceFactory(service: AccountsService) {
|
||||
return () => service.load();
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@ import { Store } from "@ngxs/store";
|
|||
|
||||
import { Account } from "../../services/models/mastodon.interfaces";
|
||||
import { AccountWrapper } from "../../models/account.models";
|
||||
import { AccountsService } from "../../services/accounts.service";
|
||||
import { AccountsStateModel, AccountInfo } from "../../states/accounts.state";
|
||||
import { NavigationService } from "../../services/navigation.service";
|
||||
import { MastodonService } from "../../services/mastodon.service";
|
||||
|
||||
|
||||
@Component({
|
||||
|
@ -23,7 +23,7 @@ export class LeftSideBarComponent implements OnInit, OnDestroy {
|
|||
|
||||
constructor(
|
||||
private readonly navigationService: NavigationService,
|
||||
private readonly accountsService: AccountsService,
|
||||
private readonly mastodonService: MastodonService,
|
||||
private readonly store: Store) {
|
||||
|
||||
this.accounts$ = this.store.select(state => state.registeredaccounts.accounts);
|
||||
|
@ -42,7 +42,7 @@ export class LeftSideBarComponent implements OnInit, OnDestroy {
|
|||
this.accounts.push(accWrapper);
|
||||
this.loadedAccounts[accWrapper.username] = acc;
|
||||
|
||||
this.accountsService.retrieveAccountDetails(acc)
|
||||
this.mastodonService.retrieveAccountDetails(acc)
|
||||
.then((result: Account) => {
|
||||
accWrapper.avatar = result.avatar;
|
||||
});
|
||||
|
|
|
@ -29,7 +29,6 @@ export class StreamComponent implements OnInit {
|
|||
const user = splitedUserName[0];
|
||||
const instance = splitedUserName[1];
|
||||
this.account = this.getRegisteredAccounts().find(x => x.username == user && x.instance == instance);
|
||||
// this.type = streamElement.type;
|
||||
|
||||
this.retrieveToots(); //TODO change this for WebSockets
|
||||
this.launchWebsocket();
|
||||
|
|
|
@ -5,9 +5,9 @@ import { Observable } from "rxjs";
|
|||
|
||||
import { AuthService } from "../../services/auth.service";
|
||||
import { TokenData, AppData } from "../../services/models/mastodon.interfaces";
|
||||
import { AccountsService } from "../../services/accounts.service";
|
||||
import { AddRegisteredApp, RegisteredAppsState, RegisteredAppsStateModel, AppInfo } from "../../states/registered-apps.state";
|
||||
import { AccountInfo, AddAccount } from "../../states/accounts.state";
|
||||
import { MastodonService } from "../../services/mastodon.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-register-new-account",
|
||||
|
@ -23,7 +23,6 @@ export class RegisterNewAccountComponent implements OnInit {
|
|||
|
||||
constructor(
|
||||
private readonly authService: AuthService,
|
||||
private readonly accountsService: AccountsService,
|
||||
private readonly store: Store,
|
||||
private readonly activatedRoute: ActivatedRoute) {
|
||||
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
import { Injectable } from "@angular/core";
|
||||
import { Http, Headers, Response } from "@angular/http";
|
||||
import { Subject, BehaviorSubject } from "rxjs";
|
||||
|
||||
import { TokenData, Account } from "./models/mastodon.interfaces";
|
||||
import { ApiRoutes } from "./models/api.settings";
|
||||
import { AccountInfo } from "../states/accounts.state";
|
||||
import { HttpClient, HttpHeaders } from "@angular/common/http";
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class AccountsService {
|
||||
|
||||
private apiRoutes = new ApiRoutes();
|
||||
|
||||
constructor(private readonly httpClient: HttpClient) {}
|
||||
|
||||
retrieveAccountDetails(account: AccountInfo): Promise<Account> {
|
||||
const headers = new HttpHeaders({'Authorization':`Bearer ${account.token.access_token}`});
|
||||
return this.httpClient.get<Account>('https://' + account.instance + this.apiRoutes.getCurrentAccount, {headers: headers}).toPromise();
|
||||
}
|
||||
|
||||
load(): any {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { MastodonService } from './mastodon.service';
|
||||
|
||||
describe('MastodonService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [MastodonService]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([MastodonService], (service: MastodonService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
|
@ -0,0 +1,18 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { HttpHeaders, HttpClient } from '@angular/common/http';
|
||||
|
||||
import { ApiRoutes } from './models/api.settings';
|
||||
import { Account } from "./models/mastodon.interfaces";
|
||||
import { AccountInfo } from '../states/accounts.state';
|
||||
|
||||
@Injectable()
|
||||
export class MastodonService {
|
||||
private apiRoutes = new ApiRoutes();
|
||||
|
||||
constructor(private readonly httpClient: HttpClient) {}
|
||||
|
||||
retrieveAccountDetails(account: AccountInfo): Promise<Account> {
|
||||
const headers = new HttpHeaders({'Authorization':`Bearer ${account.token.access_token}`});
|
||||
return this.httpClient.get<Account>('https://' + account.instance + this.apiRoutes.getCurrentAccount, {headers: headers}).toPromise();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue