Merge pull request #180 from NicolasConstant/develop

0.18.0 PR
This commit is contained in:
Nicolas Constant 2019-10-08 23:51:50 -04:00 committed by GitHub
commit 832ed7e9bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 598 additions and 131 deletions

View File

@ -1,6 +1,6 @@
{
"name": "sengi",
"version": "0.17.1",
"version": "0.18.0",
"license": "AGPL-3.0-or-later",
"main": "main-electron.js",
"description": "A multi-account desktop client for Mastodon and Pleroma",

View File

@ -34,6 +34,7 @@ import { FloatingColumnComponent } from './components/floating-column/floating-c
import { StreamsState } from "./states/streams.state";
import { StatusComponent } from "./components/stream/status/status.component";
import { MastodonService } from "./services/mastodon.service";
import { MastodonWrapperService } from "./services/mastodon-wrapper.service";
import { AttachementsComponent } from './components/stream/status/attachements/attachements.component';
import { SettingsComponent } from './components/floating-column/settings/settings.component';
import { AddNewAccountComponent } from './components/floating-column/add-new-account/add-new-account.component';
@ -163,7 +164,7 @@ const routes: Routes = [
ContextMenuModule.forRoot(),
HotkeyModule.forRoot()
],
providers: [AuthService, NavigationService, NotificationService, MastodonService, StreamingService],
providers: [AuthService, NavigationService, NotificationService, MastodonWrapperService, MastodonService, StreamingService],
bootstrap: [AppComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})

View File

