Skip to content

Commit

Permalink
Merge pull request #71 from NicolasConstant/develop
Browse files Browse the repository at this point in the history
Merge for 0.5
  • Loading branch information
NicolasConstant authored Apr 3, 2019
2 parents 829b526 + 3e54134 commit 9196b0c
Show file tree
Hide file tree
Showing 52 changed files with 1,826 additions and 241 deletions.
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}"
}
]
}
File renamed without changes.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "sengi",
"version": "0.0.0",
"license": "MIT",
"main": "main.js",
"license": "AGPL-3.0-or-later",
"main": "main-electron.js",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down
16 changes: 14 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ import { NotificationService } from "./services/notification.service";
import { MediaViewerComponent } from './components/media-viewer/media-viewer.component';
import { CreateStatusComponent } from './components/create-status/create-status.component';
import { MediaComponent } from './components/create-status/media/media.component';
import { MyAccountComponent } from './components/floating-column/manage-account/my-account/my-account.component';
import { FavoritesComponent } from './components/floating-column/manage-account/favorites/favorites.component';
import { DirectMessagesComponent } from './components/floating-column/manage-account/direct-messages/direct-messages.component';
import { MentionsComponent } from './components/floating-column/manage-account/mentions/mentions.component';
import { NotificationsComponent } from './components/floating-column/manage-account/notifications/notifications.component';
import { SettingsState } from './states/settings.state';

