added emoji cache
This commit is contained in:
parent
761a910d31
commit
f11d82c072
|
@ -10,7 +10,7 @@ import { AccountSettings, SaveAccountSettings } from '../states/settings.state';
|
|||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ToolsService {
|
||||
export class ToolsService {
|
||||
constructor(
|
||||
private readonly mastodonService: MastodonService,
|
||||
private readonly store: Store) { }
|
||||
|
@ -20,23 +20,23 @@ export class ToolsService {
|
|||
var regAccounts = <AccountInfo[]>this.store.snapshot().registeredaccounts.accounts;
|
||||
return regAccounts.filter(x => x.isSelected);
|
||||
}
|
||||
|
||||
|
||||
getAccountSettings(account: AccountInfo): AccountSettings {
|
||||
var accountsSettings = <AccountSettings[]>this.store.snapshot().globalsettings.settings.accountSettings;
|
||||
let accountSettings = accountsSettings.find(x => x.accountId === account.id);
|
||||
if(!accountSettings){
|
||||
if (!accountSettings) {
|
||||
accountSettings = new AccountSettings();
|
||||
accountSettings.accountId = account.id;
|
||||
this.saveAccountSettings(accountSettings);
|
||||
this.saveAccountSettings(accountSettings);
|
||||
}
|
||||
if(!accountSettings.customStatusCharLength){
|
||||
if (!accountSettings.customStatusCharLength) {
|
||||
accountSettings.customStatusCharLength = 500;
|
||||
this.saveAccountSettings(accountSettings);
|
||||
}
|
||||
return accountSettings;
|
||||
}
|
||||
|
||||
saveAccountSettings(accountSettings: AccountSettings){
|
||||
saveAccountSettings(accountSettings: AccountSettings) {
|
||||
this.store.dispatch([
|
||||
new SaveAccountSettings(accountSettings)
|
||||
])
|
||||
|
@ -45,19 +45,19 @@ export class ToolsService {
|
|||
findAccount(account: AccountInfo, accountName: string): Promise<Account> {
|
||||
return this.mastodonService.search(account, accountName, true)
|
||||
.then((result: Results) => {
|
||||
if(accountName[0] === '@') accountName = accountName.substr(1);
|
||||
if (accountName[0] === '@') accountName = accountName.substr(1);
|
||||
|
||||
const foundAccount = result.accounts.find(
|
||||
x => (x.acct.toLowerCase() === accountName.toLowerCase()
|
||||
||
|
||||
(x.acct.toLowerCase().split('@')[0] === accountName.toLowerCase().split('@')[0])
|
||||
&& x.url.replace('https://', '').split('/')[0] === accountName.toLowerCase().split('@')[1])
|
||||
);
|
||||
||
|
||||
(x.acct.toLowerCase().split('@')[0] === accountName.toLowerCase().split('@')[0])
|
||||
&& x.url.replace('https://', '').split('/')[0] === accountName.toLowerCase().split('@')[1])
|
||||
);
|
||||
return foundAccount;
|
||||
});
|
||||
}
|
||||
|
||||
getStatusUsableByAccount(account: AccountInfo, originalStatus: StatusWrapper): Promise<Status>{
|
||||
getStatusUsableByAccount(account: AccountInfo, originalStatus: StatusWrapper): Promise<Status> {
|
||||
const isProvider = originalStatus.provider.id === account.id;
|
||||
|
||||
let statusPromise: Promise<Status> = Promise.resolve(originalStatus.status);
|
||||
|
@ -82,15 +82,19 @@ export class ToolsService {
|
|||
}
|
||||
return `@${fullHandle}`;
|
||||
}
|
||||
|
||||
getCustomEmojis(account: AccountInfo): Promise<Emoji[]> {
|
||||
//TODO: add cache
|
||||
|
||||
return this.mastodonService.getCustomEmojis(account)
|
||||
.then(emojis => {
|
||||
return emojis.filter(x => x.visible_in_picker);
|
||||
});
|
||||
}
|
||||
private emojiCache: { [id: string]: Emoji[] } = {};
|
||||
getCustomEmojis(account: AccountInfo): Promise<Emoji[]> {
|
||||
if (this.emojiCache[account.id]) {
|
||||
return Promise.resolve(this.emojiCache[account.id]);
|
||||
} else {
|
||||
return this.mastodonService.getCustomEmojis(account)
|
||||
.then(emojis => {
|
||||
this.emojiCache[account.id] = emojis.filter(x => x.visible_in_picker);
|
||||
return this.emojiCache[account.id];
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class OpenThreadEvent {
|
||||
|
|
Loading…
Reference in New Issue