mirror of
https://github.com/NicolasConstant/sengi
synced 2025-02-10 00:40:36 +01:00
Merge pull request #167 from NicolasConstant/fix_Masto3.0.0rc1
Fix masto3.0.0rc1
This commit is contained in:
commit
46383c5fda
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sengi",
|
"name": "sengi",
|
||||||
"version": "0.16.0",
|
"version": "0.16.1",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
"main": "main-electron.js",
|
"main": "main-electron.js",
|
||||||
"description": "A multi-account desktop client for Mastodon and Pleroma",
|
"description": "A multi-account desktop client for Mastodon and Pleroma",
|
||||||
|
@ -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);
|
||||||
|
@ -259,7 +259,13 @@ 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 =
|
||||||
|
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) => {
|
.then((result: Results) => {
|
||||||
return result.statuses[0];
|
return result.statuses[0];
|
||||||
});
|
});
|
||||||
|
@ -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,9 +111,15 @@ 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
|
||||||
|
.then((foreignStatus: Status) => {
|
||||||
const statusUrl = foreignStatus.url;
|
const statusUrl = foreignStatus.url;
|
||||||
return this.mastodonService.search(account, statusUrl, true)
|
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) => {
|
.then((results: Results) => {
|
||||||
return results.statuses[0];
|
return results.statuses[0];
|
||||||
});
|
});
|
||||||
@ -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…
x
Reference in New Issue
Block a user