const routes: Routes = [
{ path: "", redirectTo: "home", pathMatch: "full" },
Expand Down Expand Up @@ -89,7 +95,12 @@ const routes: Routes = [
NotificationHubComponent,
MediaViewerComponent,
CreateStatusComponent,
MediaComponent
MediaComponent,
MyAccountComponent,
FavoritesComponent,
DirectMessagesComponent,
MentionsComponent,
NotificationsComponent
],
imports: [
FontAwesomeModule,
Expand All @@ -102,7 +113,8 @@ const routes: Routes = [
NgxsModule.forRoot([
RegisteredAppsState,
AccountsState,
StreamsState
StreamsState,
SettingsState
]),
NgxsStoragePluginModule.forRoot()
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ describe('CreateStatusComponent', () => {
expect(result[1].length).toBeLessThanOrEqual(527);
expect(result[0]).toContain('@Lorem@ipsum.com ');
expect(result[1]).toContain('@Lorem@ipsum.com ');
console.warn(result);
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
</a>
</div>

<app-manage-account *ngIf="openPanel === 'manageAccount'" [account]="userAccountUsed"></app-manage-account>
<app-manage-account *ngIf="openPanel === 'manageAccount'"
[account]="userAccountUsed"
(browseAccountEvent)="browseAccount($event)"
(browseHashtagEvent)="browseHashtag($event)"
(browseThreadEvent)="browseThread($event)"></app-manage-account>
<app-add-new-status *ngIf="openPanel === 'createNewStatus'"></app-add-new-status>
<app-add-new-account *ngIf="openPanel === 'addNewAccount'"></app-add-new-account>
<app-search *ngIf="openPanel === 'search'"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>
direct-messages works!
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { DirectMessagesComponent } from './direct-messages.component';

xdescribe('DirectMessagesComponent', () => {
let component: DirectMessagesComponent;
let fixture: ComponentFixture<DirectMessagesComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ DirectMessagesComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(DirectMessagesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { Component, OnInit, Input, Output, EventEmitter, ViewChild, ElementRef } from '@angular/core';

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 { StreamTypeEnum } from '../../../../states/streams.state';
import { Status } from '../../../../services/models/mastodon.interfaces';

@Component({
selector: 'app-direct-messages',
templateUrl: '../../../stream/stream-statuses/stream-statuses.component.html',
styleUrls: ['../../../stream/stream-statuses/stream-statuses.component.scss', './direct-messages.component.scss']
})
export class DirectMessagesComponent implements OnInit {
statuses: StatusWrapper[] = [];
displayError: string;
isLoading = true;
isThread = false;
hasContentWarnings = false;

@Output() browseAccountEvent = new EventEmitter<string>();
@Output() browseHashtagEvent = new EventEmitter<string>();
@Output() browseThreadEvent = new EventEmitter<OpenThreadEvent>();

private maxReached = false;
private _account: AccountWrapper;

@Input('account')
set account(acc: AccountWrapper) {
console.warn('account');
this._account = acc;
this.getDirectMessages();
}
get account(): AccountWrapper {
return this._account;
}

@ViewChild('statusstream') public statustream: ElementRef;

constructor(
private readonly notificationService: NotificationService,
private readonly mastodonService: MastodonService) { }

ngOnInit() {
}

private reset() {
this.isLoading = true;
this.statuses.length = 0;
this.maxReached = false;
}

private getDirectMessages() {
this.reset();

this.mastodonService.getTimeline(this.account.info, StreamTypeEnum.directmessages)
.then((statuses: Status[]) => {
//this.maxId = statuses[statuses.length - 1].id;
for (const s of statuses) {
const wrapper = new StatusWrapper(s, this.account.info);
this.statuses.push(wrapper);
}
})
.catch(err => {
this.notificationService.notifyHttpError(err);
})
.then(() => {
this.isLoading = false;
});
}

onScroll() {
var element = this.statustream.nativeElement as HTMLElement;
const atBottom = element.scrollHeight <= element.clientHeight + element.scrollTop + 1000;

if (atBottom) {
this.scrolledToBottom();
}
}

private scrolledToBottom() {
if (this.isLoading || this.maxReached) return;

const maxId = this.statuses[this.statuses.length - 1].status.id;
this.isLoading = true;
this.mastodonService.getTimeline(this.account.info, StreamTypeEnum.directmessages, maxId)
.then((statuses: Status[]) => {
if (statuses.length === 0) {
this.maxReached = true;
return;
}

for (const s of statuses) {
const wrapper = new StatusWrapper(s, this.account.info);
this.statuses.push(wrapper);
}
})
.catch(err => {
this.notificationService.notifyHttpError(err);
})
.then(() => {
this.isLoading = false;
});
}

browseAccount(accountName: string): void {
this.browseAccountEvent.next(accountName);
}

browseHashtag(hashtag: string): void {
this.browseHashtagEvent.next(hashtag);
}

browseThread(openThreadEvent: OpenThreadEvent): void {
this.browseThreadEvent.next(openThreadEvent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>
favorites works!
</p>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { FavoritesComponent } from './favorites.component';

xdescribe('FavoritesComponent', () => {
let component: FavoritesComponent;
let fixture: ComponentFixture<FavoritesComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ FavoritesComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(FavoritesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import { Component, OnInit, Output, EventEmitter, Input, ViewChild, ElementRef } from '@angular/core';

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 { Status } from '../../../../services/models/mastodon.interfaces';
import { NotificationService } from '../../../../services/notification.service';
import { resetCompiledComponents } from '@angular/core/src/render3/jit/module';

@Component({
selector: 'app-favorites',
templateUrl: '../../../stream/stream-statuses/stream-statuses.component.html',
styleUrls: ['../../../stream/stream-statuses/stream-statuses.component.scss', './favorites.component.scss']
})
export class FavoritesComponent implements OnInit {
statuses: StatusWrapper[] = [];
displayError: string;
isLoading = true;
isThread = false;
hasContentWarnings = false;

@Output() browseAccountEvent = new EventEmitter<string>();
@Output() browseHashtagEvent = new EventEmitter<string>();
@Output() browseThreadEvent = new EventEmitter<OpenThreadEvent>();

private maxReached = false;
private maxId: string;
private _account: AccountWrapper;

@Input('account')
set account(acc: AccountWrapper) {
this._account = acc;
this.getFavorites();
}
get account(): AccountWrapper {
return this._account;
}

@ViewChild('statusstream') public statustream: ElementRef;

constructor(
private readonly notificationService: NotificationService,
private readonly mastodonService: MastodonService) { }

ngOnInit() {
}

private reset(){
this.isLoading = true;
this.statuses.length = 0;
this.maxReached = false;
this.maxId = null;
}

private getFavorites() {
this.reset();

this.mastodonService.getFavorites(this.account.info)
.then((result: FavoriteResult) => {
this.maxId = result.max_id;
for (const s of result.favorites) {
const wrapper = new StatusWrapper(s, this.account.info);
this.statuses.push(wrapper);
}
})
.catch(err => {
this.notificationService.notifyHttpError(err);
})
.then(() => {
this.isLoading = false;
});

}

onScroll() {
var element = this.statustream.nativeElement as HTMLElement;
const atBottom = element.scrollHeight <= element.clientHeight + element.scrollTop + 1000;

if (atBottom) {
this.scrolledToBottom();
}
}


private scrolledToBottom() {
if (this.isLoading || this.maxReached) return;

this.isLoading = true;
this.mastodonService.getFavorites(this.account.info, this.maxId)
.then((result: FavoriteResult) => {
const statuses = result.favorites;
if (statuses.length === 0 || !this.maxId) {
this.maxReached = true;
return;
}

this.maxId = result.max_id;
for (const s of statuses) {
const wrapper = new StatusWrapper(s, this.account.info);
this.statuses.push(wrapper);
}
})
.catch(err => {
this.notificationService.notifyHttpError(err);
})
.then(() => {
this.isLoading = false;
});
}

browseAccount(accountName: string): void {
this.browseAccountEvent.next(accountName);
}

browseHashtag(hashtag: string): void {
this.browseHashtagEvent.next(hashtag);
}

browseThread(openThreadEvent: OpenThreadEvent): void {
this.browseThreadEvent.next(openThreadEvent);
}
}
Loading

0 comments on commit 9196b0c

Please sign in to comment.