working follow_request logic
This commit is contained in:
parent
d67ef4aaf2
commit
3be94a842d
|
@ -1,5 +1,5 @@
|
|||
<div class="notification">
|
||||
<div *ngIf="notification.type === 'follow_request'">
|
||||
<div *ngIf="notification.type === 'follow_request' && !followRequestProcessed">
|
||||
<div class="stream__notification--icon" title="{{notification.account.acct}}">
|
||||
<fa-icon class="followed" [icon]="faUserClock"></fa-icon>
|
||||
</div>
|
||||
|
|
|
@ -100,7 +100,7 @@ $acccount-info-left: 70px;
|
|||
padding: 2px;
|
||||
|
||||
text-align: center;
|
||||
color: rgb(219, 219, 219);
|
||||
color: rgb(182, 182, 182);
|
||||
transition: all .2s;
|
||||
|
||||
// outline: 1px dotted greenyellow;
|
||||
|
|
|
@ -5,6 +5,8 @@ import { NotificationWrapper } from '../notifications.component';
|
|||
import { ToolsService } from '../../../../../services/tools.service';
|
||||
import { Account } from '../../../../../services/models/mastodon.interfaces';
|
||||
import { BrowseBase } from '../../../../../components/common/browse-base';
|
||||
import { MastodonWrapperService } from '../../../../../services/mastodon-wrapper.service';
|
||||
import { NotificationService } from '../../../../../services/notification.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-notification',
|
||||
|
@ -19,7 +21,10 @@ export class NotificationComponent extends BrowseBase {
|
|||
|
||||
@Input() notification: NotificationWrapper;
|
||||
|
||||
constructor(private readonly toolsService: ToolsService) {
|
||||
constructor(
|
||||
private readonly notificationsService: NotificationService,
|
||||
private readonly mastodonService: MastodonWrapperService,
|
||||
private readonly toolsService: ToolsService) {
|
||||
super();
|
||||
}
|
||||
|
||||
|
@ -40,12 +45,40 @@ export class NotificationComponent extends BrowseBase {
|
|||
return false;
|
||||
}
|
||||
|
||||
acceptFollowRequest(): boolean{
|
||||
followRequestWorking: boolean;
|
||||
followRequestProcessed: boolean;
|
||||
acceptFollowRequest(): boolean {
|
||||
if(this.followRequestWorking) return false;
|
||||
this.followRequestWorking = true;
|
||||
|
||||
this.mastodonService.authorizeFollowRequest(this.notification.provider, this.notification.notification.account.id)
|
||||
.then(res => {
|
||||
this.followRequestProcessed = true;
|
||||
})
|
||||
.catch(err => {
|
||||
this.notificationsService.notifyHttpError(err, this.notification.provider);
|
||||
})
|
||||
.then(res => {
|
||||
this.followRequestWorking = false;
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
refuseFollowRequest(): boolean{
|
||||
refuseFollowRequest(): boolean {
|
||||
if(this.followRequestWorking) return false;
|
||||
this.followRequestWorking = true;
|
||||
|
||||
this.mastodonService.rejectFollowRequest(this.notification.provider, this.notification.notification.account.id)
|
||||
.then(res => {
|
||||
this.followRequestProcessed = true;
|
||||
})
|
||||
.catch(err => {
|
||||
this.notificationsService.notifyHttpError(err, this.notification.provider);
|
||||
})
|
||||
.then(res => {
|
||||
this.followRequestWorking = false;
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -158,8 +158,10 @@ export class NotificationWrapper {
|
|||
this.account = notification.account;
|
||||
this.wrapperId = `${this.type}-${notification.id}`;
|
||||
this.notification = notification;
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
provider: AccountInfo;
|
||||
notification: Notification;
|
||||
wrapperId: string;
|
||||
account: Account;
|
||||
|
|
|
@ -237,7 +237,7 @@ export class StreamNotificationsComponent extends BrowseBase {
|
|||
|
||||
this.isMentionsLoading = true;
|
||||
|
||||
this.mastodonService.getNotifications(this.account, ['follow', 'favourite', 'reblog', 'poll'], this.lastMentionId)
|
||||
this.mastodonService.getNotifications(this.account, ['follow', 'favourite', 'reblog', 'poll', 'follow_request'], this.lastMentionId)
|
||||
.then((result: Notification[]) => {
|
||||
if (result.length === 0) {
|
||||
this.mentionsMaxReached = true;
|
||||
|
|
|
@ -252,7 +252,7 @@ export class MastodonWrapperService {
|
|||
});
|
||||
}
|
||||
|
||||
getNotifications(account: AccountInfo, excludeTypes: ('follow' | 'favourite' | 'reblog' | 'mention' | 'poll')[] = null, maxId: string = null, sinceId: string = null, limit: number = 15): Promise<Notification[]> {
|
||||
getNotifications(account: AccountInfo, excludeTypes: ('follow' | 'favourite' | 'reblog' | 'mention' | 'poll' | 'follow_request')[] = 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);
|
||||
|
@ -405,4 +405,18 @@ export class MastodonWrapperService {
|
|||
return this.mastodonService.getFollowers(refreshedAccount, accountId, maxId, sinceId, limit);
|
||||
});
|
||||
}
|
||||
|
||||
authorizeFollowRequest(account: AccountInfo, id: number): Promise<Relationship> {
|
||||
return this.refreshAccountIfNeeded(account)
|
||||
.then((refreshedAccount: AccountInfo) => {
|
||||
return this.mastodonService.authorizeFollowRequest(refreshedAccount, id);
|
||||
});
|
||||
}
|
||||
|
||||
rejectFollowRequest(account: AccountInfo, id: number): Promise<Relationship> {
|
||||
return this.refreshAccountIfNeeded(account)
|
||||
.then((refreshedAccount: AccountInfo) => {
|
||||
return this.mastodonService.rejectFollowRequest(refreshedAccount, id);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -311,7 +311,7 @@ export class MastodonService {
|
|||
return this.httpClient.put<Attachment>(route, input, { headers: headers }).toPromise();
|
||||
}
|
||||
|
||||
getNotifications(account: AccountInfo, excludeTypes: ('follow' | 'favourite' | 'reblog' | 'mention' | 'poll')[] = null, maxId: string = null, sinceId: string = null, limit: number = 15): Promise<Notification[]> {
|
||||
getNotifications(account: AccountInfo, excludeTypes: ('follow' | 'favourite' | 'reblog' | 'mention' | 'poll' | 'follow_request')[] = null, maxId: string = null, sinceId: string = null, limit: number = 15): Promise<Notification[]> {
|
||||
let route = `https://${account.instance}${this.apiRoutes.getNotifications}?limit=${limit}`;
|
||||
|
||||
if (maxId) {
|
||||
|
@ -490,6 +490,7 @@ export class MastodonService {
|
|||
return new FollowingResult(lastId, res.body)
|
||||
});
|
||||
}
|
||||
|
||||
getFollowing(account: AccountInfo, targetAccountId: number, maxId: string, sinceId: string, limit: number = 40): Promise<FollowingResult> {
|
||||
const route = `https://${account.instance}${this.apiRoutes.getFollowing}`.replace('{0}', targetAccountId.toString());
|
||||
|
||||
|
@ -511,6 +512,20 @@ export class MastodonService {
|
|||
return new FollowingResult(lastId, res.body)
|
||||
});
|
||||
}
|
||||
|
||||
authorizeFollowRequest(account: AccountInfo, id: number): Promise<Relationship> {
|
||||
const route = `https://${account.instance}${this.apiRoutes.authorizeFollowRequest}`.replace('{0}', id.toString());
|
||||
|
||||
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
|
||||
return this.httpClient.post<Relationship>(route, null, { headers: headers }).toPromise();
|
||||
}
|
||||
|
||||
rejectFollowRequest(account: AccountInfo, id: number): Promise<Relationship> {
|
||||
const route = `https://${account.instance}${this.apiRoutes.rejectFollowRequest}`.replace('{0}', id.toString());
|
||||
|
||||
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
|
||||
return this.httpClient.post<Relationship>(route, null, { headers: headers }).toPromise();
|
||||
}
|
||||
}
|
||||
|
||||
export enum VisibilityEnum {
|
||||
|
|
|
@ -21,8 +21,8 @@ export class ApiRoutes {
|
|||
getBlocks = '/api/v1/blocks';
|
||||
getFavourites = '/api/v1/favourites';
|
||||
getFollowRequests = '/api/v1/follow_requests';
|
||||
authorizeFollowRequest = '/api/v1/follow_requests/authorize';
|
||||
rejectFollowRequest = '/api/v1/follow_requests/reject';
|
||||
authorizeFollowRequest = '/api/v1/follow_requests/{0}/authorize';
|
||||
rejectFollowRequest = '/api/v1/follow_requests/{0}/reject';
|
||||
followRemote = '/api/v1/follows';
|
||||
getInstance = '/api/v1/instance';
|
||||
uploadMediaAttachment = '/api/v1/media';
|
||||
|
|
|
@ -58,7 +58,7 @@ export class UserNotificationService {
|
|||
}
|
||||
|
||||
private startFetchingNotifications(account: AccountInfo) {
|
||||
let getMentionsPromise = this.mastodonService.getNotifications(account, ['favourite', 'follow', 'reblog', 'poll'], null, null, 10)
|
||||
let getMentionsPromise = this.mastodonService.getNotifications(account, ['favourite', 'follow', 'reblog', 'poll', 'follow_request'], null, null, 10)
|
||||
.then((notifications: Notification[]) => {
|
||||
this.processMentionsAndNotifications(account, notifications, NotificationTypeEnum.UserMention);
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue