Merge pull request #358 from NicolasConstant/topic_birdsitelive-support

Topic birdsitelive support
This commit is contained in:
Nicolas Constant 2021-03-07 00:59:33 +01:00 committed by GitHub
commit 8d13822000
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 259 additions and 116 deletions

View File

@ -24,6 +24,7 @@ import { PollEditorComponent } from './poll-editor/poll-editor.component';
import { StatusSchedulerComponent } from './status-scheduler/status-scheduler.component';
import { ScheduledStatusService } from '../../services/scheduled-status.service';
import { StatusesStateService } from '../../services/statuses-state.service';
import { SettingsService } from '../../services/settings.service';
@Component({
selector: 'app-create-status',
@ -186,6 +187,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
private selectedAccount: AccountInfo;
constructor(
private readonly settingsService: SettingsService,
private statusStateService: StatusesStateService,
private readonly scheduledStatusService: ScheduledStatusService,
private readonly contextMenuService: ContextMenuService,
@ -370,7 +372,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
if (accounts && accounts.length > 0) {
this.selectedAccount = accounts.filter(x => x.isSelected)[0];
const settings = this.toolsService.getAccountSettings(this.selectedAccount);
const settings = this.settingsService.getAccountSettings(this.selectedAccount);
if (settings.customStatusCharLengthEnabled) {
this.maxCharLength = settings.customStatusCharLength;
this.countStatusChar(this.status);

View File

@ -16,6 +16,7 @@ import { MentionsComponent } from './mentions/mentions.component';
import { DirectMessagesComponent } from './direct-messages/direct-messages.component';
import { FavoritesComponent } from './favorites/favorites.component';
import { BrowseBase } from '../../common/browse-base';
import { SettingsService } from '../../../services/settings.service';
@Component({
@ -54,6 +55,7 @@ export class ManageAccountComponent extends BrowseBase {
private _account: AccountWrapper;
constructor(
private readonly settingsService: SettingsService,
private readonly toolsService: ToolsService,
private readonly mastodonService: MastodonWrapperService,
private readonly notificationService: NotificationService,
@ -100,8 +102,8 @@ export class ManageAccountComponent extends BrowseBase {
this.userNotificationServiceSub = this.userNotificationService.userNotifications.subscribe((userNotifications: UserNotification[]) => {
const userNotification = userNotifications.find(x => x.account.id === this.account.info.id);
if (userNotification) {
let settings = this.toolsService.getSettings();
let accSettings = this.toolsService.getAccountSettings(this.account.info);
let settings = this.settingsService.getSettings();
let accSettings = this.settingsService.getAccountSettings(this.account.info);
if (!settings.disableAvatarNotifications && !accSettings.disableAvatarNotifications) {
this.hasNotifications = userNotification.hasNewNotifications;
@ -113,8 +115,8 @@ export class ManageAccountComponent extends BrowseBase {
let current = this.userNotificationService.userNotifications.value;
const userNotification = current.find(x => x.account.id === this.account.info.id);
if (userNotification) {
let settings = this.toolsService.getSettings();
let accSettings = this.toolsService.getAccountSettings(this.account.info);
let settings = this.settingsService.getSettings();
let accSettings = this.settingsService.getAccountSettings(this.account.info);
if (!settings.disableAutofocus && !settings.disableAvatarNotifications && !accSettings.disableAvatarNotifications) {
if (userNotification.hasNewNotifications) {

View File

@ -6,7 +6,7 @@ import { MastodonWrapperService } from '../../../../../services/mastodon-wrapper
import { AccountWrapper } from '../../../../../models/account.models';
import { NotificationService } from '../../../../../services/notification.service';
import { Account, Relationship, Instance } from "../../../../../services/models/mastodon.interfaces";
import { of } from 'rxjs';
import { SettingsService } from '../../../../../services/settings.service';
@Component({
selector: 'app-list-editor',
@ -25,6 +25,7 @@ export class ListEditorComponent implements OnInit {
searchOpen: boolean;
constructor(
private readonly settingsService: SettingsService,
private readonly notificationService: NotificationService,
private readonly mastodonService: MastodonWrapperService) { }
@ -69,13 +70,12 @@ export class ListEditorComponent implements OnInit {
}
addEvent(accountWrapper: AccountListWrapper) {
console.log(accountWrapper);
const settings = this.settingsService.getSettings();
accountWrapper.isLoading = true;
this.mastodonService.getInstance(this.account.info.instance)
.then((instance: Instance) => {
console.log(instance);
if (instance.version.toLowerCase().includes('pleroma')) {
if (instance.version.toLowerCase().includes('pleroma') && !settings.autoFollowOnListEnabled) {
return Promise.resolve(true);
} else {
return this.followAccount(accountWrapper);

View File

@ -10,8 +10,8 @@ import { AccountWrapper } from '../../../../models/account.models';
import { RemoveAccount } from '../../../../states/accounts.state';
import { NavigationService } from '../../../../services/navigation.service';
import { MastodonWrapperService } from '../../../../services/mastodon-wrapper.service';
import { ToolsService } from '../../../../services/tools.service';
import { AccountSettings } from '../../../../states/settings.state';
import { SettingsService } from '../../../../services/settings.service';
@Component({
selector: 'app-my-account',
@ -49,8 +49,8 @@ export class MyAccountComponent implements OnInit, OnDestroy {
private streamChangedSub: Subscription;
constructor(
private readonly settingsService: SettingsService,
private readonly store: Store,
private readonly toolsService: ToolsService,
private readonly navigationService: NavigationService,
private readonly mastodonService: MastodonWrapperService,
private readonly notificationService: NotificationService) { }
@ -68,7 +68,7 @@ export class MyAccountComponent implements OnInit, OnDestroy {
}
private loadAccountSettings(){
this.accountSettings = this.toolsService.getAccountSettings(this.account.info);
this.accountSettings = this.settingsService.getAccountSettings(this.account.info);
this.customStatusLengthEnabled = this.accountSettings.customStatusCharLengthEnabled;
this.customStatusLength = this.accountSettings.customStatusCharLength;
@ -77,13 +77,13 @@ export class MyAccountComponent implements OnInit, OnDestroy {
onCustomLengthEnabledChanged(): boolean {
this.accountSettings.customStatusCharLengthEnabled = this.customStatusLengthEnabled;
this.toolsService.saveAccountSettings(this.accountSettings);
this.settingsService.saveAccountSettings(this.accountSettings);
return false;
}
customStatusLengthChanged(event): boolean{
this.accountSettings.customStatusCharLength = this.customStatusLength;
this.toolsService.saveAccountSettings(this.accountSettings);
this.settingsService.saveAccountSettings(this.accountSettings);
return false;
}
@ -203,9 +203,9 @@ export class MyAccountComponent implements OnInit, OnDestroy {
}
onDisableAvatarNotificationChanged() {
let settings = this.toolsService.getAccountSettings(this.account.info);
let settings = this.settingsService.getAccountSettings(this.account.info);
settings.disableAvatarNotifications = this.avatarNotificationDisabled;
this.toolsService.saveAccountSettings(settings);
this.settingsService.saveAccountSettings(settings);
}
}

View File

@ -35,6 +35,7 @@
</form>
<a href class="form-button sound__play" type="submit" (click)="playNotificationSound()">play</a>
</div>
<h4 class="panel__subtitle">Shortcuts</h4>
<div class="sub-section">
<span class="sub-section__title">switch column:</span><br />
@ -50,6 +51,21 @@
<br>
</div>
<h4 class="panel__subtitle">Twitter Bridge</h4>
<div class="sub-section">
<input class="sub-section__checkbox" [(ngModel)]="twitterBridgeEnabled"
(change)="onTwitterBridgeEnabledChanged()" type="checkbox" name="onTwitterBridgeEnabled"
value="onTwitterBridgeEnabled" id="onTwitterBridgeEnabled">
<label class="noselect sub-section__label" for="onTwitterBridgeEnabled">enable bridge</label>
<br>
<div *ngIf="twitterBridgeEnabled">
<p>Please provide your bridge instance:
<input type="text" class="form-control form-control-sm sub_section__text-input"
[(ngModel)]="setTwitterBridgeInstance" placeholder="bridge.tld" />
If you don't know any, consider using <a href="https://github.com/NicolasConstant/BirdsiteLive" target="_blank" class="version__link">BirdsiteLIVE</a></p>
</div>
</div>
<h4 class="panel__subtitle">Content-Warning Policies</h4>
<div class="sub-section">
<span class="sub-section__title">global behavior:</span><br />
@ -135,6 +151,17 @@
<br>
</div>
<div *ngIf="hasPleromaAccount">
<h4 class="panel__subtitle">Pleroma</h4>
<div class="sub-section">
<input class="sub-section__checkbox" [(ngModel)]="autoFollowOnListEnabled"
(change)="onAutoFollowOnListChanged()" type="checkbox" name="onAutoFollowOnListChanged"
value="onAutoFollowOnListChanged" id="onAutoFollowOnListChanged">
<label class="noselect sub-section__label" for="onAutoFollowOnListChanged">autofollow accounts when adding to list</label>
<br>
</div>
</div>
<h4 class="panel__subtitle">Other</h4>
<div class="sub-section">
<input class="sub-section__checkbox" [(ngModel)]="disableRemoteStatusFetchingEnabled"
@ -148,9 +175,9 @@
<h4 class="panel__subtitle">About</h4>
<p class="version">
Sengi version: {{version}}<br />
<a href class="version__link" (click)="openTutorial()">open tutorial</a><br/>
<a href="assets/docs/privacy.html" class="version__link" target="_blank">imprint & privacy</a><br/>
<a href class="version__link" (click)="checkForUpdates()">check for updates</a>
<a href class="version__link" (click)="openTutorial()">open tutorial</a><br />
<a href="assets/docs/privacy.html" class="version__link" target="_blank">imprint & privacy</a><br />
<a href class="version__link" (click)="checkForUpdates()">check for updates</a>
<app-waiting-animation *ngIf="isCheckingUpdates" class="waiting-icon"></app-waiting-animation>
</p>

View File

@ -3,12 +3,13 @@ import { FormBuilder, FormGroup } from '@angular/forms';
import { Howl } from 'howler';
import { environment } from '../../../../environments/environment';
import { ToolsService } from '../../../services/tools.service';
import { ToolsService, InstanceType } from '../../../services/tools.service';
import { UserNotificationService, NotificationSoundDefinition } from '../../../services/user-notification.service';
import { ServiceWorkerService } from '../../../services/service-worker.service';
import { ContentWarningPolicy, ContentWarningPolicyEnum, TimeLineModeEnum, TimeLineHeaderEnum } from '../../../states/settings.state';
import { NotificationService } from '../../../services/notification.service';
import { NavigationService } from '../../../services/navigation.service';
import { SettingsService } from '../../../services/settings.service';
@Component({
selector: 'app-settings',
@ -28,6 +29,11 @@ export class SettingsComponent implements OnInit {
disableSoundsEnabled: boolean;
version: string;
hasPleromaAccount: boolean;
autoFollowOnListEnabled: boolean;
twitterBridgeEnabled: boolean;
columnShortcutEnabled: ColumnShortcut = ColumnShortcut.Ctrl;
timeLineHeader: TimeLineHeaderEnum = TimeLineHeaderEnum.Title_DomainName;
timeLineMode: TimeLineModeEnum = TimeLineModeEnum.OnTop;
@ -60,7 +66,18 @@ export class SettingsComponent implements OnInit {
return this.contentHidedCompletely;
}
private twitterBridgeInstance: string;
set setTwitterBridgeInstance(value: string) {
let instance = value.replace('https://', '').replace('http://', '').replace('/', '').trim();
this.setBridgeInstance(instance);
this.twitterBridgeInstance = instance;
}
get setTwitterBridgeInstance(): string {
return this.twitterBridgeInstance;
}
constructor(
private readonly settingsService: SettingsService,
private readonly navigationService: NavigationService,
private formBuilder: FormBuilder,
private serviceWorkersService: ServiceWorkerService,
@ -71,7 +88,7 @@ export class SettingsComponent implements OnInit {
ngOnInit() {
this.version = environment.VERSION;
const settings = this.toolsService.getSettings();
const settings = this.settingsService.getSettings();
this.notificationSounds = this.userNotificationsService.getAllNotificationSounds();
this.notificationSoundId = settings.notificationSoundFileId;
@ -97,33 +114,48 @@ export class SettingsComponent implements OnInit {
this.timeLineHeader = settings.timelineHeader;
this.timeLineMode = settings.timelineMode;
this.autoFollowOnListEnabled = settings.autoFollowOnListEnabled;
const accs = this.toolsService.getAllAccounts();
accs.forEach(a => {
this.toolsService.getInstanceInfo(a)
.then(ins => {
if(ins.type === InstanceType.Pleroma){
this.hasPleromaAccount = true;
}
})
.catch(err => console.error(err));
});
this.twitterBridgeEnabled = settings.twitterBridgeEnabled;
this.twitterBridgeInstance = settings.twitterBridgeInstance;
}
onShortcutChange(id: ColumnShortcut) {
this.columnShortcutEnabled = id;
this.notifyRestartNeeded();
let settings = this.toolsService.getSettings();
let settings = this.settingsService.getSettings();
settings.columnSwitchingWinAlt = id === ColumnShortcut.Win;
this.toolsService.saveSettings(settings);
this.settingsService.saveSettings(settings);
}
onTimeLineHeaderChange(id: TimeLineHeaderEnum){
this.timeLineHeader = id;
this.notifyRestartNeeded();
let settings = this.toolsService.getSettings();
let settings = this.settingsService.getSettings();
settings.timelineHeader = id;
this.toolsService.saveSettings(settings);
this.settingsService.saveSettings(settings);
}
onTimeLineModeChange(id: TimeLineModeEnum){
this.timeLineMode = id;
this.notifyRestartNeeded();
let settings = this.toolsService.getSettings();
let settings = this.settingsService.getSettings();
settings.timelineMode = id;
this.toolsService.saveSettings(settings);
this.settingsService.saveSettings(settings);
}
onCwPolicyChange(id: ContentWarningPolicyEnum) {
@ -135,7 +167,7 @@ export class SettingsComponent implements OnInit {
private setCwPolicy(id: ContentWarningPolicyEnum = null, addCw: string = null, removeCw: string = null, hide: string = null){
this.notifyRestartNeeded();
let settings = this.toolsService.getSettings();
let settings = this.settingsService.getSettings();
let cwPolicySettings = new ContentWarningPolicy();
if(id !== null){
@ -162,13 +194,19 @@ export class SettingsComponent implements OnInit {
cwPolicySettings.hideCompletlyContent = settings.contentWarningPolicy.hideCompletlyContent;
}
this.toolsService.saveContentWarningPolicy(cwPolicySettings);
}
this.settingsService.saveContentWarningPolicy(cwPolicySettings);
}
private splitCwValues(data: string): string[]{
return data.split(';').map(x => x.trim().toLowerCase()).filter((value, index, self) => self.indexOf(value) === index).filter(y => y !== '');
}
private setBridgeInstance(instance: string){
let settings = this.settingsService.getSettings();
settings.twitterBridgeInstance = instance;
this.settingsService.saveSettings(settings);
}
// reload(): boolean {
// window.location.reload();
// return false;
@ -176,9 +214,9 @@ export class SettingsComponent implements OnInit {
onChange(soundId: string) {
this.notificationSoundId = soundId;
let settings = this.toolsService.getSettings()
let settings = this.settingsService.getSettings()
settings.notificationSoundFileId = soundId;
this.toolsService.saveSettings(settings);
this.settingsService.saveSettings(settings);
}
playNotificationSound(): boolean {
@ -194,29 +232,41 @@ export class SettingsComponent implements OnInit {
onDisableAutofocusChanged() {
this.notifyRestartNeeded();
let settings = this.toolsService.getSettings();
let settings = this.settingsService.getSettings();
settings.disableAutofocus = this.disableAutofocusEnabled;
this.toolsService.saveSettings(settings);
this.settingsService.saveSettings(settings);
}
onDisableRemoteStatusFetchingChanged() {
this.notifyRestartNeeded();
let settings = this.toolsService.getSettings();
let settings = this.settingsService.getSettings();
settings.disableRemoteStatusFetching = this.disableRemoteStatusFetchingEnabled;
this.toolsService.saveSettings(settings);
this.settingsService.saveSettings(settings);
}
onDisableAvatarNotificationsChanged() {
this.notifyRestartNeeded();
let settings = this.toolsService.getSettings();
let settings = this.settingsService.getSettings();
settings.disableAvatarNotifications = this.disableAvatarNotificationsEnabled;
this.toolsService.saveSettings(settings);
this.settingsService.saveSettings(settings);
}
onDisableSoundsEnabledChanged() {
let settings = this.toolsService.getSettings();
let settings = this.settingsService.getSettings();
settings.disableSounds = this.disableSoundsEnabled;
this.toolsService.saveSettings(settings);
this.settingsService.saveSettings(settings);
}
onAutoFollowOnListChanged(){
let settings = this.settingsService.getSettings();
settings.autoFollowOnListEnabled = this.autoFollowOnListEnabled;
this.settingsService.saveSettings(settings);
}
onTwitterBridgeEnabledChanged(){
let settings = this.settingsService.getSettings();
settings.twitterBridgeEnabled = this.twitterBridgeEnabled;
this.settingsService.saveSettings(settings);
}
isCleanningAll: boolean = false;

View File

@ -11,6 +11,7 @@ import { NavigationService, LeftPanelType } from "../../services/navigation.serv
import { UserNotificationService, UserNotification } from '../../services/user-notification.service';
import { ToolsService } from '../../services/tools.service';
import { ScheduledStatusService, ScheduledStatusNotification } from '../../services/scheduled-status.service';
import { SettingsService } from '../../services/settings.service';
@Component({
selector: "app-left-side-bar",
@ -34,6 +35,7 @@ export class LeftSideBarComponent implements OnInit, OnDestroy {
private notificationSub: Subscription;
constructor(
private readonly settingsService: SettingsService,
private readonly hotkeysService: HotkeysService,
private readonly scheduledStatusService: ScheduledStatusService,
private readonly toolsService: ToolsService,
@ -133,7 +135,7 @@ export class LeftSideBarComponent implements OnInit, OnDestroy {
});
this.notificationSub = this.userNotificationServiceService.userNotifications.subscribe((notifications: UserNotification[]) => {
const settings = this.toolsService.getSettings();
const settings = this.settingsService.getSettings();
notifications.forEach((notification: UserNotification) => {
const acc = this.accounts.find(x => x.info.id === notification.account.id);

View File

@ -13,6 +13,7 @@ import { ToolsService } from '../../../services/tools.service';
import { StatusWrapper } from '../../../models/common.model';
import { TimeLineModeEnum } from '../../../states/settings.state';
import { TimelineBase } from '../../common/timeline-base';
import { SettingsService } from '../../../services/settings.service';
@Component({
selector: 'app-stream-statuses',
@ -43,6 +44,7 @@ export class StreamStatusesComponent extends TimelineBase {
private streams$: Observable<StreamElement[]>;
constructor(
protected readonly settingsService: SettingsService,
protected readonly store: Store,
protected readonly toolsService: ToolsService,
protected readonly notificationService: NotificationService,
@ -54,7 +56,7 @@ export class StreamStatusesComponent extends TimelineBase {
}
ngOnInit() {
let settings = this.toolsService.getSettings();
let settings = this.settingsService.getSettings();
this.timelineLoadingMode = settings.timelineMode;
this.goToTopSubscription = this.goToTop.subscribe(() => {

View File

@ -8,6 +8,7 @@ import { StreamStatusesComponent } from './stream-statuses/stream-statuses.compo
import { StreamNotificationsComponent } from './stream-notifications/stream-notifications.component';
import { TimeLineHeaderEnum } from '../../states/settings.state';
import { AccountInfo } from '../../states/accounts.state';
import { SettingsService } from '../../services/settings.service';
@Component({
selector: "app-stream",
@ -72,10 +73,12 @@ export class StreamComponent implements OnInit {
return this._streamElement;
}
constructor(private toolsService: ToolsService) { }
constructor(
private readonly settingsService: SettingsService,
private readonly toolsService: ToolsService) { }
ngOnInit() {
let settings = this.toolsService.getSettings();
let settings = this.settingsService.getSettings();
this.timelineHeader = settings.timelineHeader;
}

View File

@ -13,6 +13,7 @@ import scrollIntoView from 'scroll-into-view-if-needed';
import { UserNotificationService, UserNotification } from '../../../services/user-notification.service';
import { TimeLineModeEnum } from '../../../states/settings.state';
import { BrowseBase } from '../../common/browse-base';
import { SettingsService } from '../../../services/settings.service';
@Component({
selector: 'app-thread',
@ -54,6 +55,7 @@ export class ThreadComponent extends BrowseBase {
private responseSubscription: Subscription;
constructor(
private readonly settingsService: SettingsService,
private readonly httpClient: HttpClient,
private readonly notificationService: NotificationService,
private readonly userNotificationService: UserNotificationService,
@ -63,7 +65,7 @@ export class ThreadComponent extends BrowseBase {
}
ngOnInit() {
let settings = this.toolsService.getSettings();
let settings = this.settingsService.getSettings();
this.remoteStatusFetchingDisabled = settings.disableRemoteStatusFetching;
if (this.refreshEventEmitter) {

View File

@ -5,7 +5,7 @@ import { HotkeysService, Hotkey } from 'angular2-hotkeys';
import { StreamElement, StreamTypeEnum } from '../../states/streams.state';
import { NavigationService } from '../../services/navigation.service';
import { ToolsService } from '../../services/tools.service';
import { SettingsService } from '../../services/settings.service';
@Component({
selector: 'app-streams-selection-footer',
@ -17,14 +17,14 @@ export class StreamsSelectionFooterComponent implements OnInit {
private streams$: Observable<StreamElement[]>;
constructor(
private readonly toolsService: ToolsService,
private readonly settingsService: SettingsService,
private readonly hotkeysService: HotkeysService,
private readonly navigationService: NavigationService,
private readonly store: Store) {
this.streams$ = this.store.select(state => state.streamsstatemodel.streams);
const settings = this.toolsService.getSettings();
const settings = this.settingsService.getSettings();
if(!settings.columnSwitchingWinAlt) {
this.hotkeysService.add(new Hotkey('ctrl+right', (event: KeyboardEvent): boolean => {
this.nextColumnSelected();

View File

@ -7,6 +7,7 @@ import { StreamTypeEnum, StreamElement } from '../states/streams.state';
import { FavoriteResult, VisibilityEnum, PollParameters, MastodonService, BookmarkResult, FollowingResult } from './mastodon.service';
import { AuthService } from './auth.service';
import { AppInfo, RegisteredAppsStateModel } from '../states/registered-apps.state';
import { SettingsService } from './settings.service';
@Injectable({
providedIn: 'root'
@ -15,6 +16,7 @@ export class MastodonWrapperService {
private refreshingToken: { [id: string]: Promise<AccountInfo> } = {};
constructor(
private readonly settingsService: SettingsService,
private readonly store: Store,
private readonly authService: AuthService,
private readonly mastodonService: MastodonService) { }
@ -130,12 +132,35 @@ export class MastodonWrapperService {
}
search(account: AccountInfo, query: string, version: 'v1' | 'v2', resolve: boolean = false): Promise<Results> {
if(query.includes('twitter.com')){
query = this.processTwitterQuery(query);
}
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.search(refreshedAccount, query, version, resolve);
});
}
private processTwitterQuery(query: string): string {
const settings = this.settingsService.getSettings();
if(!settings.twitterBridgeInstance) return query;
let name;
if(query.includes('twitter.com/')){
console.log(query.replace('https://', '').replace('http://', '').split('/'));
name = query.replace('https://', '').replace('http://', '').split('/')[1];
}
if(query.includes('@twitter.com')){
console.log(query.split('@'));
name = query.split('@')[0];
if(name === '' || name == null){
name = query.split('@')[1];
}
}
return `@${name}@${settings.twitterBridgeInstance}`;
}
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) => {
@ -169,6 +194,10 @@ export class MastodonWrapperService {
}
searchAccount(account: AccountInfo, query: string, limit: number = 40, following: boolean = false, resolve = true): Promise<Account[]> {
if(query.includes('twitter.com')){
query = this.processTwitterQuery(query);
}
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.searchAccount(refreshedAccount, query, limit, following, resolve);

View File

@ -0,0 +1,71 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { AccountInfo } from '../states/accounts.state';
import { MastodonWrapperService } from './mastodon-wrapper.service';
import { Account, Results, Status, Emoji } from "./models/mastodon.interfaces";
import { StatusWrapper } from '../models/common.model';
import { AccountSettings, SaveAccountSettings, GlobalSettings, SaveSettings, ContentWarningPolicy, SaveContentWarningPolicy, ContentWarningPolicyEnum, TimeLineModeEnum, TimeLineHeaderEnum } from '../states/settings.state';
@Injectable({
providedIn: 'root'
})
export class SettingsService {
constructor(
private readonly store: Store) { }
getSettings(): GlobalSettings {
let settings = <GlobalSettings>this.store.snapshot().globalsettings.settings;
if (!settings.contentWarningPolicy) {
var newCwPolicy = new ContentWarningPolicy();
this.saveContentWarningPolicy(newCwPolicy);
return <GlobalSettings>this.store.snapshot().globalsettings.settings;
}
if(!settings.timelineMode){
settings.timelineMode = TimeLineModeEnum.OnTop;
this.saveSettings(settings);
}
if(!settings.timelineHeader){
settings.timelineHeader = TimeLineHeaderEnum.Title_DomainName;
this.saveSettings(settings);
}
return settings;
}
saveSettings(settings: GlobalSettings) {
this.store.dispatch([
new SaveSettings(settings)
]);
}
saveContentWarningPolicy(cwSettings: ContentWarningPolicy) {
this.store.dispatch([
new SaveContentWarningPolicy(cwSettings)
]);
}
getAccountSettings(account: AccountInfo): AccountSettings {
let accountsSettings = <AccountSettings[]>this.store.snapshot().globalsettings.settings.accountSettings;
let accountSettings = accountsSettings.find(x => x.accountId === account.id);
if (!accountSettings) {
accountSettings = new AccountSettings();
accountSettings.accountId = account.id;
this.saveAccountSettings(accountSettings);
}
if (!accountSettings.customStatusCharLength) {
accountSettings.customStatusCharLength = 500;
this.saveAccountSettings(accountSettings);
}
return accountSettings;
}
saveAccountSettings(accountSettings: AccountSettings) {
this.store.dispatch([
new SaveAccountSettings(accountSettings)
]);
}
}

View File

@ -6,6 +6,7 @@ import { MastodonWrapperService } from './mastodon-wrapper.service';
import { Account, Results, Status, Emoji } from "./models/mastodon.interfaces";
import { StatusWrapper } from '../models/common.model';
import { AccountSettings, SaveAccountSettings, GlobalSettings, SaveSettings, ContentWarningPolicy, SaveContentWarningPolicy, ContentWarningPolicyEnum, TimeLineModeEnum, TimeLineHeaderEnum } from '../states/settings.state';
import { SettingsService } from './settings.service';
@Injectable({
providedIn: 'root'
@ -15,6 +16,7 @@ export class ToolsService {
private instanceInfos: { [id: string]: InstanceInfo } = {};
constructor(
private readonly settingsService: SettingsService,
private readonly mastodonService: MastodonWrapperService,
private readonly store: Store) { }
@ -26,7 +28,7 @@ export class ToolsService {
let applyCw = false;
let hideStatus = false;
let cwPolicy = this.getSettings().contentWarningPolicy;
let cwPolicy = this.settingsService.getSettings().contentWarningPolicy;
let splittedContent = [];
if ((cwPolicy.policy === ContentWarningPolicyEnum.HideAll && cwPolicy.addCwOnContent.length > 0)
@ -129,61 +131,6 @@ export class ToolsService {
return regAccounts.find(x => x.id === accountId);
}
getAccountSettings(account: AccountInfo): AccountSettings {
let accountsSettings = <AccountSettings[]>this.store.snapshot().globalsettings.settings.accountSettings;
let accountSettings = accountsSettings.find(x => x.accountId === account.id);
if (!accountSettings) {
accountSettings = new AccountSettings();
accountSettings.accountId = account.id;
this.saveAccountSettings(accountSettings);
}
if (!accountSettings.customStatusCharLength) {
accountSettings.customStatusCharLength = 500;
this.saveAccountSettings(accountSettings);
}
return accountSettings;
}
saveAccountSettings(accountSettings: AccountSettings) {
this.store.dispatch([
new SaveAccountSettings(accountSettings)
]);
}
getSettings(): GlobalSettings {
let settings = <GlobalSettings>this.store.snapshot().globalsettings.settings;
if (!settings.contentWarningPolicy) {
var newCwPolicy = new ContentWarningPolicy();
this.saveContentWarningPolicy(newCwPolicy);
return <GlobalSettings>this.store.snapshot().globalsettings.settings;
}
if(!settings.timelineMode){
settings.timelineMode = TimeLineModeEnum.OnTop;
this.saveSettings(settings);
}
if(!settings.timelineHeader){
settings.timelineHeader = TimeLineHeaderEnum.Title_DomainName;
this.saveSettings(settings);
}
return settings;
}
saveSettings(settings: GlobalSettings) {
this.store.dispatch([
new SaveSettings(settings)
]);
}
saveContentWarningPolicy(cwSettings: ContentWarningPolicy) {
this.store.dispatch([
new SaveContentWarningPolicy(cwSettings)
]);
}
findAccount(account: AccountInfo, accountName: string): Promise<Account> {
let findAccountFunc = (result: Results) => {
if (accountName[0] === '@') accountName = accountName.substr(1);

View File

@ -7,9 +7,9 @@ import { Status, Notification } from './models/mastodon.interfaces';
import { MastodonWrapperService } from './mastodon-wrapper.service';
import { AccountInfo } from '../states/accounts.state';
import { NotificationService } from './notification.service';
import { ToolsService } from './tools.service';
import { StreamingService, StatusUpdate, EventEnum } from './streaming.service';
import { StreamElement, StreamTypeEnum } from '../states/streams.state';
import { SettingsService } from './settings.service';
@Injectable({
@ -29,8 +29,8 @@ export class UserNotificationService {
private loadedAccounts: AccountInfo[] = [];
constructor(
private readonly settingsService: SettingsService,
private readonly streamingService: StreamingService,
private readonly toolsService: ToolsService,
private readonly notificationService: NotificationService,
private readonly mastodonService: MastodonWrapperService,
private readonly store: Store) {
@ -89,7 +89,7 @@ export class UserNotificationService {
}
private playSoundNotification() {
const settings = this.toolsService.getSettings();
const settings = this.settingsService.getSettings();
if (settings.disableSounds) return;
if (this.soundJustPlayed) return;
this.soundJustPlayed = true;
@ -103,13 +103,13 @@ export class UserNotificationService {
}
private setNotificationSound() {
let settings = this.toolsService.getSettings();
let settings = this.settingsService.getSettings();
let soundId = settings.notificationSoundFileId;
if (!soundId) {
soundId = '0';
settings.notificationSoundFileId = '0';
this.toolsService.saveSettings(settings);
this.settingsService.saveSettings(settings);
}
if (this.soundFileId === soundId) return;
@ -174,7 +174,7 @@ export class UserNotificationService {
let lastNotificationId = newNotifications[newNotifications.length - 1].id;
const accountSettings = this.toolsService.getAccountSettings(account);
const accountSettings = this.settingsService.getAccountSettings(account);
if (type === NotificationTypeEnum.UserMention) {
userNotification.lastMentionsId = lastNotificationId;
@ -190,12 +190,12 @@ export class UserNotificationService {
// Set settings if needed
if (type === NotificationTypeEnum.UserMention && !accountSettings.lastMentionCreationDate && newNotifications.length > 0) {
accountSettings.lastMentionCreationDate = newNotifications[0].created_at;
this.toolsService.saveAccountSettings(accountSettings);
this.settingsService.saveAccountSettings(accountSettings);
}
if (type === NotificationTypeEnum.UserNotification && !accountSettings.lastNotificationCreationDate && newNotifications.length > 0) {
accountSettings.lastNotificationCreationDate = newNotifications[0].created_at;
this.toolsService.saveAccountSettings(accountSettings);
this.settingsService.saveAccountSettings(accountSettings);
}
return userNotification;
@ -208,10 +208,10 @@ export class UserNotificationService {
const lastMention = currentAccountNotifications.mentions[0];
if (lastMention) {
const settings = this.toolsService.getAccountSettings(account);
const settings = this.settingsService.getAccountSettings(account);
// const lastMentionNotification = currentAccountNotifications.mentions[0];
settings.lastMentionCreationDate = lastMention.created_at;
this.toolsService.saveAccountSettings(settings);
this.settingsService.saveAccountSettings(settings);
}
if (currentAccountNotifications.hasNewMentions === true) {
@ -226,9 +226,9 @@ export class UserNotificationService {
const lastNotification = currentAccountNotifications.notifications[0];
if (lastNotification) {
const settings = this.toolsService.getAccountSettings(account);
const settings = this.settingsService.getAccountSettings(account);
settings.lastNotificationCreationDate = lastNotification.created_at;
this.toolsService.saveAccountSettings(settings);
this.settingsService.saveAccountSettings(settings);
}
if (currentAccountNotifications.hasNewNotifications === true) {

View File

@ -66,8 +66,11 @@ export class GlobalSettings {
disableAvatarNotifications = false;
disableSounds = false;
disableRemoteStatusFetching = false;
autoFollowOnListEnabled = false;
twitterBridgeEnabled = false;
notificationSoundFileId: string = '0';
twitterBridgeInstance: string = '';
timelineHeader: TimeLineHeaderEnum = TimeLineHeaderEnum.Title_DomainName;
timelineMode: TimeLineModeEnum = TimeLineModeEnum.OnTop;
@ -164,6 +167,9 @@ export class SettingsState {
newSettings.disableRemoteStatusFetching = oldSettings.disableRemoteStatusFetching;
newSettings.timelineHeader = oldSettings.timelineHeader;
newSettings.timelineMode = oldSettings.timelineMode;
newSettings.autoFollowOnListEnabled = oldSettings.autoFollowOnListEnabled;
newSettings.twitterBridgeEnabled = oldSettings.twitterBridgeEnabled;
newSettings.twitterBridgeInstance = oldSettings.twitterBridgeInstance;
return newSettings;
}