fix search issues in 3.0.0rc1
This commit is contained in:
parent
2d9b48dede
commit
ebbd5c944f
|
@ -64,7 +64,12 @@ export class AutosuggestComponent implements OnInit, OnDestroy {
|
||||||
this.lastPatternUsed = pattern;
|
this.lastPatternUsed = pattern;
|
||||||
this.lastPatternUsedWtType = value;
|
this.lastPatternUsedWtType = value;
|
||||||
|
|
||||||
this.mastodonService.search(selectedAccount, pattern, false)
|
this.toolsService.getInstanceInfo(selectedAccount)
|
||||||
|
.then(instance => {
|
||||||
|
let version: 'v1' | 'v2' = 'v1';
|
||||||
|
if(instance.major >= 3) version = 'v2';
|
||||||
|
return this.mastodonService.search(selectedAccount, pattern, version, false);
|
||||||
|
})
|
||||||
.then((results: Results) => {
|
.then((results: Results) => {
|
||||||
if (this.lastPatternUsed !== pattern) return;
|
if (this.lastPatternUsed !== pattern) return;
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,12 @@ export class SearchComponent implements OnInit {
|
||||||
|
|
||||||
this.lastAccountUsed = this.toolsService.getSelectedAccounts()[0];
|
this.lastAccountUsed = this.toolsService.getSelectedAccounts()[0];
|
||||||
|
|
||||||
this.mastodonService.search(this.lastAccountUsed, data, true)
|
this.toolsService.getInstanceInfo(this.lastAccountUsed)
|
||||||
|
.then(instance => {
|
||||||
|
let version: 'v1' | 'v2' = 'v1';
|
||||||
|
if (instance.major >= 3) version = 'v2';
|
||||||
|
return this.mastodonService.search(this.lastAccountUsed, data, version, true)
|
||||||
|
})
|
||||||
.then((results: Results) => {
|
.then((results: Results) => {
|
||||||
if (results) {
|
if (results) {
|
||||||
this.accounts = results.accounts.slice(0, 5);
|
this.accounts = results.accounts.slice(0, 5);
|
||||||
|
|
|
@ -47,14 +47,14 @@ export class StatusUserContextMenuComponent implements OnInit, OnDestroy {
|
||||||
this.accounts$ = this.store.select(state => state.registeredaccounts.accounts);
|
this.accounts$ = this.store.select(state => state.registeredaccounts.accounts);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
if (this.statusWrapper) {
|
if (this.statusWrapper) {
|
||||||
const status = this.statusWrapper.status;
|
const status = this.statusWrapper.status;
|
||||||
if (status.reblog) {
|
if (status.reblog) {
|
||||||
this.displayedStatus = status.reblog;
|
this.displayedStatus = status.reblog;
|
||||||
} else {
|
} else {
|
||||||
this.displayedStatus = status;
|
this.displayedStatus = status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.accountSub = this.accounts$.subscribe((accounts: AccountInfo[]) => {
|
this.accountSub = this.accounts$.subscribe((accounts: AccountInfo[]) => {
|
||||||
|
@ -63,7 +63,7 @@ export class StatusUserContextMenuComponent implements OnInit, OnDestroy {
|
||||||
});
|
});
|
||||||
|
|
||||||
let account: Account;
|
let account: Account;
|
||||||
if(this.statusWrapper) {
|
if (this.statusWrapper) {
|
||||||
account = this.displayedStatus.account;
|
account = this.displayedStatus.account;
|
||||||
} else {
|
} else {
|
||||||
account = this.displayedAccount;
|
account = this.displayedAccount;
|
||||||
|
@ -82,7 +82,7 @@ export class StatusUserContextMenuComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
if(this.accountSub) this.accountSub.unsubscribe();
|
if (this.accountSub) this.accountSub.unsubscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
public onContextMenu($event: MouseEvent): void {
|
public onContextMenu($event: MouseEvent): void {
|
||||||
|
@ -259,10 +259,16 @@ export class StatusUserContextMenuComponent implements OnInit, OnDestroy {
|
||||||
let statusPromise: Promise<Status> = Promise.resolve(this.statusWrapper.status);
|
let statusPromise: Promise<Status> = Promise.resolve(this.statusWrapper.status);
|
||||||
|
|
||||||
if (account.id !== this.statusWrapper.provider.id) {
|
if (account.id !== this.statusWrapper.provider.id) {
|
||||||
statusPromise = this.mastodonService.search(account, this.statusWrapper.status.url, true)
|
statusPromise =
|
||||||
.then((result: Results) => {
|
this.toolsService.getInstanceInfo(account)
|
||||||
return result.statuses[0];
|
.then(instance => {
|
||||||
});
|
let version: 'v1' | 'v2' = 'v1';
|
||||||
|
if (instance.major >= 3) version = 'v2';
|
||||||
|
return this.mastodonService.search(account, this.statusWrapper.status.url, version, true);
|
||||||
|
})
|
||||||
|
.then((result: Results) => {
|
||||||
|
return result.statuses[0];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return statusPromise;
|
return statusPromise;
|
||||||
|
|
|
@ -128,7 +128,12 @@ export class ThreadComponent implements OnInit, OnDestroy {
|
||||||
var statusPromise: Promise<Status> = Promise.resolve(status);
|
var statusPromise: Promise<Status> = Promise.resolve(status);
|
||||||
|
|
||||||
if (sourceAccount.id !== currentAccount.id) {
|
if (sourceAccount.id !== currentAccount.id) {
|
||||||
statusPromise = this.mastodonService.search(currentAccount, status.uri, true)
|
statusPromise = this.toolsService.getInstanceInfo(currentAccount)
|
||||||
|
.then(instance => {
|
||||||
|
let version: 'v1' | 'v2' = 'v1';
|
||||||
|
if (instance.major >= 3) version = 'v2';
|
||||||
|
return this.mastodonService.search(currentAccount, status.uri, version, true);
|
||||||
|
})
|
||||||
.then((result: Results) => {
|
.then((result: Results) => {
|
||||||
if (result.statuses.length === 1) {
|
if (result.statuses.length === 1) {
|
||||||
const retrievedStatus = result.statuses[0];
|
const retrievedStatus = result.statuses[0];
|
||||||
|
|
|
@ -128,9 +128,12 @@ export class MastodonService {
|
||||||
return this.httpClient.get<Status>(route, { headers: headers }).toPromise()
|
return this.httpClient.get<Status>(route, { headers: headers }).toPromise()
|
||||||
}
|
}
|
||||||
|
|
||||||
search(account: AccountInfo, query: string, resolve: boolean = false): Promise<Results> {
|
search(account: AccountInfo, query: string, version: 'v1' | 'v2', resolve: boolean = false): Promise<Results> {
|
||||||
if (query[0] === '#') query = query.substr(1);
|
if (query[0] === '#') query = query.substr(1);
|
||||||
const route = `https://${account.instance}${this.apiRoutes.search}?q=${query}&resolve=${resolve}`;
|
let searchRoute = this.apiRoutes.search;
|
||||||
|
if(version === 'v2') searchRoute = this.apiRoutes.searchV2;
|
||||||
|
|
||||||
|
const route = `https://${account.instance}${searchRoute}?q=${query}&resolve=${resolve}`;
|
||||||
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
|
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
|
||||||
return this.httpClient.get<Results>(route, { headers: headers }).toPromise()
|
return this.httpClient.get<Results>(route, { headers: headers }).toPromise()
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,11 +12,37 @@ import { AccountSettings, SaveAccountSettings } from '../states/settings.state';
|
||||||
})
|
})
|
||||||
export class ToolsService {
|
export class ToolsService {
|
||||||
private accountAvatar: { [id: string]: string; } = {};
|
private accountAvatar: { [id: string]: string; } = {};
|
||||||
|
private instanceInfos: { [id: string]: InstanceInfo } = {};
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly mastodonService: MastodonService,
|
private readonly mastodonService: MastodonService,
|
||||||
private readonly store: Store) { }
|
private readonly store: Store) { }
|
||||||
|
|
||||||
|
getInstanceInfo(acc: AccountInfo): Promise<InstanceInfo> {
|
||||||
|
if (this.instanceInfos[acc.instance]) {
|
||||||
|
return Promise.resolve(this.instanceInfos[acc.instance]);
|
||||||
|
} else {
|
||||||
|
return this.mastodonService.getInstance(acc.instance)
|
||||||
|
.then(instance => {
|
||||||
|
var type = InstanceType.Mastodon;
|
||||||
|
if (instance.version.toLowerCase().includes('pleroma')) {
|
||||||
|
type = InstanceType.Pleroma;
|
||||||
|
} else if (instance.version.toLowerCase().includes('+glitch')) {
|
||||||
|
type = InstanceType.GlitchSoc;
|
||||||
|
} else if (instance.version.toLowerCase().includes('+florence')) {
|
||||||
|
type = InstanceType.Florence;
|
||||||
|
}
|
||||||
|
|
||||||
|
var splittedVersion = instance.version.split('.');
|
||||||
|
var major = +splittedVersion[0];
|
||||||
|
var minor = +splittedVersion[1];
|
||||||
|
|
||||||
|
var instanceInfo = new InstanceInfo(type, major, minor);
|
||||||
|
this.instanceInfos[acc.instance] = instanceInfo;
|
||||||
|
return instanceInfo;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getAvatar(acc: AccountInfo): Promise<string> {
|
getAvatar(acc: AccountInfo): Promise<string> {
|
||||||
if (this.accountAvatar[acc.id]) {
|
if (this.accountAvatar[acc.id]) {
|
||||||
|
@ -60,7 +86,12 @@ export class ToolsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
findAccount(account: AccountInfo, accountName: string): Promise<Account> {
|
findAccount(account: AccountInfo, accountName: string): Promise<Account> {
|
||||||
return this.mastodonService.search(account, accountName, true)
|
return this.getInstanceInfo(account)
|
||||||
|
.then(instance => {
|
||||||
|
let version: 'v1' | 'v2' = 'v1';
|
||||||
|
if (instance.major >= 3) version = 'v2';
|
||||||
|
return this.mastodonService.search(account, accountName, version, true);
|
||||||
|
})
|
||||||
.then((result: Results) => {
|
.then((result: Results) => {
|
||||||
if (accountName[0] === '@') accountName = accountName.substr(1);
|
if (accountName[0] === '@') accountName = accountName.substr(1);
|
||||||
|
|
||||||
|
@ -80,13 +111,19 @@ export class ToolsService {
|
||||||
let statusPromise: Promise<Status> = Promise.resolve(originalStatus.status);
|
let statusPromise: Promise<Status> = Promise.resolve(originalStatus.status);
|
||||||
|
|
||||||
if (!isProvider) {
|
if (!isProvider) {
|
||||||
statusPromise = statusPromise.then((foreignStatus: Status) => {
|
statusPromise = statusPromise
|
||||||
const statusUrl = foreignStatus.url;
|
.then((foreignStatus: Status) => {
|
||||||
return this.mastodonService.search(account, statusUrl, true)
|
const statusUrl = foreignStatus.url;
|
||||||
.then((results: Results) => {
|
return this.getInstanceInfo(account)
|
||||||
return results.statuses[0];
|
.then(instance => {
|
||||||
});
|
let version: 'v1' | 'v2' = 'v1';
|
||||||
});
|
if (instance.major >= 3) version = 'v2';
|
||||||
|
return this.mastodonService.search(account, statusUrl, version, true);
|
||||||
|
})
|
||||||
|
.then((results: Results) => {
|
||||||
|
return results.statuses[0];
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return statusPromise;
|
return statusPromise;
|
||||||
|
@ -121,3 +158,18 @@ export class OpenThreadEvent {
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class InstanceInfo {
|
||||||
|
constructor(
|
||||||
|
public readonly type: InstanceType,
|
||||||
|
public readonly major: number,
|
||||||
|
public readonly minor: number) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum InstanceType {
|
||||||
|
Mastodon = 1,
|
||||||
|
Pleroma = 2,
|
||||||
|
GlitchSoc = 3,
|
||||||
|
Florence = 4
|
||||||
|
}
|
Loading…
Reference in New Issue