summaryrefslogtreecommitdiffstats
path: root/app/src/main/java/app/fedilab/android/mastodon/client/entities/lemmy/LemmyPost.java
blob: ce42efd44bc1fcb6b9d7221efb6224fc1c24be07 (plain)
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
package app.fedilab.android.mastodon.client.entities.lemmy;
/* Copyright 2023 Thomas Schneider
 *
 * This file is a part of Fedilab
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation; either version 3 of the
 * License, or (at your option) any later version.
 *
 * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 * Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with Fedilab; if not,
 * see <http://www.gnu.org/licenses>. */

import com.google.gson.annotations.SerializedName;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import app.fedilab.android.mastodon.client.entities.api.Account;
import app.fedilab.android.mastodon.client.entities.api.Attachment;
import app.fedilab.android.mastodon.client.entities.api.Status;

public class LemmyPost implements Serializable {

    @SerializedName("post")
    public Post post;
    @SerializedName("comment")
    public Comment comment;
    @SerializedName("creator")
    public Creator creator;
    /*@SerializedName("community")
    public Community community;*/
    @SerializedName("counts")
    public Counts counts;
    @SerializedName("creator_banned_from_community")
    public boolean creator_banned_from_community;
    @SerializedName("saved")
    public boolean saved;
    @SerializedName("read")
    public boolean read;
    @SerializedName("creator_blocked")
    public boolean creator_blocked;
    @SerializedName("unread_comments")
    public int unread_comments;

    public static Status convert(LemmyPost lemmyPost, String instance) {
        Status status = new Status();
        status.id = lemmyPost.comment == null ? lemmyPost.post.id : lemmyPost.comment.id;
        if (lemmyPost.comment != null) {
            status.in_reply_to_id = lemmyPost.comment.post_id;
            status.lemmy_post_id = null;
        } else {
            status.lemmy_post_id = lemmyPost.post.id;
        }
        status.content = lemmyPost.comment == null ? lemmyPost.post.name : lemmyPost.comment.content;
        status.visibility = "public";
        status.created_at = lemmyPost.comment == null ? lemmyPost.post.published : lemmyPost.comment.published;
        status.url = lemmyPost.comment == null ? lemmyPost.post.ap_id : lemmyPost.comment.ap_id;
        status.uri = lemmyPost.comment == null ? lemmyPost.post.ap_id : lemmyPost.comment.ap_id;


        Account account = new Account();
        account.id = lemmyPost.creator.id;
        account.acct = lemmyPost.creator.name + "@" + instance;
        account.username = "@" + lemmyPost.creator.name;
        account.display_name = lemmyPost.creator.name;
        account.avatar = lemmyPost.creator.avatar;
        account.avatar_static = lemmyPost.creator.avatar;
        status.account = account;

        if (lemmyPost.comment == null && lemmyPost.post.thumbnail_url != null) {
            List<Attachment> attachmentList = new ArrayList<>();
            Attachment attachment = new Attachment();
            attachment.type = "image";
            attachment.url = lemmyPost.post.thumbnail_url;
            attachment.preview_url = lemmyPost.post.thumbnail_url;
            if (lemmyPost.post.nsfw) {
                status.sensitive = true;
            }
            attachmentList.add(attachment);
            status.media_attachments = attachmentList;
        } else if (lemmyPost.comment != null && lemmyPost.comment.thumbnail_url != null) {
            List<Attachment> attachmentList = new ArrayList<>();
            Attachment attachment = new Attachment();
            attachment.type = "image";
            attachment.url = lemmyPost.comment.thumbnail_url;
            attachment.preview_url = lemmyPost.comment.thumbnail_url;
            if (lemmyPost.post.nsfw) {
                status.sensitive = true;
            }
            attachmentList.add(attachment);
            status.media_attachments = attachmentList;
        }
        return status;
    }

    public static class LemmyPosts {
        @SerializedName("posts")
        public List<LemmyPost> posts;
    }

    public static class LemmyComments {
        @SerializedName("comments")
        public List<LemmyPost> comments;
    }

    public static class Post implements Serializable {
        @SerializedName("id")
        public String id;
        @SerializedName("name")
        public String name;
        @SerializedName("body")
        public String body;
        @SerializedName("creator_id")
        public String creator_id;
        @SerializedName("community_id")
        public String community_id;
        @SerializedName("removed")
        public boolean removed;
        @SerializedName("locked")
        public boolean locked;
        @SerializedName("published")
        public Date published;
        @SerializedName("updated")
        public Date updated;
        @SerializedName("deleted")
        public boolean deleted;
        @SerializedName("nsfw")
        public boolean nsfw;
        @SerializedName("thumbnail_url")
        public String thumbnail_url;

        @SerializedName("ap_id")
        public String ap_id;
        @SerializedName("local")
        public boolean local;
        @SerializedName("language_id")
        public String language_id;
        @SerializedName("featured_community")
        public boolean featured_community;
        @SerializedName("featured_local")
        public boolean featured_local;
    }

    public static class Comment implements Serializable {
        @SerializedName("id")
        public String id;
        @SerializedName("creator_id")
        public String creator_id;
        @SerializedName("post_id")
        public String post_id;
        @SerializedName("content")
        public String content;
        @SerializedName("removed")
        public boolean removed;
        @SerializedName("published")
        public Date published;
        @SerializedName("thumbnail_url")
        public String thumbnail_url;
        @SerializedName("deleted")
        public boolean deleted;
        @SerializedName("ap_id")
        public String ap_id;
        @SerializedName("local")
        public boolean local;
        @SerializedName("path")
        public String path;
        @SerializedName("distinguished")
        public boolean distinguished;
        @SerializedName("language_id")
        public String language_id;
    }

    public static class Community implements Serializable {
        @SerializedName("id")
        public String id;
        @SerializedName("name")
        public String name;
        @SerializedName("title")
        public String title;
        @SerializedName("description")
        public String description;
        @SerializedName("removed")
        public boolean removed;
        @SerializedName("published")
        public Date published;
        @SerializedName("updated")
        public Date updated;
        @SerializedName("deleted")
        public boolean deleted;
        @SerializedName("nsfw")
        public boolean nsfw;
        @SerializedName("actor_id")
        public String actor_id;
        @SerializedName("local")
        public boolean local;
        @SerializedName("icon")
        public String icon;
        @SerializedName("hidden")
        public boolean hidden;
        @SerializedName("posting_restricted_to_mods")
        public boolean posting_restricted_to_mods;
        @SerializedName("instance_id")
        public String instance_id;
    }

    public static class Creator implements Serializable {
        @SerializedName("id")
        public String id;
        @SerializedName("name")
        public String name;
        @SerializedName("avatar")
        public String avatar;
        @SerializedName("banned")
        public boolean banned;
        @SerializedName("published")
        public Date published;
        @SerializedName("actor_id")
        public String actor_id;
        @SerializedName("bio")
        public String