From 756deb56f403b5dfb55248481c207685b651885f Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Sun, 17 Nov 2019 00:57:58 -0500 Subject: [PATCH] starting notification retrieval --- .../stream-notifications.component.ts | 48 ++++++++++++++++++- src/app/services/tools.service.ts | 9 +++- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/app/components/stream/stream-notifications/stream-notifications.component.ts b/src/app/components/stream/stream-notifications/stream-notifications.component.ts index a0715f5b..75ceb8d3 100644 --- a/src/app/components/stream/stream-notifications/stream-notifications.component.ts +++ b/src/app/components/stream/stream-notifications/stream-notifications.component.ts @@ -1,4 +1,10 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; +import { Observable } from 'rxjs'; + +import { Notification } from '../../../services/models/mastodon.interfaces'; +import { StreamElement } from '../../../states/streams.state'; +import { OpenThreadEvent, ToolsService } from '../../../services/tools.service'; +import { MastodonService } from '../../../services/mastodon.service'; @Component({ selector: 'app-stream-notifications', @@ -8,9 +14,43 @@ import { Component, OnInit } from '@angular/core'; export class StreamNotificationsComponent implements OnInit { displayingAll = true; - constructor() { } + notifications: Notification[] = []; + mentions: Notification[] = []; + + @Input() streamElement: StreamElement; + @Input() goToTop: Observable; + + @Output() browseAccountEvent = new EventEmitter(); + @Output() browseHashtagEvent = new EventEmitter(); + @Output() browseThreadEvent = new EventEmitter(); + + constructor( + private readonly mastodonService: MastodonService, + private readonly toolsService: ToolsService) { } ngOnInit() { + this.loadNotifications(); + + } + + loadNotifications(): any { + const account = this.toolsService.getAccountById(this.streamElement.accountId); + + let getMentionsPromise = this.mastodonService.getNotifications(account, ['favourite', 'follow', 'reblog', 'poll'], null, null, 10) + .then((notifications: Notification[]) => { + this.mentions = notifications; + }) + .catch(err => { + }); + + let getNotificationPromise = this.mastodonService.getNotifications(account, null, null, null, 10) + .then((notifications: Notification[]) => { + this.notifications = notifications; + }) + .catch(err => { + }); + + throw new Error("Method not implemented."); } select(value: 'all' | 'mentions'): boolean { @@ -21,4 +61,8 @@ export class StreamNotificationsComponent implements OnInit { } return false; } + + onScroll() { + + } } diff --git a/src/app/services/tools.service.ts b/src/app/services/tools.service.ts index 398e53bd..73e7bd69 100644 --- a/src/app/services/tools.service.ts +++ b/src/app/services/tools.service.ts @@ -11,7 +11,7 @@ import { AppInfo, RegisteredAppsStateModel } from '../states/registered-apps.sta @Injectable({ providedIn: 'root' }) -export class ToolsService { +export class ToolsService { private accountAvatar: { [id: string]: string; } = {}; private instanceInfos: { [id: string]: InstanceInfo } = {}; @@ -68,6 +68,11 @@ export class ToolsService { return regAccounts.filter(x => x.isSelected); } + getAccountById(accountId: string): AccountInfo { + let regAccounts = this.store.snapshot().registeredaccounts.accounts; + return regAccounts.find(x => x.id === accountId); + } + getAccountSettings(account: AccountInfo): AccountSettings { let accountsSettings = this.store.snapshot().globalsettings.settings.accountSettings; let accountSettings = accountsSettings.find(x => x.accountId === account.id); @@ -118,7 +123,7 @@ export class ToolsService { ); return foundAccount; }); - } + } getStatusUsableByAccount(account: AccountInfo, originalStatus: StatusWrapper): Promise { const isProvider = originalStatus.provider.id === account.id;