aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/service/MessagesService.java
blob: f2321b2afc286615db85307ae068f40a57b597b7 (plain) (blame)
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
/*
 * Copyright (C) 2008-2024, Juick
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.juick.service;

import com.juick.model.Message;
import com.juick.model.Reaction;
import com.juick.model.User;
import com.juick.model.ResponseReply;
import com.juick.model.Tag;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.lang.NonNull;

import java.net.URI;
import java.util.*;

/**
 * Created by aalexeev on 11/13/16.
 */
public interface MessagesService {
    @CacheEvict(value = { "discover", "discussions", "messages", "replies", "stats" }, allEntries = true)
    int createMessage(int uid, String txt, String attachment, @NonNull Set<Tag> tags);

    @CacheEvict(value = { "discover", "discussions", "messages", "replies", "stats" }, allEntries = true)
    int createReply(int mid, int rid, User user, String txt, String attachment);
    enum RecommendStatus {
        Error,
        Added,
        Deleted
    }

    @CacheEvict(value = { "discover", "discussions", "messages", "replies" }, allEntries = true)
    RecommendStatus recommendMessage(int mid, int vuid, String userUri);

    @CacheEvict(value = { "discover", "discussions", "messages", "replies" }, allEntries = true)
    RecommendStatus recommendMessage(int mid, int vuid);

    List<Reaction> listReactions();

    @CacheEvict(value = { "discover", "discussions", "messages", "replies" }, allEntries = true)
    RecommendStatus likeMessage(int mid, int vuid, Integer reaction);

    @CacheEvict(value = { "discover", "discussions", "messages", "replies" }, allEntries = true)
    RecommendStatus likeMessage(int mid, int vuid, Integer reaction, String userUri);


    boolean canViewThread(int mid, int uid);

    boolean isReadOnly(int mid);

    @CacheEvict(value = { "discover", "discussions", "messages", "replies" }, allEntries = true)
    void setReadOnly(int mid, boolean readonly);

    int getMessagePrivacy(int mid);

    Optional<Message> getMessage(int mid);
    Optional<Message> getMessage(int uid, int mid);

    Message getReply(int mid, int rid);

    Message getReplyByUri(String replyUri);

    List<Pair<Integer, User>> getMessagesRecommendations(int visitorUid, Collection<Integer> mids);

    @Cacheable(value = "discover", key="{ #visitorUid, #before }")
    List<Integer> getAll(int visitorUid, int before);

    List<Integer> getTag(int tid, int visitorUid, int before, int cnt);

    List<Integer> getTags(String tids, int visitorUid, int before, int cnt);

    List<Integer> getPlace(int placeId, int visitorUid, int before);

    List<Integer> getMyFeed(int uid, int before, boolean recommended);

    List<Integer> getPrivate(int uid, int before);

    @Cacheable(value = "discussions", key="{ #uid, #to }")
    List<Integer> getDiscussions(int uid, Long to);

    /**
     * Get messages recommended by friends
     * @param uid visitor id
     * @param before
     * @return recommended message ids
     */
    List<Integer> getRecommended(int uid, int before);

    List<Integer> getPhotos(int visitorUid, int before);

    List<Integer> getSearch(User visitor, String search, int page);

    List<Integer> getUserBlog(int uid, int privacy, int before);

    List<Integer> getUserTag(int uid, int tid, int privacy, int before);

    List<Integer> getUserBlogAtDay(int uid, int privacy, int daysback);

    List<Integer> getUserBlogWithRecommendations(User user, User visitor, int privacy, int before);

    List<Integer> getUserRecommendations(int uid, int before);

    List<Integer> getUserPhotos(int uid, int privacy, int before);

    List<Integer> getUserSearch(User visitor, int UID, String search, int privacy, int page);

    @Cacheable(value = "messages", key="{ #uid, #mids.hashCode() }")
    List<Message> getMessages(int uid, List<Integer> mids);
    @Cacheable(value = "replies", key="{ #user.uid, #mid }")
    List<Message> getReplies(User user, int mid);

    boolean setMessagePrivacy(int mid);

    @CacheEvict(value = { "discover", "discussions", "messages", "replies", "stats" }, allEntries = true)
    boolean deleteMessage(int uid, int mid);

    @CacheEvict(value = { "discover", "discussions", "messages", "replies", "stats" }, allEntries = true)
    boolean deleteReply(int uid, int mid, int rid);

    List<Integer> getLastMessages(int hours);

    List<ResponseReply> getLastReplies(int hours);

    List<Integer> getPopularCandidates();

    @CacheEvict(value = { "discover", "discussions", "messages", "replies" }, allEntries = true, condition = "{ #user.uid != 0 }")
    void setLastReadComment(User user, Integer mid, Integer rid);

    @CacheEvict(value = { "discover", "discussions", "messages", "replies" }, allEntries = true, condition = "{ #user.uid != 0 }")
    void setRead(User user, Integer mid);

    List<Integer> getUnread(User user);

    @CacheEvict(value = { "discover", "discussions", "messages", "replies" }, allEntries = true)
    boolean updateMessage(Integer mid, Integer rid, String body, boolean foreign);

    @CacheEvict(value = { "discover", "discussions", "messages", "replies" }, allEntries = true)
    boolean updateReplyUri(Message reply, URI replyUri);

    boolean replyExists(URI replyUri);

    @CacheEvict(value = { "discover", "discussions", "messages", "replies", "stats" }, allEntries = true)
    boolean deleteReply(URI userUri, URI replyUri);

    String getMessageProperty(Integer mid, Integer rid, String key);

    void setMessageProperty(Integer mid, Integer rid, String key, String value);
    Optional<Pair<Integer, Integer>> findMessageByProperty(String key, String value);

    @CacheEvict(value = { "discover", "discussions", "messages", "replies" }, allEntries = true)
    void setFriendsOnly(Integer mid, Boolean friendsOnly);

    Optional<String> renderPlaintext(String body, String messageUrl);

    Optional<String> renderHtml(String body, String messageUrl, Message msg, String hash);
}