Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | 1x 1x 1x 1x 1x 1x 1x 1x | import { TwitarrHTTPOptions } from '../api/TwitarrHTTPOptions';
import { ForumPost } from '../model/ForumPost';
import { ForumResponse } from '../model/ForumResponse';
import { ForumThread } from '../model/ForumThread';
import { ReactionDetail } from '../model/ReactionDetail';
import { ReactionsSummary } from '../model/ReactionsSummary';
import { AbstractDAO } from './AbstractDAO';
interface IAlertCounts {
unnoticed_announcements: number;
unnoticed_alerts: boolean;
seamail_unread_count: number;
unnoticed_mentions: number;
unnoticed_upcoming_events: number;
}
export class ForumDAO extends AbstractDAO {
/**
* Get a list of forum threads.
*/
public async list(page?: number, limit?: number) {
const options = new TwitarrHTTPOptions().withParameter('app', 'plain');
if (page) {
options.parameters.page = '' + page;
}
if (limit) {
options.parameters.limit = '' + limit;
}
return this.http
.get('/api/v2/forums', options)
.then(result => this.handleErrors(result))
.then(data => {
return ForumResponse.fromRest(data);
});
}
/** Create a new thread */
public async create(subject: string, text: string, photos?: string[], as_mod?: boolean) {
const options = new TwitarrHTTPOptions().withParameter('app', 'plain').withData({
subject,
text,
});
if (photos && photos.length > 0) {
options.data.photos = photos;
}
if (as_mod) {
options.data.as_mod = as_mod;
}
return this.http
.post('/api/v2/forums', options)
.then(result => this.handleErrors(result))
.then(data => {
return ForumThread.fromRest(data.forum_thread);
});
}
/** Get a forum thread */
public async get(id: string, page?: number, limit?: number) {
const options = new TwitarrHTTPOptions().withParameter('app', 'plain');
if (page) {
options.parameters.page = '' + page;
}
if (limit) {
options.parameters.limit = '' + limit;
}
return this.http
.get('/api/v2/forums/' + id, options)
.then(result => this.handleErrors(result))
.then(data => {
return ForumThread.fromRest(data.forum_thread);
});
}
/** Post to a forum thread */
public async post(id: string, text: string, photos?: string[], as_mod?: boolean) {
const options = new TwitarrHTTPOptions().withParameter('app', 'plain').withData({
text,
});
if (photos && photos.length > 0) {
options.data.photos = photos;
}
if (as_mod) {
options.data.as_mod = as_mod;
}
return this.http
.post('/api/v2/forums/' + id, options)
.then(result => this.handleErrors(result))
.then(data => {
return ForumPost.fromRest(data.forum_post);
});
}
/** Delete a thread (admin-only) */
public async remove(id: string) {
return this.http
.httpDelete('/api/v2/forum/' + id)
.then(result => this.handleErrors(result))
.then(() => {
return true;
});
}
/** Set sticky status for a thread */
public async sticky(id: string, sticky?: boolean) {
return this.http
.post('/api/v2/forum/' + id + '/sticky/' + (sticky ? true : false))
.then(result => this.handleErrors(result))
.then(data => {
return data.sticky;
});
}
/** Set locked status for a thread */
public async locked(id: string, locked?: boolean) {
return this.http
.post('/api/v2/forum/' + id + '/locked/' + (locked ? true : false))
.then(result => this.handleErrors(result))
.then(data => {
return data.locked;
});
}
/** React to a post */
public async react(threadId: string, postId: string, reaction: string) {
return this.http
.post('/api/v2/forums/' + threadId + '/' + postId + '/react/' + reaction)
.then(result => this.handleErrors(result))
.then(data => {
return ReactionsSummary.fromRest(data.reactions);
});
}
/** React to a post */
public async deleteReact(threadId: string, postId: string, reaction: string) {
return this.http
.httpDelete('/api/v2/forums/' + threadId + '/' + postId + '/react/' + reaction)
.then(result => this.handleErrors(result))
.then(data => {
return ReactionsSummary.fromRest(data.reactions);
});
}
/** Get the list of reactions on a post */
public async reactions(threadId: string, postId: string) {
return this.http
.get('/api/v2/forums/' + threadId + '/' + postId + '/react')
.then(result => this.handleErrors(result))
.then(data => {
return data.reactions.map(reaction => ReactionDetail.fromRest(reaction));
});
}
/** Get an individual thread post */
public async getPost(threadId: string, postId: string) {
const options = new TwitarrHTTPOptions().withParameter('app', 'plain');
return this.http
.get('/api/v2/forums/' + threadId + '/' + postId, options)
.then(result => this.handleErrors(result))
.then(data => {
return ForumPost.fromRest(data.forum_post);
});
}
/** Get an individual thread post */
public async updatePost(threadId: string, postId: string, text?: string, photos?: string[]) {
const options = new TwitarrHTTPOptions().withParameter('app', 'plain').withData({});
if (text) {
options.data.text = text;
}
if (photos && photos.length > 0) {
options.data.photos = photos;
}
return this.http
.post('/api/v2/forums/' + threadId + '/' + postId, options)
.then(result => this.handleErrors(result))
.then(data => {
return ForumPost.fromRest(data.forum_post);
});
}
/** Delete an individual thread post */
public async removePost(threadId: string, postId: string) {
return this.http
.httpDelete('/api/v2/forums/' + threadId + '/' + postId)
.then(result => this.handleErrors(result))
.then(data => {
return data.thread_deleted as boolean;
});
}
}
|