296 lines
13 KiB
TypeScript
296 lines
13 KiB
TypeScript
|
import { Injectable } from '@angular/core';
|
||
|
|
||
|
import { Account, Status, Results, Context, Relationship, Instance, Attachment, Notification, List, Poll, Emoji, Conversation, ScheduledStatus } from "./models/mastodon.interfaces";
|
||
|
import { AccountInfo } from '../states/accounts.state';
|
||
|
import { StreamTypeEnum, StreamElement } from '../states/streams.state';
|
||
|
import { FavoriteResult, VisibilityEnum, PollParameters, MastodonService } from './mastodon.service';
|
||
|
|
||
|
@Injectable({
|
||
|
providedIn: 'root'
|
||
|
})
|
||
|
export class MastodonWrapperService {
|
||
|
|
||
|
constructor(private readonly mastodonService: MastodonService) { }
|
||
|
|
||
|
private refreshAccountIfNeeded(accountInfo: AccountInfo): Promise<AccountInfo> {
|
||
|
return Promise.resolve(accountInfo);
|
||
|
}
|
||
|
|
||
|
getInstance(instance: string): Promise<Instance> {
|
||
|
return this.mastodonService.getInstance(instance);
|
||
|
}
|
||
|
|
||
|
retrieveAccountDetails(account: AccountInfo): Promise<Account> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.retrieveAccountDetails(refreshedAccount);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
getTimeline(account: AccountInfo, type: StreamTypeEnum, max_id: string = null, since_id: string = null, limit: number = 20, tag: string = null, listId: string = null): Promise<Status[]> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.getTimeline(refreshedAccount, type, max_id, since_id, limit, tag, listId);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
getConversations(account: AccountInfo, max_id: string = null, since_id: string = null, min_id = null, limit: number = 20): Promise<Conversation[]> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.getConversations(refreshedAccount, max_id, since_id, min_id, limit);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
postNewStatus(account: AccountInfo, status: string, visibility: VisibilityEnum, spoiler: string = null, in_reply_to_id: string = null, mediaIds: string[], poll: PollParameters = null, scheduled_at: string = null): Promise<Status> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.postNewStatus(refreshedAccount, status, visibility, spoiler, in_reply_to_id, mediaIds, poll, scheduled_at);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
getStatus(account: AccountInfo, statusId: string): Promise<Status> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.getStatus(refreshedAccount, statusId);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
search(account: AccountInfo, query: string, version: 'v1' | 'v2', resolve: boolean = false): Promise<Results> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.search(refreshedAccount, query, version, resolve);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
getAccountStatuses(account: AccountInfo, targetAccountId: number, onlyMedia: boolean, onlyPinned: boolean, excludeReplies: boolean, maxId: string, sinceId: string, limit: number = 20): Promise<Status[]> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.getAccountStatuses(refreshedAccount, targetAccountId, onlyMedia, onlyPinned, excludeReplies, maxId, sinceId, limit);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
getStatusContext(account: AccountInfo, targetStatusId: string): Promise<Context> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.getStatusContext(refreshedAccount, targetStatusId);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
getFavorites(account: AccountInfo, maxId: string = null): Promise<FavoriteResult> { //, minId: string = null
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.getFavorites(refreshedAccount, maxId);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
searchAccount(account: AccountInfo, query: string, limit: number = 40, following: boolean = false, resolve = true): Promise<Account[]> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.searchAccount(refreshedAccount, query, limit, following, resolve);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
reblog(account: AccountInfo, status: Status): Promise<Status> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.reblog(refreshedAccount, status);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
unreblog(account: AccountInfo, status: Status): Promise<Status> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.unreblog(refreshedAccount, status);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
favorite(account: AccountInfo, status: Status): Promise<Status> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.favorite(refreshedAccount, status);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
unfavorite(account: AccountInfo, status: Status): Promise<Status> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.unfavorite(refreshedAccount, status);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
getRelationships(account: AccountInfo, accountsToRetrieve: Account[]): Promise<Relationship[]> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.getRelationships(refreshedAccount, accountsToRetrieve);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
follow(currentlyUsedAccount: AccountInfo, account: Account): Promise<Relationship> {
|
||
|
return this.refreshAccountIfNeeded(currentlyUsedAccount)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.follow(refreshedAccount, account);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
unfollow(currentlyUsedAccount: AccountInfo, account: Account): Promise<Relationship> {
|
||
|
return this.refreshAccountIfNeeded(currentlyUsedAccount)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.unfollow(refreshedAccount, account);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
uploadMediaAttachment(account: AccountInfo, file: File, description: string): Promise<Attachment> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.uploadMediaAttachment(refreshedAccount, file, description);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
updateMediaAttachment(account: AccountInfo, mediaId: string, description: string): Promise<Attachment> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.updateMediaAttachment(refreshedAccount, mediaId, description);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
getNotifications(account: AccountInfo, excludeTypes: string[] = null, maxId: string = null, sinceId: string = null, limit: number = 15): Promise<Notification[]> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.getNotifications(refreshedAccount, excludeTypes, maxId, sinceId, limit);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
getLists(account: AccountInfo): Promise<StreamElement[]> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.getLists(refreshedAccount);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
createList(account: AccountInfo, title: string): Promise<StreamElement> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.createList(refreshedAccount, title);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
deleteList(account: AccountInfo, listId: string): Promise<any> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.deleteList(refreshedAccount, listId);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
getListAccounts(account: AccountInfo, listId: string): Promise<Account[]> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.getListAccounts(refreshedAccount, listId);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
addAccountToList(account: AccountInfo, listId: string, accountId: number): Promise<any> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.addAccountToList(refreshedAccount, listId, accountId);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
removeAccountFromList(account: AccountInfo, listId: string, accountId: number): Promise<any> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.removeAccountFromList(refreshedAccount, listId, accountId);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
voteOnPoll(account: AccountInfo, pollId: string, pollSelection: number[]): Promise<Poll> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.voteOnPoll(refreshedAccount, pollId, pollSelection);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
getPoll(account: AccountInfo, pollId: string): Promise<Poll> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.getPoll(refreshedAccount, pollId);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
mute(account: AccountInfo, accounId: number): Promise<Relationship> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.mute(refreshedAccount, accounId);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
block(account: AccountInfo, accounId: number): Promise<Relationship> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.block(refreshedAccount, accounId);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
pinOnProfile(account: AccountInfo, statusId: string): Promise<Status> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.pinOnProfile(refreshedAccount, statusId);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
unpinFromProfile(account: AccountInfo, statusId: string): Promise<Status> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.unpinFromProfile(refreshedAccount, statusId);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
muteConversation(account: AccountInfo, statusId: string): Promise<Status> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.muteConversation(refreshedAccount, statusId);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
unmuteConversation(account: AccountInfo, statusId: string): Promise<Status> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.unmuteConversation(refreshedAccount, statusId);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
deleteStatus(account: AccountInfo, statusId: string): Promise<any> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.deleteStatus(refreshedAccount, statusId);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
getCustomEmojis(account: AccountInfo): Promise<Emoji[]> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.getCustomEmojis(refreshedAccount);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
getScheduledStatuses(account: AccountInfo): Promise<ScheduledStatus[]> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.getScheduledStatuses(refreshedAccount);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
changeScheduledStatus(account: AccountInfo, statusId: string, scheduled_at: string): Promise<ScheduledStatus> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.changeScheduledStatus(refreshedAccount, statusId, scheduled_at);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
deleteScheduledStatus(account: AccountInfo, statusId: string): Promise<any> {
|
||
|
return this.refreshAccountIfNeeded(account)
|
||
|
.then((refreshedAccount: AccountInfo) => {
|
||
|
return this.mastodonService.deleteScheduledStatus(refreshedAccount, statusId);
|
||
|
});
|
||
|
}
|
||
|
}
|