@ -1,7 +1,7 @@
import { Component, OnInit, Input, Output, EventEmitter, OnDestroy } from '@angular/core';
import { ToolsService } from '../../../services/tools.service';
import { MastodonService } from '../../../services/mastodon.service';
import { MastodonWrapperService } from '../../../services/mastodon-wrapper.service';
import { NotificationService } from '../../../services/notification.service';
import { Results, Account } from '../../../services/models/mastodon.interfaces';
import { Actions } from '@ngxs/store';
@ -29,6 +29,7 @@ export class AutosuggestComponent implements OnInit, OnDestroy {
this._pattern = value;
this.analysePattern(value);
} else {
this._pattern = null;
this.accounts.length = 0;
this.hashtags.length = 0;
}
@ -43,7 +44,7 @@ export class AutosuggestComponent implements OnInit, OnDestroy {
constructor(
private readonly notificationService: NotificationService,
private readonly toolsService: ToolsService,
private readonly mastodonService: MastodonService) { }
private readonly mastodonService: MastodonWrapperService) { }
ngOnInit() {
if (this.autoSuggestUserActionsStream) {

View File

@ -21,9 +21,9 @@
(suggestionSelectedEvent)="suggestionSelected($event)" (hasSuggestionsEvent)="suggestionsChanged($event)">
</app-autosuggest>
<app-poll-editor *ngIf="pollIsActive"></app-poll-editor>
<app-poll-editor *ngIf="instanceSupportsPoll && pollIsActive"></app-poll-editor>
<app-status-scheduler class="scheduler" *ngIf="scheduleIsActive"></app-status-scheduler>
<app-status-scheduler class="scheduler" *ngIf="instanceSupportsScheduling && scheduleIsActive"></app-status-scheduler>
<div class="status-editor__footer" #footer>
<button type="submit" title="reply" class="status-editor__footer--send-button" *ngIf="statusReplyingToWrapper">
@ -54,11 +54,13 @@
<fa-icon [icon]="faEnvelope" *ngIf="selectedPrivacy === 'DM'"></fa-icon>
</a>
<a href class="status-editor__footer--link status-editor__footer--add-poll" title="add poll" (click)="addPoll()">
<a href *ngIf="instanceSupportsPoll"
class="status-editor__footer--link status-editor__footer--add-poll" title="add poll" (click)="addPoll()">
<fa-icon [icon]="faPollH"></fa-icon>
</a>
<a href class="status-editor__footer--link" title="schedule" (click)="schedule()">
<a href *ngIf="instanceSupportsScheduling"
class="status-editor__footer--link" title="schedule" (click)="schedule()">
<fa-icon [icon]="faClock"></fa-icon>
</a>
</div>

View File

@ -200,7 +200,8 @@ $counter-width: 90px;
.scheduler {
display: block;
margin: 0 5px;
margin: 0 5px;
border-bottom: 1px solid whitesmoke;
}
@import '~@angular/cdk/overlay-prebuilt.css';

View File

@ -7,9 +7,10 @@ import { faPaperclip, faGlobe, faGlobeAmericas, faLock, faLockOpen, faEnvelope,
import { faClock, faWindowClose as faWindowCloseRegular } from "@fortawesome/free-regular-svg-icons";
import { ContextMenuService, ContextMenuComponent } from 'ngx-contextmenu';
import { MastodonService, VisibilityEnum, PollParameters } from '../../services/mastodon.service';
import { VisibilityEnum, PollParameters } from '../../services/mastodon.service';
import { MastodonWrapperService } from '../../services/mastodon-wrapper.service';
import { Status, Attachment } from '../../services/models/mastodon.interfaces';
import { ToolsService } from '../../services/tools.service';
import { ToolsService, InstanceInfo, InstanceType } from '../../services/tools.service';
import { NotificationService } from '../../services/notification.service';
import { StatusWrapper } from '../../models/common.model';
import { AccountInfo } from '../../states/accounts.state';
@ -109,6 +110,8 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
isSending: boolean;
mentionTooFarAwayError: boolean;
autosuggestData: string = null;
instanceSupportsPoll = true;
instanceSupportsScheduling = true;
private statusLoaded: boolean;
private hasSuggestions: boolean;
@ -160,7 +163,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
private readonly store: Store,
private readonly notificationService: NotificationService,
private readonly toolsService: ToolsService,
private readonly mastodonService: MastodonService,
private readonly mastodonService: MastodonWrapperService,
private readonly instancesInfoService: InstancesInfoService,
private readonly mediaService: MediaService,
private readonly overlay: Overlay,
@ -223,23 +226,50 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
if (!this.statusLoaded) return;
const caretPosition = this.replyElement.nativeElement.selectionStart;
const word = this.getWordByPos(status, caretPosition);
if (word && word.length > 0 && (word.startsWith('@') || word.startsWith('#'))) {
const lastChar = status.substr(caretPosition - 1, 1);
const lastCharIsSpace = lastChar === ' ';
const splitedStatus = status.split(/(\r\n|\n|\r)/);
let offset = 0;
let currentSection = '';
for(let x of splitedStatus){
const sectionLength = [...x].length;
if(offset + sectionLength >= caretPosition){
currentSection = x;
break;
} else {
offset += sectionLength;
}
};
const word = this.getWordByPos(currentSection, caretPosition - offset);
if (!lastCharIsSpace && word && word.length > 0 && (word.startsWith('@') || word.startsWith('#'))) {
this.autosuggestData = word;
return;
}
this.autosuggestData = null;
this.hasSuggestions = false;
}
private getWordByPos(str, pos) {
str = str.replace(/(\r\n|\n|\r)/gm, "");
var left = str.substr(0, pos);
var right = str.substr(pos);
var preText = str.substring(0, pos);
if (preText.indexOf(" ") > 0) {
var words = preText.split(" ");
return words[words.length - 1]; //return last word
}
else {
return preText;
}
left = left.replace(/^.+ /g, "");
right = right.replace(/ .+$/g, "");
// // str = str.replace(/(\r\n|\n|\r)/gm, "");
// var left = str.substr(0, pos);
// var right = str.substr(pos);
return left + right;
// left = left.replace(/^.+ /g, "");
// right = right.replace(/ .+$/g, "");
// return left + right;
}
private focus(caretPos = null) {
@ -295,6 +325,19 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
if (!this.statusReplyingToWrapper && !this.replyingUserHandle) {
this.getDefaultPrivacy();
}
this.toolsService.getInstanceInfo(this.selectedAccount)
.then((instance: InstanceInfo) => {
if(instance.type === InstanceType.Pixelfed){
this.instanceSupportsPoll = false;
this.instanceSupportsScheduling = false;
this.pollIsActive = false;
this.scheduleIsActive = false;
} else {
this.instanceSupportsPoll = true;
this.instanceSupportsScheduling = true;
}
});
}
}
@ -477,7 +520,6 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
return false;
}
private sendStatus(account: AccountInfo, status: string, visibility: VisibilityEnum, title: string, previousStatus: Status, attachments: Attachment[], poll: PollParameters, scheduledAt: string): Promise<Status> {
let parsedStatus = this.parseStatus(status);
let resultPromise = Promise.resolve(previousStatus);
@ -567,7 +609,6 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
return status.split(' ').filter(x => x.indexOf('@') === 0 && x.length > 1);
}
suggestionSelected(selection: AutosuggestSelection) {
if (this.status.includes(selection.pattern)) {

View File

@ -2,8 +2,6 @@
.scheduler {
background-color: $scheduler-background;
//margin: 0 5px;
border-bottom: 1px solid whitesmoke;
&__input {
color: whitesmoke;

View File

@ -5,7 +5,7 @@ import { AccountWrapper } from '../../../../models/account.models';
import { OpenThreadEvent } from '../../../../services/tools.service';
import { StatusWrapper } from '../../../../models/common.model';
import { NotificationService } from '../../../../services/notification.service';
import { MastodonService } from '../../../../services/mastodon.service';
import { MastodonWrapperService } from '../../../../services/mastodon-wrapper.service';
import { Conversation } from '../../../../services/models/mastodon.interfaces';
import { AccountInfo } from '../../../../states/accounts.state';
@ -43,7 +43,7 @@ export class DirectMessagesComponent implements OnInit {
constructor(
private readonly notificationService: NotificationService,
private readonly mastodonService: MastodonService) { }
private readonly mastodonService: MastodonWrapperService) { }
ngOnInit() {
}

View File

@ -3,7 +3,8 @@ import { Component, OnInit, Output, EventEmitter, Input, ViewChild, ElementRef }
import { StatusWrapper } from '../../../../models/common.model';
import { OpenThreadEvent } from '../../../../services/tools.service';
import { AccountWrapper } from '../../../../models/account.models';
import { MastodonService, FavoriteResult } from '../../../../services/mastodon.service';
import { FavoriteResult } from '../../../../services/mastodon.service';
import { MastodonWrapperService } from '../../../../services/mastodon-wrapper.service';
import { Status } from '../../../../services/models/mastodon.interfaces';
import { NotificationService } from '../../../../services/notification.service';
import { resetCompiledComponents } from '@angular/core/src/render3/jit/module';
@ -41,7 +42,7 @@ export class FavoritesComponent implements OnInit {
constructor(
private readonly notificationService: NotificationService,
private readonly mastodonService: MastodonService) { }
private readonly mastodonService: MastodonWrapperService) { }
ngOnInit() {
}

View File

@ -6,7 +6,7 @@ import { Subscription } from 'rxjs';
import { AccountWrapper } from '../../../models/account.models';
import { UserNotificationService, UserNotification } from '../../../services/user-notification.service';
import { OpenThreadEvent } from '../../../services/tools.service';
import { MastodonService } from '../../../services/mastodon.service';
import { MastodonWrapperService } from '../../../services/mastodon-wrapper.service';
import { Account } from "../../../services/models/mastodon.interfaces";
import { NotificationService } from '../../../services/notification.service';
import { AccountInfo } from '../../../states/accounts.state';
@ -49,7 +49,7 @@ export class ManageAccountComponent implements OnInit, OnDestroy {
private _account: AccountWrapper;
constructor(
private readonly mastodonService: MastodonService,
private readonly mastodonService: MastodonWrapperService,
private readonly notificationService: NotificationService,
private readonly userNotificationService: UserNotificationService) { }

View File

@ -5,7 +5,7 @@ import { AccountWrapper } from '../../../../models/account.models';
import { UserNotificationService, UserNotification } from '../../../../services/user-notification.service';
import { StatusWrapper } from '../../../../models/common.model';
import { Status, Notification } from '../../../../services/models/mastodon.interfaces';
import { MastodonService } from '../../../../services/mastodon.service';
import { MastodonWrapperService } from '../../../../services/mastodon-wrapper.service';
import { NotificationService } from '../../../../services/notification.service';
import { OpenThreadEvent } from '../../../../services/tools.service';
@ -45,7 +45,7 @@ export class MentionsComponent implements OnInit, OnDestroy {
constructor(
private readonly notificationService: NotificationService,
private readonly userNotificationService: UserNotificationService,
private readonly mastodonService: MastodonService) {
private readonly mastodonService: MastodonWrapperService) {
}

View File

@ -2,7 +2,7 @@ import { Component, OnInit, Input } from '@angular/core';
import { faTimes } from "@fortawesome/free-solid-svg-icons";
import { StreamWrapper } from '../my-account.component';
import { MastodonService } from '../../../../../services/mastodon.service';
import { MastodonWrapperService } from '../../../../../services/mastodon-wrapper.service';
import { AccountWrapper } from '../../../../../models/account.models';
import { NotificationService } from '../../../../../services/notification.service';
import { Account, Relationship, Instance } from "../../../../../services/models/mastodon.interfaces";
@ -26,7 +26,7 @@ export class ListEditorComponent implements OnInit {
constructor(
private readonly notificationService: NotificationService,
private readonly mastodonService: MastodonService) { }
private readonly mastodonService: MastodonWrapperService) { }
ngOnInit() {
this.accountsInList.length = 0;

View File

@ -9,7 +9,7 @@ import { StreamElement, StreamTypeEnum, AddStream, RemoveAllStreams, RemoveStrea
import { AccountWrapper } from '../../../../models/account.models';
import { RemoveAccount } from '../../../../states/accounts.state';
import { NavigationService } from '../../../../services/navigation.service';
import { MastodonService } from '../../../../services/mastodon.service';
import { MastodonWrapperService } from '../../../../services/mastodon-wrapper.service';
import { ToolsService } from '../../../../services/tools.service';
import { AccountSettings } from '../../../../states/settings.state';
@ -51,7 +51,7 @@ export class MyAccountComponent implements OnInit, OnDestroy {
private readonly store: Store,
private readonly toolsService: ToolsService,
private readonly navigationService: NavigationService,
private readonly mastodonService: MastodonService,
private readonly mastodonService: MastodonWrapperService,
private readonly notificationService: NotificationService) { }
ngOnInit() {

View File

@ -7,7 +7,7 @@ import { AccountWrapper } from '../../../../models/account.models';
import { UserNotificationService, UserNotification } from '../../../../services/user-notification.service';
import { StatusWrapper } from '../../../../models/common.model';
import { Notification, Account } from '../../../../services/models/mastodon.interfaces';
import { MastodonService } from '../../../../services/mastodon.service';
import { MastodonWrapperService } from '../../../../services/mastodon-wrapper.service';
import { NotificationService } from '../../../../services/notification.service';
import { AccountInfo } from '../../../../states/accounts.state';
import { OpenThreadEvent, ToolsService } from '../../../../services/tools.service';
@ -49,7 +49,7 @@ export class NotificationsComponent implements OnInit, OnDestroy {
private readonly toolsService: ToolsService,
private readonly notificationService: NotificationService,
private readonly userNotificationService: UserNotificationService,
private readonly mastodonService: MastodonService) { }
private readonly mastodonService: MastodonWrapperService) { }
ngOnInit() {
}

View File

@ -3,7 +3,7 @@ import { Component, OnInit, Input, ViewChild, Output, EventEmitter } from '@angu
import { AccountInfo } from '../../../../states/accounts.state';
import { ScheduledStatus } from '../../../../services/models/mastodon.interfaces';
import { ToolsService } from '../../../../services/tools.service';
import { MastodonService } from '../../../../services/mastodon.service';
import { MastodonWrapperService } from '../../../../services/mastodon-wrapper.service';
import { NotificationService } from '../../../../services/notification.service';
import { ScheduledStatusService } from '../../../../services/scheduled-status.service';
import { StatusSchedulerComponent } from '../../../../components/create-status/status-scheduler/status-scheduler.component';
@ -28,7 +28,7 @@ export class ScheduledStatusComponent implements OnInit {
constructor(
private readonly scheduledStatusService: ScheduledStatusService,
private readonly notificationService: NotificationService,
private readonly mastodonService: MastodonService,
private readonly mastodonService: MastodonWrapperService,
private readonly toolsService: ToolsService) { }
ngOnInit() {

View File

@ -1,7 +1,7 @@
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { HttpErrorResponse } from '@angular/common/http';
import { MastodonService } from '../../../services/mastodon.service';
import { MastodonWrapperService } from '../../../services/mastodon-wrapper.service';
import { AccountInfo } from '../../../states/accounts.state';
import { Results, Account } from '../../../services/models/mastodon.interfaces';
import { ToolsService, OpenThreadEvent } from '../../../services/tools.service';
@ -29,7 +29,7 @@ export class SearchComponent implements OnInit {
constructor(
private readonly notificationService: NotificationService,
private readonly toolsService: ToolsService,
private readonly mastodonService: MastodonService) { }
private readonly mastodonService: MastodonWrapperService) { }
ngOnInit() {
}

View File

@ -5,7 +5,7 @@ import { Observable, Subscription } from 'rxjs';
import { faWindowClose, faReply, faRetweet, faStar, faEllipsisH, faLock, faEnvelope } from "@fortawesome/free-solid-svg-icons";
import { faWindowClose as faWindowCloseRegular } from "@fortawesome/free-regular-svg-icons";
import { MastodonService } from '../../../../services/mastodon.service';
import { MastodonWrapperService } from '../../../../services/mastodon-wrapper.service';
import { AccountInfo } from '../../../../states/accounts.state';
import { Status, Account, Results } from '../../../../services/models/mastodon.interfaces';
import { ToolsService, OpenThreadEvent } from '../../../../services/tools.service';
@ -59,7 +59,7 @@ export class ActionBarComponent implements OnInit, OnDestroy {
constructor(
private readonly store: Store,
private readonly toolsService: ToolsService,
private readonly mastodonService: MastodonService,
private readonly mastodonService: MastodonWrapperService,
private readonly notificationService: NotificationService) {
this.accounts$ = this.store.select(state => state.registeredaccounts.accounts);
@ -155,7 +155,11 @@ export class ActionBarComponent implements OnInit, OnDestroy {
if (boostedStatus.pleroma) {
this.bootedStatePerAccountId[account.id] = boostedStatus.reblog !== null; //FIXME: when Pleroma will return the good status
} else {
this.bootedStatePerAccountId[account.id] = boostedStatus.reblogged;
let reblogged = boostedStatus.reblogged; //FIXME: when pixelfed will return the good status
if(reblogged === null){
reblogged = !this.bootedStatePerAccountId[account.id];
}
this.bootedStatePerAccountId[account.id] = reblogged;
}
this.checkIfBoosted();
@ -187,9 +191,12 @@ export class ActionBarComponent implements OnInit, OnDestroy {
}
})
.then((favoritedStatus: Status) => {
this.favoriteStatePerAccountId[account.id] = favoritedStatus.favourited;
let favourited = favoritedStatus.favourited; //FIXME: when pixelfed will return the good status
if(favourited === null){
favourited = !this.favoriteStatePerAccountId[account.id];
}
this.favoriteStatePerAccountId[account.id] = favourited;
this.checkIfFavorited();
// this.isFavorited = !this.isFavorited;
})
.catch((err: HttpErrorResponse) => {
this.notificationService.notifyHttpError(err, account);

View File

@ -9,7 +9,7 @@ import { ToolsService, OpenThreadEvent } from '../../../../../services/tools.ser
import { StatusWrapper } from '../../../../../models/common.model';
import { NavigationService } from '../../../../../services/navigation.service';
import { AccountInfo } from '../../../../../states/accounts.state';
import { MastodonService } from '../../../../../services/mastodon.service';
import { MastodonWrapperService } from '../../../../../services/mastodon-wrapper.service';
import { NotificationService } from '../../../../../services/notification.service';
@ -39,7 +39,7 @@ export class StatusUserContextMenuComponent implements OnInit, OnDestroy {
constructor(
private readonly store: Store,
private readonly mastodonService: MastodonService,
private readonly mastodonService: MastodonWrapperService,
private readonly notificationService: NotificationService,
private readonly navigationService: NavigationService,
private readonly toolsService: ToolsService,

View File

@ -1,38 +1,34 @@
<div class="card" *ngIf="card.type === 'link' || card.type === 'video'">
<a *ngIf="card.type === 'link'" class="card__link" href="{{ card.url }}" target="_blank" title="{{ card.title }}">
<img *ngIf="card.image" class="card__link--image" src="{{ card.image }}" alt="" />
<div *ngIf="!card.image" class="card__link--image">
<fa-icon class="card__link--image--logo" [icon]="faFileAlt"></fa-icon>
<div class="card-data" *ngIf="card.type === 'link' || card.type === 'video'">
<a *ngIf="card.type === 'link'" class="card-data__link" href="{{ card.url }}" target="_blank" title="{{ card.title }}">
<img *ngIf="card.image" class="card-data__link--image" src="{{ card.image }}" alt="" />
<div *ngIf="!card.image" class="card-data__link--image">
<fa-icon class="card-data__link--image--logo" [icon]="faFileAlt"></fa-icon>
</div>
<h3 class="card__link--title">{{ card.title }}</h3>
<span class="card__link--host">{{ host }}</span>
<h3 class="card-data__link--title">{{ card.title }}</h3>
<span class="card-data__link--host">{{ host }}</span>
</a>
<div *ngIf="card.type === 'photo'" class="card__photo">
<div *ngIf="card.type === 'photo'" class="card-data__photo">
</div>
<div *ngIf="card.type === 'video'" class="card__video">
<div *ngIf="!showHtml" class="card__video--preview">
<div class="card__video--preview--controls">
<a href class="card__video--preview--link" (click)="play()" title="play">
<div *ngIf="card.type === 'video'" class="card-data__video">
<div *ngIf="!showHtml" class="card-data__video--preview">
<div class="card-data__video--preview--controls">
<a href class="card-data__video--preview--link" (click)="play()" title="play">
<fa-icon [icon]="faPlay"></fa-icon>
</a>
<a href class="card__video--preview--link" (click)="expand()" title="open">
<a href class="card-data__video--preview--link" (click)="expand()" title="open">
<fa-icon [icon]="faExpand"></fa-icon>
</a>
<a href="{{ card.url }}" class="card__video--preview--link" target="_blank" title="browse">
<a href="{{ card.url }}" class="card-data__video--preview--link" target="_blank" title="browse">
<fa-icon [icon]="faExternalLinkAlt"></fa-icon>
</a>
</div>
<img src="{{ card.image }}" class="card__video--preview--image" />
<img src="{{ card.image }}" class="card-data__video--preview--image" />
</div>
<div #video *ngIf="showHtml" class="card__video--content" [innerHTML]="html">
<div #video *ngIf="showHtml" class="card-data__video--content" [innerHTML]="html">
</div>
<!-- {{ card.html }} -->
<!-- <div [innerHTML]="html">
</div> -->
</div>
<div *ngIf="card.type === 'rich'" class="card__rich" [innerHTML]="html"></div>
<div *ngIf="card.type === 'rich'" class="card-data__rich" [innerHTML]="html"></div>
</div>

View File

@ -1,13 +1,12 @@
@import "variables";
// @import "mixins";
.card {
border: 1px solid $card-border-color;
background-color: $column-background;
.card-data {
border-radius: 3px;
border: 0px;
transition: all .2s;
white-space: nowrap;
overflow: hidden;
overflow: hidden;
&:hover {
background-color: lighten($column-background, 5);
@ -17,6 +16,9 @@
display: block;
text-decoration: none;
color: whitesmoke;
overflow: auto;
border: 1px solid $card-border-color;
&--image {
width: 55px;

View File

@ -5,7 +5,7 @@ import { faLock } from "@fortawesome/free-solid-svg-icons";
import { Poll, PollOption, Status } from '../../../../services/models/mastodon.interfaces';
import { AccountInfo } from '../../../../states/accounts.state';
import { MastodonService } from '../../../../services/mastodon.service';
import { MastodonWrapperService } from '../../../../services/mastodon-wrapper.service';
import { NotificationService } from '../../../../services/notification.service';
import { ToolsService } from '../../../../services/tools.service';
import { StatusWrapper } from '../../../../models/common.model';
@ -67,7 +67,7 @@ export class PollComponent implements OnInit {
private readonly store: Store,
private notificationService: NotificationService,
private toolsService: ToolsService,
private mastodonService: MastodonService) {
private mastodonService: MastodonWrapperService) {
this.accounts$ = this.store.select(state => state.registeredaccounts.accounts);
}

View File

@ -7,7 +7,7 @@ import { StreamElement } from '../../../states/streams.state';
import { AccountInfo } from '../../../states/accounts.state';
import { StreamingService, EventEnum, StreamingWrapper, StatusUpdate } from '../../../services/streaming.service';
import { Status } from '../../../services/models/mastodon.interfaces';
import { MastodonService } from '../../../services/mastodon.service';
import { MastodonWrapperService } from '../../../services/mastodon-wrapper.service';
import { NotificationService } from '../../../services/notification.service';
import { OpenThreadEvent, ToolsService } from '../../../services/tools.service';
import { StatusWrapper } from '../../../models/common.model';
@ -67,7 +67,7 @@ export class StreamStatusesComponent implements OnInit, OnDestroy {
private readonly toolsService: ToolsService,
private readonly notificationService: NotificationService,
private readonly streamingService: StreamingService,
private readonly mastodonService: MastodonService) {
private readonly mastodonService: MastodonWrapperService) {
this.streams$ = this.store.select(state => state.streamsstatemodel.streams);
}
@ -180,13 +180,7 @@ export class StreamStatusesComponent implements OnInit, OnDestroy {
top: 0,
behavior: 'smooth'
});
}, 0);
setTimeout(() => {
stream.scrollTo({
top: 0,
behavior: 'auto'
});
}, 250);
}, 10);
return false;
}

View File

@ -2,13 +2,14 @@ import { Component, OnInit, OnDestroy, Input, Output, EventEmitter, ViewChildren
import { HttpErrorResponse } from '@angular/common/http';
import { Subscription } from 'rxjs';
import { MastodonService } from '../../../services/mastodon.service';
import { MastodonWrapperService } from '../../../services/mastodon-wrapper.service';
import { ToolsService, OpenThreadEvent } from '../../../services/tools.service';
import { Results, Context, Status } from '../../../services/models/mastodon.interfaces';
import { NotificationService, NewReplyData } from '../../../services/notification.service';
import { AccountInfo } from '../../../states/accounts.state';
import { StatusWrapper } from '../../../models/common.model';
import { StatusComponent } from '../status/status.component';
import scrollIntoView from 'scroll-into-view-if-needed';
@Component({
selector: 'app-thread',
@ -50,7 +51,7 @@ export class ThreadComponent implements OnInit, OnDestroy {
constructor(
private readonly notificationService: NotificationService,
private readonly toolsService: ToolsService,
private readonly mastodonService: MastodonService) { }
private readonly mastodonService: MastodonWrapperService) { }
ngOnInit() {
if (this.refreshEventEmitter) {
@ -177,11 +178,11 @@ export class ThreadComponent implements OnInit, OnDestroy {
setTimeout(() => {
const el = this.statusChildren.toArray()[position];
el.isSelected = true;
// el.elem.nativeElement.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'start' });
// el.elem.nativeElement.scrollIntoView({ behavior: 'auto', block: 'start', inline: 'nearest' });
// el.elem.nativeElement.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'start' });
el.elem.nativeElement.scrollIntoViewIfNeeded({ behavior: 'auto', block: 'start', inline: 'nearest' });
}, 0);
//el.elem.nativeElement.scrollIntoViewIfNeeded({ behavior: 'auto', block: 'start', inline: 'nearest' });
scrollIntoView(el.elem.nativeElement, { behavior: 'smooth', block: 'nearest'});
}, 250);
})
.catch((err: HttpErrorResponse) => {
this.notificationService.notifyHttpError(err, currentAccount);
@ -218,6 +219,11 @@ export class ThreadComponent implements OnInit, OnDestroy {
const statuses = this.statusChildren.toArray();
statuses.forEach(x => {
x.removeContentWarning();
if(x.isSelected){
setTimeout(() => {
scrollIntoView(x.elem.nativeElement, { behavior: 'auto', block: 'nearest'});
}, 0);
}
});
this.hasContentWarnings = false;
return false;

View File

@ -6,7 +6,7 @@ import { Observable, Subscription } from 'rxjs';
import { Store } from '@ngxs/store';
import { Account, Status, Relationship, Attachment } from "../../../services/models/mastodon.interfaces";
import { MastodonService } from '../../../services/mastodon.service';
import { MastodonWrapperService } from '../../../services/mastodon-wrapper.service';
import { ToolsService, OpenThreadEvent } from '../../../services/tools.service';
import { NotificationService } from '../../../services/notification.service';
import { AccountInfo } from '../../../states/accounts.state';
@ -77,7 +77,7 @@ export class UserProfileComponent implements OnInit {
private readonly store: Store,
private readonly navigationService: NavigationService,
private readonly notificationService: NotificationService,
private readonly mastodonService: MastodonService,
private readonly mastodonService: MastodonWrapperService,
private readonly toolsService: ToolsService) {
this.accounts$ = this.store.select(state => state.registeredaccounts.accounts);

View File

@ -8,7 +8,7 @@ import { TokenData, Account } from "../../services/models/mastodon.interfaces";
import { RegisteredAppsStateModel, AppInfo } from "../../states/registered-apps.state";
import { AccountInfo, AddAccount, AccountsStateModel } from "../../states/accounts.state";
import { NotificationService } from "../../services/notification.service";
import { MastodonService } from '../../services/mastodon.service';
import { MastodonWrapperService } from '../../services/mastodon-wrapper.service';
@Component({
selector: "app-register-new-account",
@ -24,7 +24,7 @@ export class RegisterNewAccountComponent implements OnInit {
private authStorageKey: string = 'tempAuth';
constructor(
private readonly mastodonService: MastodonService,
private readonly mastodonService: MastodonWrapperService,
private readonly notificationService: NotificationService,
private readonly authService: AuthService,
private readonly store: Store,
@ -50,7 +50,14 @@ export class RegisterNewAccountComponent implements OnInit {
let usedTokenData: TokenData;
this.authService.getToken(appDataWrapper.instance, appInfo.app.client_id, appInfo.app.client_secret, code, appInfo.app.redirect_uri)
.then((tokenData: TokenData) => {
if(tokenData.refresh_token && !tokenData.created_at){
const nowEpoch = Date.now() / 1000 | 0;
tokenData.created_at = nowEpoch;
}
usedTokenData = tokenData;
return this.mastodonService.retrieveAccountDetails({ 'instance': appDataWrapper.instance, 'id': '', 'username': '', 'order': 0, 'isSelected': true, 'token': tokenData });
})
.then((account: Account) => {
@ -103,7 +110,7 @@ export class RegisterNewAccountComponent implements OnInit {
this.errorMessage = 'No authentication code returned. Please retry.'
break;
}
}
}
private getAllSavedApps(): AppInfo[] {
const snapshot = <RegisteredAppsStateModel>this.store.snapshot().registeredapps;

View File

@ -31,6 +31,20 @@ export class AuthService {
return this.httpClient.post<TokenData>(url, bodyLoad).toPromise();
}
refreshToken(instance: string, client_id: string, client_secret: string, refresh_token: string): Promise<TokenData> {
const url = `https://${instance}/oauth/token?client_id=${client_id}&client_secret=${client_secret}&grant_type=refresh_token&refresh_token=${refresh_token}&scope=${encodeURIComponent('read write follow')}`;
const bodyLoad = {
'client_id': client_id,
'client_secret': client_secret,
'grant_type': 'refresh_token',
'refresh_token': refresh_token,
'scope': 'read write follow'
};
return this.httpClient.post<TokenData>(url, bodyLoad).toPromise();
}
createNewApplication(instance: string, appName: string, redirectUrl: string, scopes: string, website: string): Promise<AppData> {
const url = 'https://' + instance + this.apiRoutes.createApp;

View File

@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { MastodonService, VisibilityEnum } from './mastodon.service';
import { VisibilityEnum } from './mastodon.service';
import { MastodonWrapperService } from './mastodon-wrapper.service';
import { Instance, Account } from './models/mastodon.interfaces';
import { AccountInfo } from '../states/accounts.state';
@ -12,7 +13,7 @@ export class InstancesInfoService {
private cachedMaxInstanceChar: { [id: string]: Promise<number>; } = {};
private cachedDefaultPrivacy: { [id: string]: Promise<VisibilityEnum>; } = {};
constructor(private mastodonService: MastodonService) { }
constructor(private mastodonService: MastodonWrapperService) { }
getMaxStatusChars(instance: string): Promise<number> {
if (!this.cachedMaxInstanceChar[instance]) {

View File

@ -0,0 +1,12 @@
import { TestBed } from '@angular/core/testing';
import { MastodonWrapperService } from './mastodon-wrapper.service';
xdescribe('MastodonWrapperService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: MastodonWrapperService = TestBed.get(MastodonWrapperService);
expect(service).toBeTruthy();
});
});

View File

@ -0,0 +1,358 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { Account, Status, Results, Context, Relationship, Instance, Attachment, Notification, List, Poll, Emoji, Conversation, ScheduledStatus, TokenData } from "./models/mastodon.interfaces";
import { AccountInfo, UpdateAccount } from '../states/accounts.state';
import { StreamTypeEnum, StreamElement } from '../states/streams.state';
import { FavoriteResult, VisibilityEnum, PollParameters, MastodonService } from './mastodon.service';
import { AuthService } from './auth.service';
import { AppInfo, RegisteredAppsStateModel } from '../states/registered-apps.state';
@Injectable({
providedIn: 'root'
})
export class MastodonWrapperService {
constructor(
private readonly store: Store,
private readonly authService: AuthService,
private readonly mastodonService: MastodonService) { }
refreshAccountIfNeeded(accountInfo: AccountInfo): Promise<AccountInfo> {
let isExpired = false;
let storedAccountInfo = this.getStoreAccountInfo(accountInfo.id);
try {
if (storedAccountInfo.token.refresh_token) {
if (!storedAccountInfo.token.created_at || !storedAccountInfo.token.expires_in) {
isExpired = true;
} else {
const nowEpoch = Date.now() / 1000 | 0;
//Pleroma workaround
let expire_in = storedAccountInfo.token.expires_in;
if(expire_in < 3600) {
expire_in = 3600;
}
let expire_on = expire_in + storedAccountInfo.token.created_at;
isExpired = expire_on - nowEpoch <= 60 * 2;
//console.warn(`expiring in ${Math.round((expire_on - nowEpoch)/24/60/60)}days ${Math.round((expire_on - nowEpoch)/60/60)}h ${Math.round((expire_on - nowEpoch)/60)} mins`);
}
}
} catch (err) {
console.error(err);
}
if (storedAccountInfo.token.refresh_token && isExpired) {
console.warn('--------------------------');
console.warn('-------->> MARTY!! -------');
console.warn('-------->> RENEW TOKEN FFS');
console.warn('--------------------------');
const app = this.getAllSavedApps().find(x => x.instance === storedAccountInfo.instance);
return this.authService.refreshToken(storedAccountInfo.instance, app.app.client_id, app.app.client_secret, storedAccountInfo.token.refresh_token)
.then((tokenData: TokenData) => {
if (tokenData.refresh_token && !tokenData.created_at) {
const nowEpoch = Date.now() / 1000 | 0;
tokenData.created_at = nowEpoch;
}
storedAccountInfo.token = tokenData;
this.store.dispatch([new UpdateAccount(storedAccountInfo)]);
return storedAccountInfo;
})
.catch(err => {
return Promise.resolve(storedAccountInfo);
});
} else {
return Promise.resolve(storedAccountInfo);
}
}
private getAllSavedApps(): AppInfo[] {
const snapshot = <RegisteredAppsStateModel>this.store.snapshot().registeredapps;
return snapshot.apps;
}
private getStoreAccountInfo(accountId: string): AccountInfo {
var regAccounts = <AccountInfo[]>this.store.snapshot().registeredaccounts.accounts;
return regAccounts.find(x => x.id === accountId);
}
getInstance(instance: string): Promise<Instance> {
return this.mastodonService.getInstance(instance);
}
retrieveAccountDetails(account: AccountInfo): Promise<Account> {
return this.mastodonService.retrieveAccountDetails(account);
}
getTimeline(account: AccountInfo, type: StreamTypeEnum, max_id: string = null, since_id: string = null, limit: number = 20, tag: string = null, listId: string = null): Promise<Status[]> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.getTimeline(refreshedAccount, type, max_id, since_id, limit, tag, listId);
});
}
getConversations(account: AccountInfo, max_id: string = null, since_id: string = null, min_id = null, limit: number = 20): Promise<Conversation[]> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.getConversations(refreshedAccount, max_id, since_id, min_id, limit);
});
}
postNewStatus(account: AccountInfo, status: string, visibility: VisibilityEnum, spoiler: string = null, in_reply_to_id: string = null, mediaIds: string[], poll: PollParameters = null, scheduled_at: string = null): Promise<Status> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.postNewStatus(refreshedAccount, status, visibility, spoiler, in_reply_to_id, mediaIds, poll, scheduled_at);
});
}
getStatus(account: AccountInfo, statusId: string): Promise<Status> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.getStatus(refreshedAccount, statusId);
});
}
search(account: AccountInfo, query: string, version: 'v1' | 'v2', resolve: boolean = false): Promise<Results> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.search(refreshedAccount, query, version, resolve);
});
}
getAccountStatuses(account: AccountInfo, targetAccountId: number, onlyMedia: boolean, onlyPinned: boolean, excludeReplies: boolean, maxId: string, sinceId: string, limit: number = 20): Promise<Status[]> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.getAccountStatuses(refreshedAccount, targetAccountId, onlyMedia, onlyPinned, excludeReplies, maxId, sinceId, limit);
});
}
getStatusContext(account: AccountInfo, targetStatusId: string): Promise<Context> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.getStatusContext(refreshedAccount, targetStatusId);
});
}
getFavorites(account: AccountInfo, maxId: string = null): Promise<FavoriteResult> { //, minId: string = null
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.getFavorites(refreshedAccount, maxId);
});
}
searchAccount(account: AccountInfo, query: string, limit: number = 40, following: boolean = false, resolve = true): Promise<Account[]> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.searchAccount(refreshedAccount, query, limit, following, resolve);
});
}
reblog(account: AccountInfo, status: Status): Promise<Status> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.reblog(refreshedAccount, status);
});
}
unreblog(account: AccountInfo, status: Status): Promise<Status> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.unreblog(refreshedAccount, status);
});
}
favorite(account: AccountInfo, status: Status): Promise<Status> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.favorite(refreshedAccount, status);
});
}
unfavorite(account: AccountInfo, status: Status): Promise<Status> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.unfavorite(refreshedAccount, status);
});
}
getRelationships(account: AccountInfo, accountsToRetrieve: Account[]): Promise<Relationship[]> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.getRelationships(refreshedAccount, accountsToRetrieve);
});
}
follow(currentlyUsedAccount: AccountInfo, account: Account): Promise<Relationship> {
return this.refreshAccountIfNeeded(currentlyUsedAccount)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.follow(refreshedAccount, account);
});
}
unfollow(currentlyUsedAccount: AccountInfo, account: Account): Promise<Relationship> {
return this.refreshAccountIfNeeded(currentlyUsedAccount)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.unfollow(refreshedAccount, account);
});
}
uploadMediaAttachment(account: AccountInfo, file: File, description: string): Promise<Attachment> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.uploadMediaAttachment(refreshedAccount, file, description);
});
}
updateMediaAttachment(account: AccountInfo, mediaId: string, description: string): Promise<Attachment> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.updateMediaAttachment(refreshedAccount, mediaId, description);
});
}
getNotifications(account: AccountInfo, excludeTypes: string[] = null, maxId: string = null, sinceId: string = null, limit: number = 15): Promise<Notification[]> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.getNotifications(refreshedAccount, excludeTypes, maxId, sinceId, limit);
});
}
getLists(account: AccountInfo): Promise<StreamElement[]> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.getLists(refreshedAccount);
});
}
createList(account: AccountInfo, title: string): Promise<StreamElement> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.createList(refreshedAccount, title);
});
}
deleteList(account: AccountInfo, listId: string): Promise<any> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.deleteList(refreshedAccount, listId);
});
}
getListAccounts(account: AccountInfo, listId: string): Promise<Account[]> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.getListAccounts(refreshedAccount, listId);
});
}
addAccountToList(account: AccountInfo, listId: string, accountId: number): Promise<any> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.addAccountToList(refreshedAccount, listId, accountId);
});
}
removeAccountFromList(account: AccountInfo, listId: string, accountId: number): Promise<any> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.removeAccountFromList(refreshedAccount, listId, accountId);
});
}
voteOnPoll(account: AccountInfo, pollId: string, pollSelection: number[]): Promise<Poll> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.voteOnPoll(refreshedAccount, pollId, pollSelection);
});
}
getPoll(account: AccountInfo, pollId: string): Promise<Poll> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.getPoll(refreshedAccount, pollId);
});
}
mute(account: AccountInfo, accounId: number): Promise<Relationship> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.mute(refreshedAccount, accounId);
});
}
block(account: AccountInfo, accounId: number): Promise<Relationship> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.block(refreshedAccount, accounId);
});
}
pinOnProfile(account: AccountInfo, statusId: string): Promise<Status> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.pinOnProfile(refreshedAccount, statusId);
});
}
unpinFromProfile(account: AccountInfo, statusId: string): Promise<Status> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.unpinFromProfile(refreshedAccount, statusId);
});
}
muteConversation(account: AccountInfo, statusId: string): Promise<Status> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.muteConversation(refreshedAccount, statusId);
});
}
unmuteConversation(account: AccountInfo, statusId: string): Promise<Status> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.unmuteConversation(refreshedAccount, statusId);
});
}
deleteStatus(account: AccountInfo, statusId: string): Promise<any> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.deleteStatus(refreshedAccount, statusId);
});
}
getCustomEmojis(account: AccountInfo): Promise<Emoji[]> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.getCustomEmojis(refreshedAccount);
});
}
getScheduledStatuses(account: AccountInfo): Promise<ScheduledStatus[]> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.getScheduledStatuses(refreshedAccount);
});
}
changeScheduledStatus(account: AccountInfo, statusId: string, scheduled_at: string): Promise<ScheduledStatus> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.changeScheduledStatus(refreshedAccount, statusId, scheduled_at);
});
}
deleteScheduledStatus(account: AccountInfo, statusId: string): Promise<any> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.deleteScheduledStatus(refreshedAccount, statusId);
});
}
}

View File

@ -28,7 +28,7 @@ export class MastodonService {
return this.httpClient.get<Status[]>(route, { headers: headers }).toPromise();
}
getConversations(account: AccountInfo, max_id: string = null, since_id: string = null, min_id = null, limit: number = 20,): Promise<Conversation[]> {
getConversations(account: AccountInfo, max_id: string = null, since_id: string = null, min_id = null, limit: number = 20): Promise<Conversation[]> {
let params = `?limit=${limit}`;
if (max_id) params += `&max_id=${max_id}`;
if (since_id) params += `&since_id=${since_id}`;

View File

@ -3,7 +3,7 @@ import { BehaviorSubject } from 'rxjs';
import { AccountInfo } from '../states/accounts.state';
import { Attachment } from './models/mastodon.interfaces';
import { MastodonService } from './mastodon.service';
import { MastodonWrapperService } from './mastodon-wrapper.service';
import { NotificationService } from './notification.service';
@ -15,7 +15,7 @@ export class MediaService {
constructor(
private readonly notificationService: NotificationService,
private readonly mastodonService: MastodonService) { }
private readonly mastodonService: MastodonWrapperService) { }
uploadMedia(account: AccountInfo, files: File[]) {
for (let file of files) {

View File

@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { BehaviorSubject } from 'rxjs';
import { MastodonService } from './mastodon.service';
import { MastodonWrapperService } from './mastodon-wrapper.service';
import { AccountInfo } from '../states/accounts.state';
import { ScheduledStatus } from './models/mastodon.interfaces';
import { NotificationService } from './notification.service';
@ -15,7 +15,7 @@ export class ScheduledStatusService {
constructor(
private readonly notificationService: NotificationService,
private readonly mastodonService: MastodonService,
private readonly mastodonService: MastodonWrapperService,
private readonly store: Store) {
this.fetchScheduledStatus();
@ -46,7 +46,7 @@ export class ScheduledStatusService {
}
})
.catch(err => {
this.notificationService.notifyHttpError(err, account);
//this.notificationService.notifyHttpError(err, account);
});
}

View File

@ -4,8 +4,9 @@ import { BehaviorSubject } from "rxjs";
import { Status } from "./models/mastodon.interfaces";
import { ApiRoutes } from "./models/api.settings";
import { StreamTypeEnum, StreamElement } from "../states/streams.state";
import { MastodonService } from "./mastodon.service";
import { MastodonWrapperService } from "./mastodon-wrapper.service";
import { AccountInfo } from "../states/accounts.state";
import { AccountIconComponent } from '../components/left-side-bar/account-icon/account-icon.component';
@Injectable()
export class StreamingService {
@ -13,7 +14,7 @@ export class StreamingService {
public readonly nbStatusPerIteration: number = 20;
constructor(
private readonly mastodonService: MastodonService) { }
private readonly mastodonService: MastodonWrapperService) { }
getStreaming(accountInfo: AccountInfo, stream: StreamElement): StreamingWrapper {
return new StreamingWrapper(this.mastodonService, accountInfo, stream, this.nbStatusPerIteration);
@ -29,13 +30,12 @@ export class StreamingWrapper {
private disposed: boolean;
constructor(
private readonly mastodonService: MastodonService,
private readonly mastodonService: MastodonWrapperService,
private readonly account: AccountInfo,
private readonly stream: StreamElement,
private readonly nbStatusPerIteration: number) {
const route = this.getRoute(account, stream);
this.start(route);
this.start(account, stream);
}
dispose(): any {
@ -43,34 +43,41 @@ export class StreamingWrapper {
this.eventSource.close();
}
private start(route: string) {
this.eventSource = new WebSocket(route);
this.eventSource.onmessage = x => {
if (x.data !== '') {
this.statusParsing(<WebSocketEvent>JSON.parse(x.data));
}
}
this.eventSource.onerror = x => this.webSocketGotError(x);
this.eventSource.onopen = x => { };
this.eventSource.onclose = x => this.webSocketClosed(route, x);
private start(account: AccountInfo, stream: StreamElement) {
this.mastodonService.refreshAccountIfNeeded(account)
.catch(err => {
return account;
})
.then((refreshedAccount: AccountInfo) => {
const route = this.getRoute(refreshedAccount, stream);
this.eventSource = new WebSocket(route);
this.eventSource.onmessage = x => {
if (x.data !== '') {
this.statusParsing(<WebSocketEvent>JSON.parse(x.data));
}
}
this.eventSource.onerror = x => this.webSocketGotError(x);
this.eventSource.onopen = x => { };
this.eventSource.onclose = x => this.webSocketClosed(refreshedAccount, stream, x);
});
}
private webSocketGotError(x: Event) {
this.errorClosing = true;
}
private webSocketClosed(domain, x: Event) {
private webSocketClosed(account: AccountInfo, stream: StreamElement, x: Event) {
if (this.errorClosing) {
setTimeout(() => {
this.pullNewStatuses(domain);
this.pullNewStatuses();
this.errorClosing = false;
}, 60 * 1000);
} else if (!this.disposed) {
setTimeout(() => { this.start(domain) }, 60 * 1000);
setTimeout(() => { this.start(account, stream) }, 60 * 1000);
}
}
private pullNewStatuses(domain) {
private pullNewStatuses() {
this.mastodonService.getTimeline(this.account, this.stream.type, null, this.since_id, this.nbStatusPerIteration, this.stream.tag, this.stream.listId)
.then((status: Status[]) => {
// status = status.sort((n1, n2) => { return (<number>n1.id) < (<number>n2.id); });
@ -89,7 +96,7 @@ export class StreamingWrapper {
.then(() => {
// setTimeout(() => { this.start(domain) }, 20 * 1000);
if (!this.disposed) {
setTimeout(() => { this.pullNewStatuses(domain) }, 60 * 1000);
setTimeout(() => { this.pullNewStatuses() }, 60 * 1000);
}
});
}

View File

@ -2,10 +2,11 @@ import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { AccountInfo } from '../states/accounts.state';
import { MastodonService } from './mastodon.service';
import { MastodonWrapperService } from './mastodon-wrapper.service';
import { Account, Results, Status, Emoji } from "./models/mastodon.interfaces";
import { StatusWrapper } from '../models/common.model';
import { AccountSettings, SaveAccountSettings } from '../states/settings.state';
import { AppInfo, RegisteredAppsStateModel } from '../states/registered-apps.state';
@Injectable({
providedIn: 'root'
@ -15,7 +16,7 @@ export class ToolsService {
private instanceInfos: { [id: string]: InstanceInfo } = {};
constructor(
private readonly mastodonService: MastodonService,
private readonly mastodonService: MastodonWrapperService,
private readonly store: Store) { }
getInstanceInfo(acc: AccountInfo): Promise<InstanceInfo> {

View File

@ -3,7 +3,7 @@ import { BehaviorSubject, Subject, Observable, Subscription } from 'rxjs';
import { Store } from '@ngxs/store';
import { Status, Notification } from './models/mastodon.interfaces';
import { MastodonService } from './mastodon.service';
import { MastodonWrapperService } from './mastodon-wrapper.service';
import { AccountInfo } from '../states/accounts.state';
import { NotificationService } from './notification.service';
import { ToolsService } from './tools.service';
@ -19,7 +19,7 @@ export class UserNotificationService {
constructor(
private readonly toolsService: ToolsService,
private readonly notificationService: NotificationService,
private readonly mastodonService: MastodonService,
private readonly mastodonService: MastodonWrapperService,
private readonly store: Store) {
this.fetchNotifications();

View File

@ -11,6 +11,11 @@ export class SelectAccount {
constructor(public account: AccountInfo, public multiselection: boolean = false) {}
}
export class UpdateAccount {
static readonly type = '[Accounts] Update account';
constructor(public account: AccountInfo) {}
}
export class RemoveAccount {
static readonly type = '[Accounts] Remove account';
constructor(public accountId: string) {}
@ -41,6 +46,18 @@ export class AccountsState {
});
}
@Action(UpdateAccount)
UpdateAccount(ctx: StateContext<AccountsStateModel>, action: UpdateAccount){
const state = ctx.getState();
let editedAcc = state.accounts.find(x => x.id === action.account.id);
editedAcc.token = action.account.token;
ctx.patchState({
accounts: [...state.accounts]
});
}
@Action(SelectAccount)
SelectAccount(ctx: StateContext<AccountsStateModel>, action: SelectAccount){
const state = ctx.getState();

View File

@ -48,7 +48,7 @@ $button-border-color: #303957;
$column-background: #0f111a;
$card-border-color: #1e2435;
$card-border-color: #2b344d;
$context-menu-background: #d9e1e8;
$context-menu-background-hover: #a9c9e6;