Merge pull request #167 from NicolasConstant/fix_Masto3.0.0rc1

Fix masto3.0.0rc1
This commit is contained in:
Nicolas Constant 2019-09-25 00:37:24 -04:00 committed by GitHub
commit 46383c5fda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 98 additions and 22 deletions

View File

@ -1,6 +1,6 @@
{
"name": "sengi",
"version": "0.16.0",
"version": "0.16.1",
"license": "AGPL-3.0-or-later",
"main": "main-electron.js",
"description": "A multi-account desktop client for Mastodon and Pleroma",

View File

@ -64,7 +64,12 @@ export class AutosuggestComponent implements OnInit, OnDestroy {
this.lastPatternUsed = pattern;
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) => {
if (this.lastPatternUsed !== pattern) return;

View File

@ -69,7 +69,12 @@ export class SearchComponent implements OnInit {
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) => {
if (results) {
this.accounts = results.accounts.slice(0, 5);

View File

@ -47,14 +47,14 @@ export class StatusUserContextMenuComponent implements OnInit, OnDestroy {
this.accounts$ = this.store.select(state => state.registeredaccounts.accounts);
}
ngOnInit() {
ngOnInit() {
if (this.statusWrapper) {
const status = this.statusWrapper.status;
if (status.reblog) {
this.displayedStatus = status.reblog;
} else {
this.displayedStatus = status;
}
}
}
this.accountSub = this.accounts$.subscribe((accounts: AccountInfo[]) => {
@ -63,7 +63,7 @@ export class StatusUserContextMenuComponent implements OnInit, OnDestroy {
});
let account: Account;
if(this.statusWrapper) {
if (this.statusWrapper) {
account = this.displayedStatus.account;
} else {
account = this.displayedAccount;
@ -82,7 +82,7 @@ export class StatusUserContextMenuComponent implements OnInit, OnDestroy {
ngOnDestroy(): void {
if(this.accountSub) this.accountSub.unsubscribe();
if (this.accountSub) this.accountSub.unsubscribe();
}
public onContextMenu($event: MouseEvent): void {
@ -259,10 +259,16 @@ export class StatusUserContextMenuComponent implements OnInit, OnDestroy {
let statusPromise: Promise<Status> = Promise.resolve(this.statusWrapper.status);
if (account.id !== this.statusWrapper.provider.id) {
statusPromise = this.mastodonService.search(account, this.statusWrapper.status.url, true)
.then((result: Results) => {
return result.statuses[0];
});
statusPromise =
this.toolsService.getInstanceInfo(account)
.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;

View File

@ -128,7 +128,12 @@ export class ThreadComponent implements OnInit, OnDestroy {
var statusPromise: Promise<Status> = Promise.resolve(status);
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) => {
if (result.statuses.length === 1) {
const retrievedStatus = result.statuses[0];

View File

@ -128,9 +128,12 @@ export class MastodonService {
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);
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}` });
return this.httpClient.get<Results>(route, { headers: headers }).toPromise()
}

View File

@ -12,11 +12,37 @@ import { AccountSettings, SaveAccountSettings } from '../states/settings.state';
})
export class ToolsService {
private accountAvatar: { [id: string]: string; } = {};
private instanceInfos: { [id: string]: InstanceInfo } = {};
constructor(
private readonly mastodonService: MastodonService,
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> {
if (this.accountAvatar[acc.id]) {
@ -60,7 +86,12 @@ export class ToolsService {
}
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) => {
if (accountName[0] === '@') accountName = accountName.substr(1);
@ -80,13 +111,19 @@ export class ToolsService {
let statusPromise: Promise<Status> = Promise.resolve(originalStatus.status);
if (!isProvider) {
statusPromise = statusPromise.then((foreignStatus: Status) => {
const statusUrl = foreignStatus.url;
return this.mastodonService.search(account, statusUrl, true)
.then((results: Results) => {
return results.statuses[0];
});
});
statusPromise = statusPromise
.then((foreignStatus: Status) => {
const statusUrl = foreignStatus.url;
return this.getInstanceInfo(account)
.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;
@ -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
}