starting handling hashtags

This commit is contained in:
Nicolas Constant 2018-11-03 01:38:52 -04:00
parent 628cb94505
commit d92cca787b
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
6 changed files with 28 additions and 40 deletions

View File

@ -18,9 +18,9 @@ export class ManageAccountComponent implements OnInit {
ngOnInit() {
this.availableStreams.length = 0;
this.availableStreams.push(new StreamElement(StreamTypeEnum.global, 'Global Timeline', this.account.info.id));
this.availableStreams.push(new StreamElement(StreamTypeEnum.local, 'Local Timeline', this.account.info.id));
this.availableStreams.push(new StreamElement(StreamTypeEnum.personnal, 'Personnal Timeline', this.account.info.id));
this.availableStreams.push(new StreamElement(StreamTypeEnum.global, 'Global Timeline', this.account.info.id, null, null));
this.availableStreams.push(new StreamElement(StreamTypeEnum.local, 'Local Timeline', this.account.info.id, null, null));
this.availableStreams.push(new StreamElement(StreamTypeEnum.personnal, 'Personnal Timeline', this.account.info.id, null, null));
}
addStream(stream: StreamElement): boolean {

View File

@ -6,6 +6,7 @@ import { AccountInfo } from '../../../states/accounts.state';
import { Results, Account, Status } from '../../../services/models/mastodon.interfaces';
import { ToolsService } from '../../../services/tools.service';
import { StatusWrapper } from '../../stream/stream.component';
import { StreamElement, StreamTypeEnum, AddStream } from './../../../states/streams.state';
@Component({
@ -38,9 +39,16 @@ export class SearchComponent implements OnInit {
addHashtag(hashtag: string): boolean {
console.warn(hashtag);
if (hashtag) {
const newStream = new StreamElement(StreamTypeEnum.tag, `#${hashtag}`, this.lastAccountUsed.id, hashtag, null);
this.store.dispatch([new AddStream(newStream)]);
}
return false;
}
private lastAccountUsed: AccountInfo;
private search(data: string) {
this.accounts.length = 0;
this.statuses.length = 0;
@ -52,8 +60,8 @@ export class SearchComponent implements OnInit {
const enabledAccounts = this.toolsService.getSelectedAccounts();
//First candid implementation
if (enabledAccounts.length > 0) {
const candid_oneAccount = enabledAccounts[0];
this.mastodonService.search(candid_oneAccount, data, true)
this.lastAccountUsed = enabledAccounts[0];
this.mastodonService.search(this.lastAccountUsed, data, true)
.then((results: Results) => {
if (results) {
console.warn(results);
@ -61,10 +69,10 @@ export class SearchComponent implements OnInit {
this.hashtags = results.hashtags;
for (let status of results.statuses) {
const statusWrapper = new StatusWrapper(status, candid_oneAccount);
this.statuses.push(statusWrapper);
const statusWrapper = new StatusWrapper(status, this.lastAccountUsed);
this.statuses.push(statusWrapper);
}
}
})

View File

@ -149,7 +149,7 @@ export class StreamComponent implements OnInit {
}
private retrieveToots(): void {
this.mastodonService.getTimeline(this.account, this._streamElement.type)
this.mastodonService.getTimeline(this.account, this._streamElement.type, null, null, 20, this._streamElement.tag, this._streamElement.list)
.then((results: Status[]) => {
for (const s of results) {
const wrapper = new StatusWrapper(s, this.account);

View File

@ -19,13 +19,13 @@ export class MastodonService {
return this.httpClient.get<Account>('https://' + account.instance + this.apiRoutes.getCurrentAccount, { headers: headers }).toPromise();
}
getTimeline(account: AccountInfo, type: StreamTypeEnum, max_id: string = null, since_id: string = null, limit: number = 20): Promise<Status[]> {
const route = `https://${account.instance}${this.getTimelineRoute(type, max_id, since_id, limit)}`;
getTimeline(account: AccountInfo, type: StreamTypeEnum, max_id: string = null, since_id: string = null, limit: number = 20, tag: string = null, list: string = null): Promise<Status[]> {
const route = `https://${account.instance}${this.getTimelineRoute(type, max_id, since_id, limit, tag, list)}`;
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
return this.httpClient.get<Status[]>(route, { headers: headers }).toPromise()
}
private getTimelineRoute(type: StreamTypeEnum, max_id: string, since_id: string, limit: number): string {
private getTimelineRoute(type: StreamTypeEnum, max_id: string, since_id: string, limit: number, tag: string, list: string): string {
let route: string;
switch (type) {
case StreamTypeEnum.personnal:
@ -41,10 +41,10 @@ export class MastodonService {
route = this.apiRoutes.getDirectTimeline;
break;
case StreamTypeEnum.tag:
route = this.apiRoutes.getTagTimeline.replace('{0}', 'TODO');
route = this.apiRoutes.getTagTimeline.replace('{0}', tag);
break;
case StreamTypeEnum.list:
route = this.apiRoutes.getListTimeline.replace('{0}', 'TODO');
route = this.apiRoutes.getListTimeline.replace('{0}', list);
break;
default:
throw new Error('StreamTypeEnum not supported');

View File

@ -44,37 +44,13 @@ export class StreamingWrapper {
private errorClosing: boolean;
private webSocketGotError(x: Event) {
console.log(x);
this.errorClosing = true;
}
private since_id: string;
private webSocketClosed(domain, x: Event) {
console.log(x);
if (this.errorClosing) {
this.pullNewStatuses(domain);
// this.mastodonService.getTimeline(this.accountInfo, this.streamType, null, this.since_id)
// .then((status: Status[]) => {
// // status = status.sort((n1, n2) => { return (<number>n1.id) < (<number>n2.id); });
// status = status.sort((a, b) => a.id.localeCompare(b.id));
// for (const s of status) {
// const update = new StatusUpdate();
// update.status = s;
// update.type = EventEnum.update;
// this.since_id = update.status.id;
// this.statusUpdateSubjet.next(update);
// }
// })
// .catch(err => {
// console.error(err);
// })
// .then(() => {
// setTimeout(() => { this.start(domain) }, 20 * 1000);
// });
this.errorClosing = false;
} else {
setTimeout(() => { this.start(domain) }, 5000);

View File

@ -26,8 +26,12 @@ export class StreamsState {
}
export class StreamElement {
constructor(public type: StreamTypeEnum, public name: string, public accountId: string) {
constructor(
public type: StreamTypeEnum,
public name: string,
public accountId: string,
public tag: string,
public list: string) {
}
}