Skip to content

Commit

Permalink
Merge pull request #134 from NicolasConstant/develop
Browse files Browse the repository at this point in the history
0.12.0
  • Loading branch information
NicolasConstant authored Jul 10, 2019
2 parents e840d5f + 5936ef2 commit f8e99ce
Show file tree
Hide file tree
Showing 43 changed files with 1,096 additions and 260 deletions.
22 changes: 20 additions & 2 deletions main-electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ function createWindow() {
});

var server = http.createServer(requestHandler).listen(9527);
win.loadURL("http://localhost:9527");
const sengiUrl = "http://localhost:9527";
win.loadURL(sengiUrl);

const template = [
{
label: "View",
submenu: [
{
label: "Return on Sengi",
click() {
win.loadURL(sengiUrl);
}
},
{ type: "separator" },
{ role: "reload" },
{ role: "forcereload" },
{ type: "separator" },
Expand Down Expand Up @@ -75,7 +83,17 @@ function createWindow() {
},
{
label: "View",
submenu: [{ role: "reload" }, { role: "forcereload" }]
submenu: [
{
label: "Return on Sengi",
click() {
win.loadURL(sengiUrl);
}
},
{ type: "separator" },
{ role: "reload" },
{ role: "forcereload" }
]
},
{
role: "help",
Expand Down
27 changes: 26 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sengi",
"version": "0.11.0",
"version": "0.12.0",
"license": "AGPL-3.0-or-later",
"main": "main-electron.js",
"description": "A multi-account desktop client for Mastodon and Pleroma",
Expand All @@ -23,11 +23,12 @@
"e2e": "ng e2e",
"electron": "ng build --prod && electron .",
"electron-debug": "ng build && electron .",
"dist": "npm run build && build --publish onTagOrDraft"
"dist": "npm run build && electron-builder --publish onTagOrDraft"
},
"private": true,
"dependencies": {
"@angular/animations": "^7.2.7",
"@angular/cdk": "^7.2.7",
"@angular/common": "^7.2.7",
"@angular/compiler": "^7.2.7",
"@angular/core": "^7.2.7",
Expand All @@ -46,6 +47,7 @@
"bootstrap": "^4.1.3",
"core-js": "^2.5.4",
"emojione": "~4.5.0",
"ngx-contextmenu": "^5.2.0",
"rxjs": "^6.4.0",
"tslib": "^1.9.0",
"zone.js": "^0.8.29"
Expand Down
6 changes: 3 additions & 3 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { debounceTime, map } from 'rxjs/operators';
import { Select } from '@ngxs/store';
// import { ElectronService } from 'ngx-electron';

import { NavigationService, LeftPanelType } from './services/navigation.service';
import { NavigationService, LeftPanelType, OpenLeftPanelEvent } from './services/navigation.service';
import { StreamElement } from './states/streams.state';
import { OpenMediaEvent } from './models/common.model';
import { ToolsService } from './services/tools.service';
Expand Down Expand Up @@ -44,8 +44,8 @@ export class AppComponent implements OnInit, OnDestroy {
}
});

this.columnEditorSub = this.navigationService.activatedPanelSubject.subscribe((type: LeftPanelType) => {
if (type === LeftPanelType.Closed) {
this.columnEditorSub = this.navigationService.activatedPanelSubject.subscribe((event: OpenLeftPanelEvent) => {
if (event.type === LeftPanelType.Closed) {
this.floatingColumnActive = false;
} else {
this.floatingColumnActive = true;
Expand Down
4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { NgxsModule } from '@ngxs/store';
import { NgxsStoragePluginModule } from '@ngxs/storage-plugin';

import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import { ContextMenuModule } from 'ngx-contextmenu';

import { AppComponent } from "./app.component";
import { LeftSideBarComponent } from "./components/left-side-bar/left-side-bar.component";
Expand Down Expand Up @@ -128,7 +129,8 @@ const routes: Routes = [
StreamsState,
SettingsState
]),
NgxsStoragePluginModule.forRoot()
NgxsStoragePluginModule.forRoot(),
ContextMenuModule.forRoot()
],
providers: [AuthService, NavigationService, NotificationService, MastodonService, StreamingService],
bootstrap: [AppComponent],
Expand Down
156 changes: 126 additions & 30 deletions src/app/components/create-status/create-status.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { identifierModuleUrl } from '@angular/compiler';
})
export class CreateStatusComponent implements OnInit, OnDestroy {
private _title: string;
set title(value: string){
set title(value: string) {
this._title = value;
this.countStatusChar(this.status);
}
Expand All @@ -30,14 +30,54 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
}

private _status: string = '';
@Input('status')
set status(value: string) {
this.countStatusChar(value);
this._status = value;
if (value) {
this.countStatusChar(value);
this._status = value;
}
}
get status(): string {
return this._status;
}

@Input('redraftedStatus')
set redraftedStatus(value: StatusWrapper) {
if (value) {
let parser = new DOMParser();
var dom = parser.parseFromString(value.status.content, 'text/html')
this.status = dom.body.textContent;

this.setVisibilityFromStatus(value.status);
this.title = value.status.spoiler_text;

if (value.status.in_reply_to_id) {
this.isSending = true;
this.mastodonService.getStatus(value.provider, value.status.in_reply_to_id)
.then((status: Status) => {
this.statusReplyingToWrapper = new StatusWrapper(status, value.provider);

const mentions = this.getMentions(this.statusReplyingToWrapper.status, this.statusReplyingToWrapper.provider);
for (const mention of mentions) {
const name = `@${mention.split('@')[0]}`;
if(this.status.includes(name)){
this.status = this.status.replace(name, `@${mention}`);
} else {
this.status = `@${mention} ` + this.status;
}
}

})
.catch(err => {
this.notificationService.notifyHttpError(err);
})
.then(() => {
this.isSending = false;
});
}
}
}

private maxCharLength: number;
charCountLeft: number;
postCounts: number = 1;
Expand All @@ -48,13 +88,38 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
@Output() onClose = new EventEmitter();
@ViewChild('reply') replyElement: ElementRef;

private _isDirectMention: boolean;
@Input('isDirectMention')
set isDirectMention(value: boolean) {
if (value) {
this._isDirectMention = value;
this.initMention();
}
}
get isDirectMention(): boolean {
return this._isDirectMention;
}

private _replyingUserHandle: string;
@Input('replyingUserHandle')
set replyingUserHandle(value: string) {
if (value) {
this._replyingUserHandle = value;
this.initMention();
}
}
get replyingUserHandle(): string {
return this._replyingUserHandle;
}

private statusReplyingTo: Status;

selectedPrivacy = 'Public';
privacyList: string[] = ['Public', 'Unlisted', 'Follows-only', 'DM'];

private accounts$: Observable<AccountInfo[]>;
private accountSub: Subscription;
private selectedAccount: AccountInfo;

constructor(
private readonly store: Store,
Expand All @@ -70,6 +135,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
this.accountSub = this.accounts$.subscribe((accounts: AccountInfo[]) => {
this.accountChanged(accounts);
});
this.selectedAccount = this.toolsService.getSelectedAccounts()[0];

if (this.statusReplyingToWrapper) {
if (this.statusReplyingToWrapper.status.reblog) {
Expand All @@ -83,43 +149,52 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
this.status += `@${mention} `;
}

switch (this.statusReplyingTo.visibility) {
case 'unlisted':
this.setVisibility(VisibilityEnum.Unlisted);
break;
case 'public':
this.setVisibility(VisibilityEnum.Public);
break;
case 'private':
this.setVisibility(VisibilityEnum.Private);
break;
case 'direct':
this.setVisibility(VisibilityEnum.Direct);
break;
}
this.setVisibilityFromStatus(this.statusReplyingTo);

this.title = this.statusReplyingTo.spoiler_text;
} else if (this.replyingUserHandle) {
this.initMention();
}

this.focus();
}

ngOnDestroy() {
this.accountSub.unsubscribe();
}

private focus() {
setTimeout(() => {
this.replyElement.nativeElement.focus();
}, 0);
}

ngOnDestroy() {
this.accountSub.unsubscribe();
private initMention() {
if (!this.selectedAccount) {
this.selectedAccount = this.toolsService.getSelectedAccounts()[0];
}

if (this.isDirectMention) {
this.setVisibility(VisibilityEnum.Direct);
} else {
this.getDefaultPrivacy();
}
this.status = `${this.replyingUserHandle} `;
this.countStatusChar(this.status);

this.focus();
}

private accountChanged(accounts: AccountInfo[]): void {
if (accounts && accounts.length > 0) {
const selectedAccount = accounts.filter(x => x.isSelected)[0];
this.selectedAccount = accounts.filter(x => x.isSelected)[0];

const settings = this.toolsService.getAccountSettings(selectedAccount);
const settings = this.toolsService.getAccountSettings(this.selectedAccount);
if (settings.customStatusCharLengthEnabled) {
this.maxCharLength = settings.customStatusCharLength;
this.countStatusChar(this.status);
} else {
this.instancesInfoService.getMaxStatusChars(selectedAccount.instance)
this.instancesInfoService.getMaxStatusChars(this.selectedAccount.instance)
.then((maxChars: number) => {
this.maxCharLength = maxChars;
this.countStatusChar(this.status);
Expand All @@ -129,18 +204,39 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
});
}

if (!this.statusReplyingToWrapper) {
this.instancesInfoService.getDefaultPrivacy(selectedAccount)
.then((defaultPrivacy: VisibilityEnum) => {
this.setVisibility(defaultPrivacy);
})
.catch((err: HttpErrorResponse) => {
this.notificationService.notifyHttpError(err);
});
if (!this.statusReplyingToWrapper && !this.replyingUserHandle) {
this.getDefaultPrivacy();
}
}
}

private getDefaultPrivacy() {
this.instancesInfoService.getDefaultPrivacy(this.selectedAccount)
.then((defaultPrivacy: VisibilityEnum) => {
this.setVisibility(defaultPrivacy);
})
.catch((err: HttpErrorResponse) => {
this.notificationService.notifyHttpError(err);
});
}

private setVisibilityFromStatus(status: Status) {
switch (status.visibility) {
case 'unlisted':
this.setVisibility(VisibilityEnum.Unlisted);
break;
case 'public':
this.setVisibility(VisibilityEnum.Public);
break;
case 'private':
this.setVisibility(VisibilityEnum.Private);
break;
case 'direct':
this.setVisibility(VisibilityEnum.Direct);
break;
}
}

private setVisibility(defaultPrivacy: VisibilityEnum) {
switch (defaultPrivacy) {
case VisibilityEnum.Public:
Expand Down
Loading

0 comments on commit f8e99ce

Please sign in to comment.