diff options
author | Vitaly Takmazov | 2018-11-08 21:38:27 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-11-08 21:38:27 +0300 |
commit | 7aaa3f9a29c280f01c677c918932620be45cdbd7 (patch) | |
tree | 39947b2c889afd08f9c73ba54fab91159d2af258 /juick-common | |
parent | 3ea9770d0d43fbe45449ac4531ec4b0a374d98ea (diff) |
Merge everything into single Spring Boot application
Diffstat (limited to 'juick-common')
61 files changed, 0 insertions, 4009 deletions
diff --git a/juick-common/build.gradle b/juick-common/build.gradle deleted file mode 100644 index 8b26a887..00000000 --- a/juick-common/build.gradle +++ /dev/null @@ -1,20 +0,0 @@ -apply plugin: 'java' - -dependencies { - compile("org.springframework.boot:spring-boot-starter-json") - compile "org.apache.commons:commons-lang3:3.8.1" - compile "org.apache.commons:commons-collections4:4.2" - compile 'org.apache.commons:commons-text:1.6' - compile "commons-codec:commons-codec:1.11" - compile "commons-io:commons-io:2.6" - compile 'com.google.code.findbugs:jsr305:3.0.2' - compile 'org.ocpsoft.prettytime:prettytime:4.0.2.Final' - compile 'org.imgscalr:imgscalr-lib:4.2' - compile "org.apache.commons:commons-imaging:1.0-SNAPSHOT" - runtime "commons-fileupload:commons-fileupload:1.3.3" - - compile "javax.inject:javax.inject:1" - compile "javax.xml.bind:jaxb-api:2.3.1" - compile 'org.glassfish.jaxb:jaxb-runtime:2.3.1' - testCompile("org.springframework.boot:spring-boot-starter-test") -} diff --git a/juick-common/src/main/java/com/juick/Attachment.java b/juick-common/src/main/java/com/juick/Attachment.java deleted file mode 100644 index 76f2995a..00000000 --- a/juick-common/src/main/java/com/juick/Attachment.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.juick; - -public class Attachment { - private String url; - private Integer height; - private Integer width; - private Attachment small; - private Attachment medium; - private Attachment thumbnail; - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public Integer getHeight() { - return height; - } - - public void setHeight(Integer height) { - this.height = height; - } - - public Integer getWidth() { - return width; - } - - public void setWidth(Integer width) { - this.width = width; - } - - public Attachment getSmall() { - return small; - } - - public void setSmall(Attachment small) { - this.small = small; - } - - public Attachment getMedium() { - return medium; - } - - public void setMedium(Attachment medium) { - this.medium = medium; - } - - public Attachment getThumbnail() { - return thumbnail; - } - - public void setThumbnail(Attachment thumbnail) { - this.thumbnail = thumbnail; - } -} diff --git a/juick-common/src/main/java/com/juick/Chat.java b/juick-common/src/main/java/com/juick/Chat.java deleted file mode 100644 index 59c0a2dc..00000000 --- a/juick-common/src/main/java/com/juick/Chat.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.juick; - -import com.fasterxml.jackson.annotation.JsonFormat; - -import java.time.Instant; - -public class Chat extends User { - private Instant lastMessageTimestamp; - private String lastMessageText; - - public Instant getLastMessageTimestamp() { - return lastMessageTimestamp; - } - - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "UTC") - public void setLastMessageTimestamp(Instant lastMessageTimestamp) { - this.lastMessageTimestamp = lastMessageTimestamp; - } - - public String getLastMessageText() { - return lastMessageText; - } - - public void setLastMessageText(String lastMessageText) { - this.lastMessageText = lastMessageText; - } -} diff --git a/juick-common/src/main/java/com/juick/ExternalToken.java b/juick-common/src/main/java/com/juick/ExternalToken.java deleted file mode 100644 index f6094478..00000000 --- a/juick-common/src/main/java/com/juick/ExternalToken.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Created by vitalyster on 22.11.2016. - */ -public class ExternalToken { - private String name; - private String type; - private String token; - private String secret; - - @JsonCreator - public ExternalToken(@JsonProperty("name") String name, - @JsonProperty("type") String type, - @JsonProperty("token") String token, - @JsonProperty("secret") String secret) { - this.name = name; - this.type = type; - this.token = token; - this.secret = secret; - if (this.type == null) { - throw new IllegalStateException("Token must have type"); - } - if (this.token == null) { - throw new IllegalStateException("Token must have value"); - } - } - - public String getType() { - return type; - } - - public String getToken() { - return token; - } - - public String getName() { - return name; - } - - public String getSecret() { - return secret; - } -} diff --git a/juick-common/src/main/java/com/juick/Message.java b/juick-common/src/main/java/com/juick/Message.java deleted file mode 100644 index bd2c91b5..00000000 --- a/juick-common/src/main/java/com/juick/Message.java +++ /dev/null @@ -1,378 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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; - -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.juick.adapters.SimpleDateAdapter; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.builder.ToStringBuilder; - -import javax.xml.bind.annotation.*; -import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import java.net.URI; -import java.time.Instant; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Set; - -/** - * @author Ugnich Anton - */ -@XmlRootElement(name = "juick", namespace = "http://juick.com/message") -@XmlAccessorType() -public class Message implements Comparable { - private int mid = 0; - private int rid = 0; - private int replyto = 0; - private String text = null; - private User user = null; - private final List<Tag> tags; - private Instant ts; - private Instant updated; - private Instant updatedAt; - private boolean unread; - @JsonIgnore - private int privacy = 1; - @XmlTransient - @JsonIgnore - public boolean FriendsOnly = false; - @XmlTransient - @JsonIgnore - public boolean ReadOnly = false; - @XmlTransient - @JsonIgnore - public boolean Hidden = false; - @JsonIgnore - @XmlTransient - public boolean VisitorCanComment = true; - private int replies = 0; - private String repliesBy; - private String attachmentType; - @XmlTransient - private Photo photo; - @XmlTransient - private Attachment attachment; - private int likes; - private User to; - private String replyQuote; - @XmlTransient - private Set<Reaction> reactions; - private boolean service; - private URI replyUri; - private URI replyToUri; - private boolean html; - - private Set<String> recommendations; - - public Message() { - tags = new ArrayList<>(); - reactions = new HashSet<>(); - } - - @Override - public String toString() { - return new ToStringBuilder(this) - .append("mid", mid) - .append("rid", rid) - .append("replyto", replyto) - .append("privacy", privacy) - .append("FriendsOnly", FriendsOnly) - .append("ReadOnly", ReadOnly) - .append("Hidden", Hidden) - .append("VisitorCanComment", VisitorCanComment) - .append("replies", replies) - .append("likes", likes) - .append("reactions", reactions) - .toString(); - } - - @Override - public boolean equals(Object obj) { - if (obj == this) - return true; - - if (!(obj instanceof Message)) - return false; - - Message jmsg = (Message) obj; - return (this.getMid() == jmsg.getMid() && this.getRid() == jmsg.getRid()); - } - - @Override - public int compareTo(Object obj) throws ClassCastException { - if (obj == this) - return 0; - - if (!(obj instanceof Message)) - throw new ClassCastException(); - - Message jmsg = (Message) obj; - - int cmp = Integer.compare(jmsg.getMid(), getMid()); - - if (cmp == 0) - cmp = Integer.compare(getRid(), jmsg.getRid()); - - return cmp; - } - - @JsonProperty("mid") - @XmlAttribute(name = "mid") - public int getMid() { - return mid; - } - - public void setMid(int mid) { - this.mid = mid; - } - - @JsonProperty("rid") - @XmlAttribute(name = "rid") - public int getRid() { - return rid; - } - - public void setRid(int rid) { - this.rid = rid; - } - - @XmlElement(name = "user", namespace = "http://juick.com/user") - public com.juick.User getUser() { - return user; - } - - public void setUser(com.juick.User user) { - this.user = user; - } - - @JsonProperty("body") - @XmlElement(name = "body") - public String getText() { - return text; - } - - public void setText(String text) { - this.text = text; - } - - @JsonProperty("timestamp") - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "UTC") - @XmlAttribute(name = "ts") - @XmlJavaTypeAdapter(SimpleDateAdapter.class) - public Instant getTimestamp() { - return ts; - } - - public void setTimestamp(Instant timestamp) { - this.ts = timestamp; - } - - @XmlElement(name = "to", namespace = "http://juick.com/user") - public User getTo() { - return to; - } - - public void setTo(User to) { - this.to = to; - } - - @XmlAttribute(name = "quote") - public String getReplyQuote() { - return replyQuote; - } - - public void setReplyQuote(String quote) { - replyQuote = quote; - } - - @JsonProperty("replyto") - @XmlAttribute(name = "replyto") - public int getReplyto() { - return replyto; - } - - public void setReplyto(int replyto) { - this.replyto = replyto; - } - - @JsonProperty("tags") - @XmlElement(name = "tag") - public List<Tag> getTags() { - return tags; - } - - public void setTags(List<Tag> tags) { - this.tags.clear(); - if (CollectionUtils.isNotEmpty(tags)) - this.tags.addAll(tags); - } - - @XmlAttribute - public int getPrivacy() { - return privacy; - } - - public void setPrivacy(int privacy) { - this.privacy = privacy; - } - - public Photo getPhoto() { - return photo; - } - - public void setPhoto(Photo photo) { - this.photo = photo; - } - - @XmlAttribute(name = "attach") - @JsonProperty("attach") - public String getAttachmentType() { - return attachmentType; - } - - public void setAttachmentType(String attachmentType) { - this.attachmentType = attachmentType; - } - - @XmlTransient - public int getReplies() { - return replies; - } - - public void setReplies(int replies) { - this.replies = replies; - } - - @XmlTransient - public int getLikes() { - return likes; - } - - public void setLikes(int likes) { - this.likes = likes; - } - - @JsonProperty("repliesby") - public String getRepliesBy() { - return repliesBy; - } - - public void setRepliesBy(String repliesBy) { - this.repliesBy = repliesBy; - } - - public Attachment getAttachment() { - return attachment; - } - public void setAttachment(Attachment attachment) { - this.attachment = attachment; - } - - /** - * @return timestamp of the last comment - */ - @XmlTransient - public Instant getUpdated() { - return updated; - } - - public void setUpdated(Instant updated) { - this.updated = updated; - } - - @XmlTransient - public boolean isUnread() { - return unread; - } - - public void setUnread(boolean unread) { - this.unread = unread; - } - - - @XmlTransient - public Set<Reaction> getReactions() { - return reactions; - } - - public void setReactions(Set<Reaction> reactions) { - this.reactions = reactions; - } - - @Override - public int hashCode() { - return Objects.hash(mid, rid); - } - - public boolean isService() { - return service; - } - - public void setService(boolean service) { - this.service = service; - } - - public Set<String> getRecommendations() { - return recommendations; - } - - public void setRecommendations(Set<String> recommendations) { - this.recommendations = recommendations; - } - - /** - * @return timestamp of the last edit - */ - @XmlTransient - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "UTC") - @JsonProperty("updated_at") - public Instant getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(Instant updatedAt) { - this.updatedAt = updatedAt; - } - - public URI getReplyUri() { - return replyUri; - } - - public void setReplyUri(URI replyUri) { - this.replyUri = replyUri; - } - - public boolean isHtml() { - return html; - } - - public void setHtml(boolean html) { - this.html = html; - } - - public URI getReplyToUri() { - return replyToUri; - } - - public void setReplyToUri(URI replyToUri) { - this.replyToUri = replyToUri; - } -} diff --git a/juick-common/src/main/java/com/juick/Photo.java b/juick-common/src/main/java/com/juick/Photo.java deleted file mode 100644 index 06299610..00000000 --- a/juick-common/src/main/java/com/juick/Photo.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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; - -/** - * Created by vitalyster on 30.11.2016. - */ -// used for compatibility -@Deprecated -public class Photo { - private String small; - private String medium; - private String thumbnail; - - public String getSmall() { - return small; - } - - public void setSmall(String small) { - this.small = small; - } - - public String getMedium() { - return medium; - } - - public void setMedium(String medium) { - this.medium = medium; - } - - public String getThumbnail() { - return thumbnail; - } - - public void setThumbnail(String thumbnail) { - this.thumbnail = thumbnail; - } -} diff --git a/juick-common/src/main/java/com/juick/Reaction.java b/juick-common/src/main/java/com/juick/Reaction.java deleted file mode 100644 index 536ac241..00000000 --- a/juick-common/src/main/java/com/juick/Reaction.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.juick; - -import org.apache.commons.lang3.builder.ToStringBuilder; - -public class Reaction { - - public static final int LIKE = 1; - - private final int id; - private String description; - private int count; - - public Reaction(int id) { - this.id = id; - } - - @Override - public String toString() { - return new ToStringBuilder(this) - .append("id", getId()) - .append("description", description) - .append("count", count) - .build(); - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public int getCount() { - return count; - } - - public void setCount(int count) { - this.count = count; - } - - public int getId() { - return id; - } -} diff --git a/juick-common/src/main/java/com/juick/Status.java b/juick-common/src/main/java/com/juick/Status.java deleted file mode 100644 index d7983536..00000000 --- a/juick-common/src/main/java/com/juick/Status.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Created by vitalyster on 25.07.2016. - */ -public class Status { - private final String value; - - public static final Status OK = new Status("ok"); - public static final Status FAIL = new Status("Fail"); - public static final Status ERROR = new Status("Error"); - - public static Status getStatus(final String stringStatus) { - return new Status(stringStatus); - } - - private Status(String value) { - this.value = value; - } - - @JsonProperty("status") - public String getValue() { - return value; - } - - @Override - public String toString() { - return "value = " + value; - } -} diff --git a/juick-common/src/main/java/com/juick/Tag.java b/juick-common/src/main/java/com/juick/Tag.java deleted file mode 100644 index b93d0e76..00000000 --- a/juick-common/src/main/java/com/juick/Tag.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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; - -import com.fasterxml.jackson.annotation.JsonValue; - -import javax.xml.bind.annotation.*; -import java.util.Comparator; -import java.util.Objects; - -/** - * @author Ugnich Anton - */ -@XmlRootElement(name = "tag", namespace = "http://juick.com/message") -@XmlAccessorType(XmlAccessType.FIELD) -public class Tag implements Comparable<Tag> { - @XmlValue - private String name; - - @XmlTransient - public int TID = 0; - @XmlTransient - public int SynonymID = 0; - - public Tag() { - // required for (de)serialization - } - - public Tag(String name) { - this.name = name; - } - - @Override - public boolean equals(Object o) { - return o == this || - (o instanceof Tag) && Objects.equals(name, ((Tag) o).name); - } - - @XmlTransient - @JsonValue - public String getName() { - return name; - } - - @Override - public int hashCode() { - return Objects.hash(name); - } - - @Override - public String toString() { - return name; - } - - @Override - public int compareTo(Tag o) { - return Objects.compare(name, o.getName(), Comparator.naturalOrder()); - } -} diff --git a/juick-common/src/main/java/com/juick/User.java b/juick-common/src/main/java/com/juick/User.java deleted file mode 100644 index e2e45122..00000000 --- a/juick-common/src/main/java/com/juick/User.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.builder.ToStringBuilder; - -import javax.annotation.Nonnull; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import java.net.URI; -import java.time.Instant; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -/** - * @author Ugnich Anton - */ -@XmlRootElement(name = "user", namespace = "http://juick.com/user") -@XmlAccessorType() -public class User { - private int uid; - private String name; - private Object avatar; - private String fullName; - private int messagesCount; - private String authHash; - private boolean banned; - private String credentials; - private List<ExternalToken> tokens; - private List<User> read; - private List<User> readers; - private List<Integer> unread; - private URI uri; - private Instant seen; - - public User() { - tokens = new ArrayList<>(); - uri = URI.create(StringUtils.EMPTY); - } - - @Override - public boolean equals(Object obj) { - return obj == this || - (obj instanceof User && ((User) obj).getUid() == this.getUid()); - } - - @Override - public int hashCode() { - return Objects.hash(uid); - } - - @Override - public String toString() { - return new ToStringBuilder(this) - .append("uid", uid) - .append("name", name) - .append("fullName", fullName) - .append("messagesCount", messagesCount) - .append("banned", banned) - .toString(); - } - - @JsonProperty("uid") - @XmlAttribute(name = "uid") - public int getUid() { - return uid; - } - - public void setUid(int uid) { - this.uid = uid; - } - - @JsonProperty("uname") - @XmlAttribute(name = "uname") - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @JsonProperty("fullname") - @XmlTransient - public String getFullName() { - return fullName; - } - - public void setFullName(String fullName) { - this.fullName = fullName; - } - - @XmlTransient - @JsonIgnore - public String getAuthHash() { - return authHash; - } - - public void setAuthHash(String authHash) { - this.authHash = authHash; - } - - @JsonProperty("unreadCount") - @XmlTransient - public Integer getUnreadCount() { - return messagesCount; - } - - public void setUnreadCount(Integer count) { - this.messagesCount = count; - } - - @XmlTransient - public boolean isBanned() { - return banned; - } - - public void setBanned(boolean banned) { - this.banned = banned; - } - - public Object getAvatar() { - return avatar; - } - - public void setAvatar(Object avatar) { - this.avatar = avatar; - } - - @XmlTransient - @JsonIgnore - public String getCredentials() { - return credentials; - } - - public void setCredentials(String credentials) { - this.credentials = credentials; - } - - @XmlTransient - public int getMessagesCount() { - return messagesCount; - } - - public void setMessagesCount(int messagesCount) { - this.messagesCount = messagesCount; - } - - @XmlTransient - @JsonIgnore - public boolean isAnonymous() { - return false; - } - - @Nonnull - public List<ExternalToken> getTokens() { - return tokens; - } - - public void setTokens(List<ExternalToken> tokens) { - this.tokens = tokens; - } - - public List<User> getRead() { - return read; - } - public List<User> getReaders() { - return readers; - } - - public void setRead(List<User> read) { - this.read = read; - } - - public void setReaders(List<User> readers) { - this.readers = readers; - } - - public List<Integer> getUnread() { - return unread; - } - - public void setUnread(List<Integer> unread) { - this.unread = unread; - } - - @Nonnull - public URI getUri() { - if (uri == null) { - uri = URI.create(StringUtils.EMPTY); - } - return uri; - } - - public void setUri(URI uri) { - this.uri = uri; - } - - public Instant getSeen() { - return seen; - } - - public void setSeen(Instant seen) { - this.seen = seen; - } -} diff --git a/juick-common/src/main/java/com/juick/adapters/SimpleDateAdapter.java b/juick-common/src/main/java/com/juick/adapters/SimpleDateAdapter.java deleted file mode 100644 index b8e08599..00000000 --- a/juick-common/src/main/java/com/juick/adapters/SimpleDateAdapter.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.adapters; - -import com.juick.util.DateFormattersHolder; - -import javax.xml.bind.annotation.adapters.XmlAdapter; -import java.time.Instant; - -/** - * Created by vitalyster on 15.11.2016. - */ - -public class SimpleDateAdapter extends XmlAdapter<String, Instant> { - - @Override - public String marshal(Instant v) throws Exception { - return DateFormattersHolder.getMessageFormatterInstance().format(v); - } - - @Override - public Instant unmarshal(String v) throws Exception { - return DateFormattersHolder.getMessageFormatterInstance().parse(v); - } -} diff --git a/juick-common/src/main/java/com/juick/formatters/PlainTextFormatter.java b/juick-common/src/main/java/com/juick/formatters/PlainTextFormatter.java deleted file mode 100644 index 378a523f..00000000 --- a/juick-common/src/main/java/com/juick/formatters/PlainTextFormatter.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.formatters; - -import com.juick.Message; -import com.juick.util.MessageUtils; -import org.apache.commons.lang3.StringUtils; -import org.ocpsoft.prettytime.PrettyTime; - -import java.util.Date; -import java.util.Locale; - -/** - * Created by vitalyster on 12.10.2016. - */ -public class PlainTextFormatter { - static PrettyTime pt = new PrettyTime(new Locale("en")); - - public static String formatPost(Message jmsg) { - return formatPost(jmsg, false); - } - - public static String formatPost(Message jmsg, boolean markdown) { - StringBuilder sb = new StringBuilder(); - String title = MessageUtils.isReply(jmsg) ? "Reply by @" : MessageUtils.isPM(jmsg) ? "Private message from @" : "@"; - String subtitle = MessageUtils.isReply(jmsg) ? markdown ? MessageUtils.escapeMarkdown(StringUtils.defaultString(jmsg.getReplyQuote())) - : jmsg.getReplyQuote() - : markdown ? MessageUtils.getMarkdownTags(jmsg) : MessageUtils.getTagsString(jmsg); - sb.append(title).append(markdown ? MessageUtils.getMarkdownUser(jmsg.getUser()) : jmsg.getUser().getName()).append(":\n") - .append(subtitle).append("\n"); - if (markdown) { - sb.append(MessageUtils.formatMarkdownText(jmsg)); - } else { - sb.append(StringUtils.defaultString(jmsg.getText())); - } - sb.append("\n"); - if (!markdown && StringUtils.isNotEmpty(jmsg.getAttachmentType())) { - sb.append(MessageUtils.attachmentUrl(jmsg)); - } - return sb.toString(); - } - - public static String formatPostSummary(Message m) { - int cropLength = 384; - String timeAgo = pt.format(Date.from(m.getTimestamp())); - String repliesCount = m.getReplies() == 1 ? "; 1 reply" : m.getReplies() == 0 ? "" - : String.format("; %d replies", m.getReplies()); - StringBuilder sb = new StringBuilder(); - String txt = StringUtils.defaultString(m.getText()); - String attachmentUrl = MessageUtils.attachmentUrl(m); - if (StringUtils.isNotEmpty(attachmentUrl)) { - sb.append(attachmentUrl).append("\n"); - } - if (txt.length() >= cropLength) { - sb.append(StringUtils.substring(txt, 0, cropLength)).append(" [...]"); - } else { - sb.append(txt); - } - return String.format("@%s:%s\n%s\n#%s (%s%s) %s", - m.getUser().getName(), MessageUtils.getTagsString(m), sb.toString(), formatPostNumber(m), timeAgo, repliesCount, formatUrl(m)); - } - - public static String formatUrl(com.juick.Message jmsg) { - if (MessageUtils.isReply(jmsg)) { - return String.format("https://juick.com/m/%d#%d", jmsg.getMid(), jmsg.getRid()); - } else if (MessageUtils.isPM(jmsg)) { - return "https://juick.com/pm/inbox"; - } - return "https://juick.com/m/" + jmsg.getMid(); - } - - public static String formatPostNumber(com.juick.Message jmsg) { - if (jmsg.getRid() > 0) { - return String.format("%d/%d", jmsg.getMid(), jmsg.getRid()); - } - return String.format("%d", jmsg.getMid()); - } - - public static String formatTwitterCard(Message jmsg) { - return MessageUtils.getMessageHashTags(jmsg) + StringUtils.defaultString(jmsg.getText()); - } -} diff --git a/juick-common/src/main/java/com/juick/model/AnonymousUser.java b/juick-common/src/main/java/com/juick/model/AnonymousUser.java deleted file mode 100644 index f4511194..00000000 --- a/juick-common/src/main/java/com/juick/model/AnonymousUser.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.model; - -import com.juick.User; - -/** - * Created by aalexeev on 12/11/16. - */ -public final class AnonymousUser extends User { - public static final AnonymousUser INSTANCE = new AnonymousUser(); - - private AnonymousUser() { - super.setUid(getUid()); - super.setName(getName()); - super.setAvatar(getAvatar()); - super.setFullName(getFullName()); - super.setMessagesCount(getMessagesCount()); - super.setAuthHash(getAuthHash()); - super.setBanned(isBanned()); - super.setCredentials(getCredentials()); - } - - @Override - public boolean equals(Object obj) { - return obj == this || obj instanceof AnonymousUser; - } - - @Override - public int getUid() { - return 0; - } - - @Override - public String getName() { - return "Anonymous"; - } - - @Override - public String getFullName() { - return getName(); - } - - @Override - public String getAuthHash() { - return null; - } - - @Override - public Integer getUnreadCount() { - return 0; - } - - @Override - public boolean isBanned() { - return false; - } - - @Override - public Object getAvatar() { - return null; - } - - @Override - public String getCredentials() { - return null; - } - - @Override - public int getMessagesCount() { - return 0; - } - - @Override - public boolean isAnonymous() { - return true; - } - - @Override - public void setUid(int uid) { - } - - @Override - public void setName(String name) { - } - - @Override - public void setFullName(String fullName) { - } - - @Override - public void setAuthHash(String authHash) { - } - - @Override - public void setUnreadCount(Integer count) { - } - - @Override - public void setBanned(boolean banned) { - } - - @Override - public void setAvatar(Object avatar) { - } - - @Override - public void setCredentials(String credentials) { - } - - @Override - public void setMessagesCount(int messagesCount) { - } -} diff --git a/juick-common/src/main/java/com/juick/model/ApplicationStatus.java b/juick-common/src/main/java/com/juick/model/ApplicationStatus.java deleted file mode 100644 index b18e12bf..00000000 --- a/juick-common/src/main/java/com/juick/model/ApplicationStatus.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.model; - -import org.apache.commons.lang3.builder.ToStringBuilder; - -/** - * Created by vt on 03/09/16. - */ -public class ApplicationStatus { - private boolean connected; - private boolean crosspostEnabled; - - @Override - public String toString() { - return new ToStringBuilder(this) - .append("connected", connected) - .append("crosspostEnabled", crosspostEnabled) - .toString(); - } - - public boolean isConnected() { - return connected; - } - - public void setConnected(boolean connected) { - this.connected = connected; - } - - public boolean isCrosspostEnabled() { - return crosspostEnabled; - } - - public void setCrosspostEnabled(boolean crosspostEnabled) { - this.crosspostEnabled = crosspostEnabled; - } -} diff --git a/juick-common/src/main/java/com/juick/model/Auth.java b/juick-common/src/main/java/com/juick/model/Auth.java deleted file mode 100644 index 66125567..00000000 --- a/juick-common/src/main/java/com/juick/model/Auth.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.model; - -/** - * Created by vt on 09/02/16. - */ -public class Auth { - private String account; - private String authCode; - - public Auth(String account, String authCode) { - this.account = account; - this.authCode = authCode; - } - - public String getAccount() { - return account; - } - - public String getAuthCode() { - return authCode; - } -}
\ No newline at end of file diff --git a/juick-common/src/main/java/com/juick/model/CommandResult.java b/juick-common/src/main/java/com/juick/model/CommandResult.java deleted file mode 100644 index c310756c..00000000 --- a/juick-common/src/main/java/com/juick/model/CommandResult.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.juick.model; - -import com.juick.Message; - -import java.util.Optional; - -public class CommandResult { - private String text; - private String markdown; - private Message newMessage; - - public String getText() { - return text; - } - public String getMarkdown() { - return markdown; - } - - public Optional<Message> getNewMessage() { - return Optional.ofNullable(newMessage); - } - public static CommandResult build(Message newMessage, String text, String markdown) { - CommandResult result = new CommandResult(); - result.newMessage = newMessage; - result.text = text; - result.markdown = markdown; - return result; - } - public static CommandResult fromString(String text) { - CommandResult result = new CommandResult(); - result.text = text; - return result; - } - -} diff --git a/juick-common/src/main/java/com/juick/model/NotifyOpts.java b/juick-common/src/main/java/com/juick/model/NotifyOpts.java deleted file mode 100644 index 1c0e0aac..00000000 --- a/juick-common/src/main/java/com/juick/model/NotifyOpts.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.model; - -/** - * Created by vt on 03/09/16. - */ -public class NotifyOpts { - private boolean repliesEnabled; - private boolean subscriptionsEnabled; - private boolean recommendationsEnabled; - - public boolean isRepliesEnabled() { - return repliesEnabled; - } - - public void setRepliesEnabled(boolean repliesEnabled) { - this.repliesEnabled = repliesEnabled; - } - - public boolean isSubscriptionsEnabled() { - return subscriptionsEnabled; - } - - public void setSubscriptionsEnabled(boolean subscriptionsEnabled) { - this.subscriptionsEnabled = subscriptionsEnabled; - } - - public boolean isRecommendationsEnabled() { - return recommendationsEnabled; - } - - public void setRecommendationsEnabled(boolean recommendationsEnabled) { - this.recommendationsEnabled = recommendationsEnabled; - } -} diff --git a/juick-common/src/main/java/com/juick/model/PrivacyOpts.java b/juick-common/src/main/java/com/juick/model/PrivacyOpts.java deleted file mode 100644 index 52cbe588..00000000 --- a/juick-common/src/main/java/com/juick/model/PrivacyOpts.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.model; - -/** - * Created by vt on 16/01/16. - */ -public class PrivacyOpts { - private int uid; - private int privacy; - - public PrivacyOpts() { - - } - - public int getUid() { - return uid; - } - - public void setUid(int uid) { - this.uid = uid; - } - - public int getPrivacy() { - return privacy; - } - - public void setPrivacy(int privacy) { - this.privacy = privacy; - } -} diff --git a/juick-common/src/main/java/com/juick/model/PrivateChats.java b/juick-common/src/main/java/com/juick/model/PrivateChats.java deleted file mode 100644 index b6bb48ab..00000000 --- a/juick-common/src/main/java/com/juick/model/PrivateChats.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.model; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.juick.Chat; - -import java.util.List; - -/** - * Created by vt on 24/11/2016. - */ -public class PrivateChats { - private List<Chat> users; - - @JsonProperty("pms") - public List<Chat> getUsers() { - return users; - } - - public void setUsers(List<Chat> users) { - this.users = users; - } -} diff --git a/juick-common/src/main/java/com/juick/model/ResponseReply.java b/juick-common/src/main/java/com/juick/model/ResponseReply.java deleted file mode 100644 index 183c6f72..00000000 --- a/juick-common/src/main/java/com/juick/model/ResponseReply.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.model; - -import java.util.Date; - -/** - * Created by vitalyster on 13.12.2016. - */ -public class ResponseReply { - private String muname; - private int mid; - private int rid; - private String uname; - private String description; - private Date pubDate; - private String attachmentType; - private boolean html; - - public String getMuname() { - return muname; - } - - public void setMuname(String muname) { - this.muname = muname; - } - - public int getMid() { - return mid; - } - - public void setMid(int mid) { - this.mid = mid; - } - - public int getRid() { - return rid; - } - - public void setRid(int rid) { - this.rid = rid; - } - - public String getUname() { - return uname; - } - - public void setUname(String uname) { - this.uname = uname; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Date getPubDate() { - return pubDate; - } - - public void setPubDate(Date pubDate) { - this.pubDate = pubDate; - } - - public String getAttachmentType() { - return attachmentType; - } - - public void setAttachmentType(String attachmentType) { - this.attachmentType = attachmentType; - } - - public boolean isHtml() { - return html; - } - - public void setHtml(boolean html) { - this.html = html; - } -} diff --git a/juick-common/src/main/java/com/juick/model/TagStats.java b/juick-common/src/main/java/com/juick/model/TagStats.java deleted file mode 100644 index da2f3f92..00000000 --- a/juick-common/src/main/java/com/juick/model/TagStats.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.model; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.juick.Tag; - -/** - * Created by vitalyster on 01.12.2016. - */ -public class TagStats { - private Tag tag; - private int usageCount; - - public Tag getTag() { - return tag; - } - - public void setTag(Tag tag) { - this.tag = tag; - } - - @JsonProperty("messages") - public int getUsageCount() { - return usageCount; - } - - public void setUsageCount(int usageCount) { - this.usageCount = usageCount; - } -} diff --git a/juick-common/src/main/java/com/juick/model/UserInfo.java b/juick-common/src/main/java/com/juick/model/UserInfo.java deleted file mode 100644 index ca5d75e0..00000000 --- a/juick-common/src/main/java/com/juick/model/UserInfo.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.model; - -/** - * Created by vt on 03/09/16. - */ -public class UserInfo { - private String fullName; - private String country; - private String url; - private String description; - - public String getFullName() { - return fullName; - } - - public void setFullName(String fullName) { - this.fullName = fullName; - } - - public String getCountry() { - return country; - } - - public void setCountry(String country) { - this.country = country; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } -} diff --git a/juick-common/src/main/java/com/juick/model/facebook/User.java b/juick-common/src/main/java/com/juick/model/facebook/User.java deleted file mode 100644 index 80838de6..00000000 --- a/juick-common/src/main/java/com/juick/model/facebook/User.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.model.facebook; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Created by vitalyster on 28.11.2016. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class User { - private String id; - private String name; - private String link; - private boolean verified; - private String firstName; - private String lastName; - private String gender; - private String locale; - private String timezone; - private String updatedTime; - private String email; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getLink() { - return link; - } - - public void setLink(String link) { - this.link = link; - } - - public boolean getVerified() { - return verified; - } - - public void setVerified(boolean verified) { - this.verified = verified; - } - - @JsonProperty("first_name") - public String getFirstName() { - return firstName; - } - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getGender() { - return gender; - } - - public void setGender(String gender) { - this.gender = gender; - } - - @JsonProperty("last_name") - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getLocale() { - return locale; - } - - public void setLocale(String locale) { - this.locale = locale; - } - - public String getTimezone() { - return timezone; - } - - public void setTimezone(String timezone) { - this.timezone = timezone; - } - - @JsonProperty("updated_time") - public String getUpdatedTime() { - return updatedTime; - } - - public void setUpdatedTime(String updatedTime) { - this.updatedTime = updatedTime; - } - - public String getEmail() { - return email; - } -} diff --git a/juick-common/src/main/java/com/juick/model/twitter/User.java b/juick-common/src/main/java/com/juick/model/twitter/User.java deleted file mode 100644 index 3c80eff4..00000000 --- a/juick-common/src/main/java/com/juick/model/twitter/User.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.model.twitter; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Created by vitalyster on 28.11.2016. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class User { - private String screenName; - - @JsonProperty("screen_name") - public String getScreenName() { - return screenName; - } - - public void setScreenName(String screenName) { - this.screenName = screenName; - } -} diff --git a/juick-common/src/main/java/com/juick/model/vk/Token.java b/juick-common/src/main/java/com/juick/model/vk/Token.java deleted file mode 100644 index ed93a3ab..00000000 --- a/juick-common/src/main/java/com/juick/model/vk/Token.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.model.vk; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Created by vitalyster on 28.11.2016. - */ -public class Token { - private Long userId; - private String accessToken; - private String expiresIn; - - @JsonProperty("user_id") - public Long getUserId() { - return userId; - } - - public void setUserId(Long userId) { - this.userId = userId; - } - - @JsonProperty("access_token") - public String getAccessToken() { - return accessToken; - } - - public void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } - - @JsonProperty("expires_in") - public String getExpiresIn() { - return expiresIn; - } - - public void setExpiresIn(String expiresIn) { - this.expiresIn = expiresIn; - } -} diff --git a/juick-common/src/main/java/com/juick/model/vk/User.java b/juick-common/src/main/java/com/juick/model/vk/User.java deleted file mode 100644 index aeb18285..00000000 --- a/juick-common/src/main/java/com/juick/model/vk/User.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.model.vk; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Created by vitalyster on 28.11.2016. - */ -public class User { - private String id; - private String firstName; - private String lastName; - private String screenName; - - @JsonProperty("first_name") - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - @JsonProperty("last_name") - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - @JsonProperty("screen_name") - public String getScreenName() { - return screenName; - } - - public void setScreenName(String screenName) { - this.screenName = screenName; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } -} diff --git a/juick-common/src/main/java/com/juick/model/vk/UsersResponse.java b/juick-common/src/main/java/com/juick/model/vk/UsersResponse.java deleted file mode 100644 index 67505703..00000000 --- a/juick-common/src/main/java/com/juick/model/vk/UsersResponse.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.model.vk; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.util.List; - -/** - * Created by vitalyster on 28.11.2016. - */ -public class UsersResponse { - private List<User> users; - - @JsonProperty("response") - public List<User> getUsers() { - return users; - } - - public void setUsers(List<User> users) { - this.users = users; - } -} diff --git a/juick-common/src/main/java/com/juick/package-info.java b/juick-common/src/main/java/com/juick/package-info.java deleted file mode 100644 index c9023417..00000000 --- a/juick-common/src/main/java/com/juick/package-info.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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/>. - */ - -/** - * Created by vitalyster on 15.11.2016. - */ -@XmlSchema( - namespace="http://juick.com/message", - elementFormDefault = XmlNsForm.QUALIFIED, - xmlns={ - @XmlNs(prefix= StringUtils.EMPTY, namespaceURI="http://juick.com/message"), - @XmlNs(prefix="user", namespaceURI="http://juick.com/user") - } -) -package com.juick; - -import org.apache.commons.lang3.StringUtils; - -import javax.xml.bind.annotation.XmlNs; -import javax.xml.bind.annotation.XmlNsForm; -import javax.xml.bind.annotation.XmlSchema;
\ No newline at end of file diff --git a/juick-common/src/main/java/com/juick/service/CrosspostService.java b/juick-common/src/main/java/com/juick/service/CrosspostService.java deleted file mode 100644 index 99911250..00000000 --- a/juick-common/src/main/java/com/juick/service/CrosspostService.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.ExternalToken; -import com.juick.model.ApplicationStatus; -import org.apache.commons.lang3.tuple.Pair; - -import javax.annotation.Nonnull; -import java.util.Optional; - -/** - * Created by aalexeev on 11/13/16. - */ -public interface CrosspostService { - - Optional<ExternalToken> getTwitterToken(int uid); - - boolean deleteTwitterToken(Integer uid); - - void addFacebookState(String state, String redirectUri); - - void addVKState(String state, String redirectUri); - - String verifyFacebookState(String state); - - String verifyVKState(String state); - - Optional<Pair<String, String>> getFacebookTokens(int uid); - - ApplicationStatus getFbCrossPostStatus(int uid); - - boolean enableFBCrosspost(Integer uid); - - void disableFBCrosspost(Integer uid); - - @Nonnull - String getTwitterName(int uid); - - String getTelegramName(int uid); - - Optional<Pair<String, String>> getVkTokens(int uid); - - void deleteVKUser(Integer uid); - - int getUIDbyFBID(long fbID); - - boolean createFacebookUser(long fbID, String loginhash, String token, String fbName, String fbLink); - - boolean updateFacebookUser(long fbID, String token, String fbName, String fbLink); - - int getUIDbyVKID(long vkID); - - boolean createVKUser(long vkID, String loginhash, String token, String vkName, String vkLink); - - String getFacebookNameByHash(String hash); - - String getTelegramNameByHash(String hash); - - boolean setFacebookUser(String hash, int uid); - - String getVKNameByHash(String hash); - - boolean setVKUser(String hash, int uid); - - boolean setTelegramUser(String hash, int uid); - - String getJIDByHash(String hash); - - boolean setJIDUser(String hash, int uid); -} diff --git a/juick-common/src/main/java/com/juick/service/EmailService.java b/juick-common/src/main/java/com/juick/service/EmailService.java deleted file mode 100644 index 0708cd96..00000000 --- a/juick-common/src/main/java/com/juick/service/EmailService.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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 java.util.List; - -/** - * Created by vitalyster on 09.12.2016. - */ -public interface EmailService { - boolean verifyAddressByCode(Integer userId, String code); - boolean addVerificationCode(Integer userId, String account, String code); - boolean addEmail(Integer userId, String email); - boolean deleteEmail(Integer userId, String account); - String getNotificationsEmail(Integer userId); - boolean setNotificationsEmail(Integer userId, String account); - List<String> getEmails(Integer userId, boolean active); - String getEmailByAuthCode(String code); - void deleteAuthCode(String code); -} diff --git a/juick-common/src/main/java/com/juick/service/ImagesService.java b/juick-common/src/main/java/com/juick/service/ImagesService.java deleted file mode 100644 index 902301ed..00000000 --- a/juick-common/src/main/java/com/juick/service/ImagesService.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.juick.service; - -import com.juick.Message; - -import java.io.IOException; - -public interface ImagesService { - void setAttachmentMetadata(String baseUrl, Message msg) throws Exception; - /** - * Move attached image from temp folder to image folder. - * Create preview images in corresponding folders. - * - * @param tempFilename Name of the image file in the temp folder. - * @param outputFilename Name that will be used in the image folder. - */ - void saveImageWithPreviews(String tempFilename, String outputFilename) throws IOException; - /** - * Save new avatar in all required sizes. - * - * @param tempFilename Name of the image file in the temp folder. - * @param uid User id that is used to build image file names. - */ - void saveAvatar(String tempFilename, int uid) throws IOException; -} diff --git a/juick-common/src/main/java/com/juick/service/MessagesService.java b/juick-common/src/main/java/com/juick/service/MessagesService.java deleted file mode 100644 index 362501b5..00000000 --- a/juick-common/src/main/java/com/juick/service/MessagesService.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.Message; -import com.juick.Reaction; -import com.juick.User; -import com.juick.model.ResponseReply; - -import java.net.URI; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Created by aalexeev on 11/13/16. - */ -public interface MessagesService { - int createMessage(int uid, String txt, String attachment, Collection<com.juick.Tag> tags); - - int createReply(int mid, int rid, User user, String txt, String attachment); - - int getReplyIDIncrement(int mid); - - enum RecommendStatus { - Error, - Added, - Deleted - } - - RecommendStatus recommendMessage(int mid, int vuid, String userUri); - - RecommendStatus recommendMessage(int mid, int vuid); - - List<Reaction> listReactions(); - - RecommendStatus likeMessage(int mid, int vuid, int reactionId); - - RecommendStatus likeMessage(int mid, int vuid, int reactionId, String userUri); - - - boolean canViewThread(int mid, int uid); - - boolean isReadOnly(int mid); - - boolean isSubscribed(int uid, int mid); - - int getMessagePrivacy(int mid); - - com.juick.Message getMessage(int mid); - - com.juick.Message getReply(int mid, int rid); - - com.juick.Message getReplyByUri(String replyUri); - - User getMessageAuthor(int mid); - - List<String> getMessageRecommendations(int mid); - - 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); - - List<Integer> getDiscussions(int uid, Long to); - - List<Integer> getRecommended(int uid, int before); - - List<Integer> getPopular(int visitorUid, 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(int uid, 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); - - List<com.juick.Message> getMessages(User visitor, List<Integer> mids); - - Map<Integer,Set<Reaction>> updateReactionsFor(final List<Integer> mid); - - List<com.juick.Message> getReplies(User user, int mid); - - boolean setMessagePopular(int mid, int popular); - - boolean setMessagePrivacy(int mid); - - boolean deleteMessage(int uid, int mid); - - boolean deleteReply(int uid, int mid, int rid); - - List<Integer> getLastMessages(int hours); - - List<ResponseReply> getLastReplies(int hours); - - List<Integer> getPopularCandidates(); - - void setLastReadComment(User user, Integer mid, Integer rid); - - void setRead(User user, Integer mid); - - List<Integer> getUnread(User user); - - boolean updateMessage(Integer mid, Integer rid, String body); - - boolean updateReplyUri(Message reply, URI replyUri); - - boolean replyExists(URI replyUri); - - boolean deleteReply(URI userUri, URI replyUri); -} diff --git a/juick-common/src/main/java/com/juick/service/MessengerService.java b/juick-common/src/main/java/com/juick/service/MessengerService.java deleted file mode 100644 index e07c73fe..00000000 --- a/juick-common/src/main/java/com/juick/service/MessengerService.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.juick.service; - -import com.juick.User; - -import java.util.Optional; - -public interface MessengerService { - Integer getUserId(String senderId); - Optional<String> getSenderId(User user); - boolean createMessengerUser(String senderId, String displayName); - String getDisplayName(String hash); - String getSignUpHash(String senderId, String username); - boolean linkMessengerUser(String hash, int uid); -} diff --git a/juick-common/src/main/java/com/juick/service/PMQueriesService.java b/juick-common/src/main/java/com/juick/service/PMQueriesService.java deleted file mode 100644 index e0067544..00000000 --- a/juick-common/src/main/java/com/juick/service/PMQueriesService.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.Chat; -import com.juick.User; - -import java.util.List; - -/** - * Created by aalexeev on 11/13/16. - */ -public interface PMQueriesService { - boolean createPM(int uidFrom, int uid_to, String body); - - boolean addPMinRoster(int uid, String jid); - - boolean removePMinRoster(int uid, String jid); - - boolean havePMinRoster(int uid, String jid); - - List<Chat> getLastChats(User user); - - List<com.juick.Message> getPMMessages(int uid, int uidTo); - - List<com.juick.Message> getLastPMInbox(int uid); - - List<com.juick.Message> getLastPMSent(int uid); -} diff --git a/juick-common/src/main/java/com/juick/service/PrivacyQueriesService.java b/juick-common/src/main/java/com/juick/service/PrivacyQueriesService.java deleted file mode 100644 index 17dd6a9b..00000000 --- a/juick-common/src/main/java/com/juick/service/PrivacyQueriesService.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.Tag; -import com.juick.User; - -/** - * Created by aalexeev on 11/13/16. - */ -public interface PrivacyQueriesService { - enum PrivacyResult { - Removed, Added - } - - PrivacyResult blacklistUser(User user, User target); - - PrivacyResult blacklistTag(User user, Tag tag); -} diff --git a/juick-common/src/main/java/com/juick/service/PushQueriesService.java b/juick-common/src/main/java/com/juick/service/PushQueriesService.java deleted file mode 100644 index f84a83e4..00000000 --- a/juick-common/src/main/java/com/juick/service/PushQueriesService.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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 java.util.Collection; -import java.util.List; - -/** - * Created by aalexeev on 11/13/16. - */ -public interface PushQueriesService { - List<String> getGCMRegID(int uid); - - List<String> getGCMTokens(Collection<Integer> uids); - - boolean addGCMToken(Integer uid, String token); - - boolean deleteGCMToken(String token); - - List<String> getMPNSURL(int uid); - - List<String> getMPNSTokens(Collection<Integer> uids); - - boolean addMPNSToken(Integer uid, String token); - - boolean deleteMPNSToken(String token); - - List<String> getAPNSToken(int uid); - - List<String> getAPNSTokens(Collection<Integer> uids); - - boolean addAPNSToken(Integer uid, String token); - - boolean deleteAPNSToken(String token); -} diff --git a/juick-common/src/main/java/com/juick/service/SearchService.java b/juick-common/src/main/java/com/juick/service/SearchService.java deleted file mode 100644 index 0dae5cfc..00000000 --- a/juick-common/src/main/java/com/juick/service/SearchService.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.User; - -import java.util.List; - -/** - * Created by aalexeev on 11/18/16. - */ -public interface SearchService { - void setMaxResult(int maxResult); - - List<Integer> searchInAllMessages(User visitor, String searchString, int messageIdBefore); - - List<Integer> searchByStringAndUser(User visitor, String searchString, final int userId, int messageIdBefore); -} diff --git a/juick-common/src/main/java/com/juick/service/ShowQueriesService.java b/juick-common/src/main/java/com/juick/service/ShowQueriesService.java deleted file mode 100644 index 32b34b4e..00000000 --- a/juick-common/src/main/java/com/juick/service/ShowQueriesService.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.User; - -import java.util.List; - -/** - * Created by aalexeev on 11/13/16. - */ -public interface ShowQueriesService { - List<String> getRecommendedUsers(User forUser); - - List<String> getTopUsers(); -} diff --git a/juick-common/src/main/java/com/juick/service/SocialService.java b/juick-common/src/main/java/com/juick/service/SocialService.java deleted file mode 100644 index eb77619b..00000000 --- a/juick-common/src/main/java/com/juick/service/SocialService.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.juick.service; - -import com.juick.User; - -import javax.annotation.Nonnull; -import java.util.List; - -public interface SocialService { - @Nonnull - User getUserByAccountUri(String acct); - @Nonnull - List<String> getFollowers(User user); - void addFollower(User user, String acct); - void removeFollower(User user, String acct); - void removeAccount(String acct); -} diff --git a/juick-common/src/main/java/com/juick/service/SubscriptionService.java b/juick-common/src/main/java/com/juick/service/SubscriptionService.java deleted file mode 100644 index 8bc8d071..00000000 --- a/juick-common/src/main/java/com/juick/service/SubscriptionService.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.Message; -import com.juick.Tag; -import com.juick.User; -import com.juick.model.NotifyOpts; - -import java.util.List; - -/** - * Created by aalexeev on 11/13/16. - */ -public interface SubscriptionService { - - List<User> getSubscribedUsers(int uid, Message msg); - - List<User> getUsersSubscribedToComments(Message msg, Message reply); - - List<User> getUsersSubscribedToComments(Message msg, Message reply, boolean blacklisted); - - List<User> getUsersSubscribedToUserRecommendations(int uid, Message msg); - - boolean subscribeMessage(Message message, User user); - - boolean unSubscribeMessage(int mid, int vuid); - - boolean subscribeUser(User user, User toUser); - - boolean unSubscribeUser(User user, User fromUser); - - boolean subscribeTag(User user, Tag toTag); - - boolean unSubscribeTag(User user, Tag toTag); - - List<String> getSubscribedTags(User user); - - NotifyOpts getNotifyOptions(User user); - - boolean setNotifyOptions(User user, NotifyOpts options); -} diff --git a/juick-common/src/main/java/com/juick/service/TagService.java b/juick-common/src/main/java/com/juick/service/TagService.java deleted file mode 100644 index 489f405a..00000000 --- a/juick-common/src/main/java/com/juick/service/TagService.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.Tag; -import com.juick.User; -import com.juick.model.TagStats; -import org.apache.commons.lang3.tuple.Pair; - -import java.util.Collection; -import java.util.List; -import java.util.stream.Stream; - -/** - * Created by aalexeev on 11/13/16. - */ -public interface TagService { - Tag getTag(int tid); - - Tag getTag(String tag, boolean autoCreate); - - List<Tag> getTags(Stream<String> tags, boolean autoCreate); - - boolean getTagNoIndex(int tagId); - - int createTag(String name); - - List<TagStats> getUserTagStats(int uid); - - List<String> getUserBLTags(int uid); - - List<String> getPopularTags(); - - List<TagStats> getTagStats(); - - List<Tag> updateTags(int mid, Collection<Tag> newTags); - - Pair<String, List<Tag>> fromString(String txt); - - List<TagStats> getMessageTags(int mid); - - List<Integer> getMessageTagsIDs(int mid); - - boolean blacklistTag(User user, Tag tag); - - boolean isInBL(User user, Tag tag); - - boolean isSubscribed(User user, Tag tag); -} diff --git a/juick-common/src/main/java/com/juick/service/TelegramService.java b/juick-common/src/main/java/com/juick/service/TelegramService.java deleted file mode 100644 index 2954370c..00000000 --- a/juick-common/src/main/java/com/juick/service/TelegramService.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.User; - -import java.util.List; - -/** - * Created by vt on 24/11/2016. - */ -public interface TelegramService { - - boolean deleteAnonymous(Long id); - - List<Long> getAnonymous(); - - int getUser(long tgId); - - boolean createTelegramUser(long tgID, String tgName); - - boolean deleteTelegramUser(Integer uid); - - List<Long> getTelegramIdentifiers(List<User> users); -} diff --git a/juick-common/src/main/java/com/juick/service/UserService.java b/juick-common/src/main/java/com/juick/service/UserService.java deleted file mode 100644 index 832f978a..00000000 --- a/juick-common/src/main/java/com/juick/service/UserService.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.Message; -import com.juick.User; -import com.juick.model.Auth; -import com.juick.model.UserInfo; - -import javax.annotation.Nonnull; -import java.time.Instant; -import java.util.Collection; -import java.util.List; -import java.util.Optional; - -/** - * Created by aalexeev on 11/13/16. - */ -public interface UserService { - enum ActiveStatus { - Inactive, - Active - } - - String getSignUpHashByJID(String jid); - - String getSignUpHashByTelegramID(Long telegramId, String username); - - int createUser(String username, String password); - - Optional<User> getUserByUID(int uid); - - @Nonnull User getUserByName(String username); - - @Nonnull User getUserByEmail(String email); - - User getUserByJID(String jid); - - List<User> getUsersByName(Collection<String> unames); - - List<User> getUsersByID(Collection<Integer> uids); - - List<String> getJIDsbyUID(int uid); - - int getUIDbyJID(String jid); - - int getUIDbyName(String uname); - - int getUIDbyHash(String hash); - - @Nonnull com.juick.User getUserByHash(String hash); - - String getHashByUID(int uid); - - int checkPassword(String username, String password); - - boolean updatePassword(User user, String newPassword); - - int getUserOptionInt(int uid, String option, int defaultValue); - - int setUserOptionInt(int uid, String option, int value); - - UserInfo getUserInfo(User user); - - boolean updateUserInfo(User user, UserInfo info); - - boolean getCanMedia(int uid); - - boolean isInWL(int uid, int check); - - boolean isInBL(int uid, int check); - - boolean isInBLAny(int uid, int uid2); - - boolean isReplyToBL(final User user, final Message reply); - - List<Integer> checkBL(int visitor, Collection<Integer> uids); - - boolean isSubscribed(int uid, int check); - - List<com.juick.User> getUserReadLeastPopular(int uid, int cnt); - - List<User> getUserReaders(int uid); - - List<User> getUserFriends(int uid); - - Integer getUserRecommendations(User user); - - List<com.juick.User> getUserBLUsers(int uid); - - boolean linkTwitterAccount(User user, String accessToken, String accessTokenSecret, String screenName); - - int getStatsMyReaders(int uid); - - int getStatsMessages(int uid); - - int getStatsReplies(int uid); - - boolean setActiveStatusForJID(String JID, ActiveStatus jidStatus); - - List<String> getAllJIDs(User user); - - List<Auth> getAuthCodes(User user); - - List<String> getEmails(User user); - - String getEmailHash(User user); - - int deleteLoginForUser(String name); - - int setLoginForUser(int uid, String loginHash); - - void logout(int uid); - - boolean deleteJID(int uid, String jid); - - boolean unauthJID(int uid, String jid); - - List<String> getActiveJIDs(); - - void updateLastSeen(User user); -} diff --git a/juick-common/src/main/java/com/juick/service/component/DisconnectedEvent.java b/juick-common/src/main/java/com/juick/service/component/DisconnectedEvent.java deleted file mode 100644 index 552c3e66..00000000 --- a/juick-common/src/main/java/com/juick/service/component/DisconnectedEvent.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.juick.service.component; - -import org.springframework.context.ApplicationEvent; - -public class DisconnectedEvent extends ApplicationEvent { - /** - * Create a new ApplicationEvent. - * - * @param source the object on which the event initially occurred (never {@code null}) - */ - public DisconnectedEvent(Object source) { - super(source); - } -} diff --git a/juick-common/src/main/java/com/juick/service/component/LikeEvent.java b/juick-common/src/main/java/com/juick/service/component/LikeEvent.java deleted file mode 100644 index 0d4df70c..00000000 --- a/juick-common/src/main/java/com/juick/service/component/LikeEvent.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.juick.service.component; - -import com.juick.Message; -import com.juick.User; -import org.springframework.context.ApplicationEvent; - -import java.util.List; - -public class LikeEvent extends ApplicationEvent { - private User user; - private Message message; - private List<User> subscribers; - /** - * Create a new ApplicationEvent. - * - * @param source the object on which the event initially occurred (never {@code null}) - */ - public LikeEvent(Object source, User user, Message message, List<User> subscribers) { - super(source); - this.message = message; - this.user = user; - this.subscribers = subscribers; - } - - public User getUser() { - return user; - } - - public Message getMessage() { - return message; - } - - public List<User> getSubscribers() { - return subscribers; - } -} diff --git a/juick-common/src/main/java/com/juick/service/component/MessageEvent.java b/juick-common/src/main/java/com/juick/service/component/MessageEvent.java deleted file mode 100644 index 82911a58..00000000 --- a/juick-common/src/main/java/com/juick/service/component/MessageEvent.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.juick.service.component; - -import com.juick.Message; -import com.juick.User; -import org.springframework.context.ApplicationEvent; - -import java.util.List; - -public class MessageEvent extends ApplicationEvent { - private Message message; - private List<User> users; - /** - * Create a new ApplicationEvent. - * - * @param source the object on which the event initially occurred (never {@code null}) - * @param message app message - * @param interestedUsers users interested in notification - */ - public MessageEvent(Object source, Message message, List<User> interestedUsers) { - super(source); - this.message = message; - this.users = interestedUsers; - } - - public Message getMessage() { - return message; - } - public List<User> getUsers() { - return users; - } -} diff --git a/juick-common/src/main/java/com/juick/service/component/MessageReadEvent.java b/juick-common/src/main/java/com/juick/service/component/MessageReadEvent.java deleted file mode 100644 index b070c8cb..00000000 --- a/juick-common/src/main/java/com/juick/service/component/MessageReadEvent.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.juick.service.component; - -import com.juick.Message; -import com.juick.User; -import org.springframework.context.ApplicationEvent; - -import java.util.List; - -public class MessageReadEvent extends ApplicationEvent { - private User user; - private Message message; - /** - * Create a new ApplicationEvent. - * - * @param source the object on which the event initially occurred (never {@code null}) - */ - public MessageReadEvent(Object source, User user, Message message) { - super(source); - this.user = user; - this.message = message; - } - - public User getUser() { - return user; - } - - public Message getMessage() { - return message; - } -} diff --git a/juick-common/src/main/java/com/juick/service/component/NotificationListener.java b/juick-common/src/main/java/com/juick/service/component/NotificationListener.java deleted file mode 100644 index 38d0490a..00000000 --- a/juick-common/src/main/java/com/juick/service/component/NotificationListener.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.juick.service.component; - -import org.springframework.context.event.EventListener; -import org.springframework.scheduling.annotation.Async; - -public interface NotificationListener { - @Async - @EventListener - void processMessageEvent(MessageEvent messageEvent); - @Async - @EventListener - void processSubscribeEvent(SubscribeEvent subscribeEvent); - @Async - @EventListener - void processLikeEvent(LikeEvent likeEvent); - @Async - @EventListener - void processPingEvent(PingEvent pingEvent); - @Async - @EventListener - void processMessageReadEvent(MessageReadEvent messageReadEvent); - @Async - @EventListener - void processTopEvent(TopEvent topEvent); -} diff --git a/juick-common/src/main/java/com/juick/service/component/PingEvent.java b/juick-common/src/main/java/com/juick/service/component/PingEvent.java deleted file mode 100644 index 8e3f3fa7..00000000 --- a/juick-common/src/main/java/com/juick/service/component/PingEvent.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.juick.service.component; - -import com.juick.User; -import org.springframework.context.ApplicationEvent; - -public class PingEvent extends ApplicationEvent { - private User pinger; - /** - * Create a new ApplicationEvent. - * - * @param source the object on which the event initially occurred (never {@code null}) - */ - public PingEvent(Object source, User pinger) { - super(source); - this.pinger = pinger; - } - - public User getPinger() { - return pinger; - } -} diff --git a/juick-common/src/main/java/com/juick/service/component/SubscribeEvent.java b/juick-common/src/main/java/com/juick/service/component/SubscribeEvent.java deleted file mode 100644 index 9b644f2f..00000000 --- a/juick-common/src/main/java/com/juick/service/component/SubscribeEvent.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.juick.service.component; - -import com.juick.User; -import org.springframework.context.ApplicationEvent; - -public class SubscribeEvent extends ApplicationEvent { - private User user; - private User toUser; - /** - * Create a new ApplicationEvent. - * - * @param source the object on which the event initially occurred (never {@code null}) - */ - public SubscribeEvent(Object source, User user, User toUser) { - super(source); - this.user = user; - this.toUser = toUser; - } - - public User getUser() { - return user; - } - - public User getToUser() { - return toUser; - } -} diff --git a/juick-common/src/main/java/com/juick/service/component/TopEvent.java b/juick-common/src/main/java/com/juick/service/component/TopEvent.java deleted file mode 100644 index b7e24957..00000000 --- a/juick-common/src/main/java/com/juick/service/component/TopEvent.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.juick.service.component; - -import com.juick.Message; -import org.springframework.context.ApplicationEvent; - -public class TopEvent extends ApplicationEvent { - private Message message; - /** - * Create a new ApplicationEvent. - * - * @param source the object on which the event initially occurred (never {@code null}) - */ - public TopEvent(Object source, Message message) { - super(source); - this.message = message; - } - - public Message getMessage() { - return message; - } -} diff --git a/juick-common/src/main/java/com/juick/service/component/UserUpdatedEvent.java b/juick-common/src/main/java/com/juick/service/component/UserUpdatedEvent.java deleted file mode 100644 index af2f579a..00000000 --- a/juick-common/src/main/java/com/juick/service/component/UserUpdatedEvent.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.juick.service.component; - -import com.juick.User; -import org.springframework.context.ApplicationEvent; -import org.springframework.lang.NonNull; - -public class UserUpdatedEvent extends ApplicationEvent { - private User user; - /** - * Generated when user is updated (avatar changed, etc). - * - * @param source the object on which the event initially occurred (never {@code null}) - * @param user updated user - */ - public UserUpdatedEvent(@NonNull Object source, User user) { - super(source); - this.user = user; - } - - public User getUser() { - return user; - } -} diff --git a/juick-common/src/main/java/com/juick/util/DateFormatter.java b/juick-common/src/main/java/com/juick/util/DateFormatter.java deleted file mode 100644 index 8f569562..00000000 --- a/juick-common/src/main/java/com/juick/util/DateFormatter.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.util; - -import org.apache.commons.lang3.StringUtils; - -import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneOffset; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Locale; - -/** - * Created by aalexeev on 12/7/16. - */ -public class DateFormatter { - private final DateTimeFormatter formatter; - - public DateFormatter(String pattern) { - formatter = DateTimeFormatter.ofPattern(pattern, Locale.ENGLISH); - } - - public String format(final Instant ts) { - if (ts == null) - return null; - - ZonedDateTime ldt = ZonedDateTime.ofInstant(ts, ZoneOffset.UTC); - - return ldt.format(formatter); - } - - - public Instant parse(final String v) { - if (StringUtils.isBlank(v)) - return null; - - ZonedDateTime ldt = ZonedDateTime.parse(v, formatter); - - return ldt.toInstant(); - } -} diff --git a/juick-common/src/main/java/com/juick/util/DateFormattersHolder.java b/juick-common/src/main/java/com/juick/util/DateFormattersHolder.java deleted file mode 100644 index 8292e68e..00000000 --- a/juick-common/src/main/java/com/juick/util/DateFormattersHolder.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.util; - -/** - * Created by aalexeev on 12/7/16. - */ -public class DateFormattersHolder { - - private DateFormattersHolder() { - throw new IllegalStateException(); - } - - private static volatile DateFormatter messageFormatter; - - public static DateFormatter getMessageFormatterInstance() { - DateFormatter localInstance = messageFormatter; - - if (localInstance == null) { - synchronized (DateFormatter.class) { - localInstance = messageFormatter; - - if (localInstance == null) - messageFormatter = localInstance = new DateFormatter("yyyy-MM-dd HH:mm:ss"); - } - } - return localInstance; - } - - private static volatile DateFormatter rssFormatter; - - public static DateFormatter getRssFormatterInstance() { - DateFormatter localInstance = rssFormatter; - - if (localInstance == null) { - synchronized (DateFormatter.class) { - localInstance = rssFormatter; - - if (localInstance == null) - rssFormatter = localInstance = new DateFormatter("EEE, d MMM yyyy HH:mm:ss"); - } - } - return localInstance; - } - - private static volatile DateFormatter httpDateFormatter; - - public static DateFormatter getHttpDateFormatter() { - DateFormatter localInstance = httpDateFormatter; - if (localInstance == null) { - synchronized (DateFormatter.class) { - localInstance = httpDateFormatter; - if (localInstance == null) { - httpDateFormatter = localInstance = new DateFormatter("EEE, dd MMM yyyy HH:mm:ss O"); - } - } - } - return localInstance; - } -} diff --git a/juick-common/src/main/java/com/juick/util/MessageUtils.java b/juick-common/src/main/java/com/juick/util/MessageUtils.java deleted file mode 100644 index fd357c32..00000000 --- a/juick-common/src/main/java/com/juick/util/MessageUtils.java +++ /dev/null @@ -1,324 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.util; - -import com.juick.Message; -import com.juick.Tag; -import com.juick.User; -import org.apache.commons.codec.CharEncoding; -import org.apache.commons.lang3.StringUtils; -import org.springframework.web.util.UriComponentsBuilder; - -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - -/** - * Created by aalexeev on 11/13/16. - */ -public class MessageUtils { - private MessageUtils() { - throw new IllegalStateException(); - } - - public static String formatQuote(final String quote) { - String result = quote; - - if (quote != null) { - if (quote.length() > 50) { - result = ">" + quote.substring(0, 47).replace('\n', ' ') + "...\n"; - } else if (!quote.isEmpty()) { - result = ">" + quote.replace('\n', ' ') + "\n"; - } - } - - return result; - } - - private final static String urlWhiteSpacePrefix = "((?<=\\s)|(?<=\\A))"; - - private final static String urlRegex = "((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\n\\\"]+)/?[^\\]\\s\\n\\\"\\>]*)"; - - private final static String urlWithWhitespacesRegex = - urlWhiteSpacePrefix + urlRegex; - - private final static Pattern regexLinks2 = Pattern.compile("((?<=\\s)|(?<=\\A))([\\[\\{]|<)((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\\"\\)\\!]+)/?(?:[^\\]\\}](?<!>))*)([\\]\\}]|>)"); - - private final static String replyNumberRegex = "((?<=\\s)|(?<=\\A))\\/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))"; - - private final static String usernameRegex = "((?<=\\s)|(?<=\\A))@([\\w\\-]{2,16})((?=\\s)|(?=\\Z)|(?=\\p{Punct}))"; - private final static Pattern usernamePattern = Pattern.compile(usernameRegex); - - private final static String jidRegex = "((?<=\\s)|(?<=\\A))@([\\w\\-\\.]+@[\\w\\-\\.]+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))"; - private final static Pattern jidPattern = Pattern.compile(jidRegex); - - public static String formatMessageCode(String msg) { - msg = msg.replaceAll("&", "&"); - msg = msg.replaceAll("<", "<"); - msg = msg.replaceAll(">", ">"); - - // http://juick.com/last?page=2 - // <a href="http://juick.com/last?page=2" rel="nofollow">http://juick.com/last?page=2</a> - msg = msg.replaceAll(urlWithWhitespacesRegex, "$1<a href=\"$2\" rel=\"nofollow\">$2</a>"); - - // (http://juick.com/last?page=2) - // (<a href="http://juick.com/last?page=2" rel="nofollow">http://juick.com/last?page=2</a>) - Matcher m = regexLinks2.matcher(msg); - StringBuffer sb = new StringBuffer(); - while (m.find()) { - String url = m.group(3).replace(" ", "%20").replaceAll("\\s+", StringUtils.EMPTY); - m.appendReplacement(sb, "$1$2<a href=\"" + url + "\" rel=\"nofollow\">" + url + "</a>$5"); - } - m.appendTail(sb); - msg = sb.toString(); - - return "<pre>" + msg + "</pre>"; - } - - public static String formatMessage(String msg) { - msg = msg.replaceAll("&", "&"); - msg = msg.replaceAll("<", "<"); - msg = msg.replaceAll(">", ">"); - - // -- - // — - msg = msg.replaceAll("((?<=\\s)|(?<=\\A))\\-\\-?((?=\\s)|(?=\\Z))", "$1—$2"); - - // http://juick.com/last?page=2 - // <a href="http://juick.com/last?page=2" rel="nofollow">juick.com</a> - msg = msg.replaceAll(urlWithWhitespacesRegex, "$1<a href=\"$2\" rel=\"nofollow\">$3</a>"); - - // [link text][http://juick.com/last?page=2] - // <a href="http://juick.com/last?page=2" rel="nofollow">link text</a> - msg = msg.replaceAll("\\[([^\\]]+)\\]\\[((?:ht|f)tps?://[^\\]]+)\\]", "<a href=\"$2\" rel=\"nofollow\">$1</a>"); - msg = msg.replaceAll("\\[([^\\]]+)\\]\\(((?:ht|f)tps?://[^\\)]+)\\)", "<a href=\"$2\" rel=\"nofollow\">$1</a>"); - - // #12345 - // <a href="http://juick.com/12345">#12345</a> - msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)((?=\\s)|(?=\\Z)|(?=\\))|(?=\\.)|(?=\\,))", "$1<a href=\"https://juick.com/m/$2\">#$2</a>$3"); - - // #12345/65 - // <a href="http://juick.com/12345#65">#12345/65</a> - msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"https://juick.com/m/$2#$3\">#$2/$3</a>$4"); - - // *bold* - // <b>bold</b> - msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))\\*([^\\*\\n<>]+)\\*((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<b>$2</b>$3"); - - // /italic/ - // <i>italic</i> - msg = msg.replaceAll("((?<=\\s)|(?<=\\A))/([^\\/\\n<>]+)/((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<i>$2</i>$3"); - - // _underline_ - // <span class="u">underline</span> - msg = msg.replaceAll("((?<=\\s)|(?<=\\A))_([^\\_\\n<>]+)_((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<span class=\"u\">$2</span>$3"); - - // /12 - // <a href="#12">/12</a> - msg = msg.replaceAll(replyNumberRegex, "$1<a href=\"#$2\">/$2</a>$3"); - - // @username@jabber.org - // <a href="http://juick.com/username@jabber.org/">@username@jabber.org</a> - msg = msg.replaceAll(jidRegex, "$1<a href=\"https://juick.com/$2/\">@$2</a>$3"); - - // @username - // <a href="http://juick.com/username/">@username</a> - msg = msg.replaceAll(usernameRegex, "$1<a href=\"https://juick.com/$2/\">@$2</a>$3"); - - // (http://juick.com/last?page=2) - // (<a href="http://juick.com/last?page=2" rel="nofollow">juick.com</a>) - Matcher m = regexLinks2.matcher(msg); - StringBuffer sb = new StringBuffer(); - while (m.find()) { - String url = m.group(3).replace(" ", "%20").replaceAll("\\s+", StringUtils.EMPTY); - m.appendReplacement(sb, "$1$2<a href=\"" + url + "\" rel=\"nofollow\">$4</a>$5"); - } - m.appendTail(sb); - msg = sb.toString(); - - // > citate - msg = msg.replaceAll("(?:(?<=\\n)|(?<=\\A))> *(.*)?(\\n|(?=\\Z))", "<q>$1</q>"); - msg = msg.replaceAll("</q><q>", "\n"); - - msg = msg.replaceAll("\n", "<br/>\n"); - return msg; - } - - public static String formatHtml(Message jmsg) { - StringBuilder sb = new StringBuilder(); - boolean isReply = jmsg.getRid() > 0; - String title = isReply ? "<b>Reply by @" : "<b>@"; - String subtitle = isReply ? "<blockquote>" + jmsg.getReplyQuote() + "</blockquote>" : "<i>" + getTagsString(jmsg) + "</i>"; - boolean isCode = jmsg.getTags().stream().anyMatch(t -> t.getName().equals("code")); - - sb.append(title).append(jmsg.getUser().getName()).append(":</b></br/>") - .append(subtitle).append("<br/>") - .append(isCode ? formatMessageCode(StringUtils.defaultString(jmsg.getText())) - : formatMessage(StringUtils.defaultString(jmsg.getText()))).append("<br />"); - if (StringUtils.isNotEmpty(jmsg.getAttachmentType())) { - // FIXME: attachment does not serialized to xml - if (jmsg.getAttachment() == null) { - if (jmsg.getRid() > 0) { - sb.append(String.format("<img src=\"http://i.juick.com/photos-1024/%d-%d.%s\" />", jmsg.getMid(), - jmsg.getRid(), jmsg.getAttachmentType())); - } else { - sb.append(String.format("<img src=\"http://i.juick.com/photos-1024/%d.%s\" />", jmsg.getMid(), - jmsg.getAttachmentType())); - } - } else { - sb.append("<img src=\"").append(jmsg.getAttachment().getMedium().getUrl()).append("\" />"); - } - } - return sb.toString(); - } - - public static String getMessageHashTags(final Message jmsg) { - StringBuilder hashtags = new StringBuilder(); - for (Tag tag : jmsg.getTags()) { - hashtags.append("#").append(tag).append(" "); - } - return hashtags.toString(); - } - public static String getMarkdownTags(final Message jmsg) { - return jmsg.getTags().stream().map(t -> String.format("[%s](http://juick.com/tag/%s)", t.getName(), percentEncode(t.getName()))) - .collect(Collectors.joining(", ")); - } - - public static String getMarkdownUser(final User user) { - return String.format("[%s](https://juick.com/%s/)", user.getName(), user.getName()); - } - - // TODO: check if it is really needed - public static String percentEncode(final String s) { - String ret = StringUtils.EMPTY; - try { - ret = URLEncoder.encode(s, CharEncoding.UTF_8).replace("+", "%20").replace("*", "%2A").replace("%7E", "~"); - } catch (UnsupportedEncodingException e) { - } - return ret; - } - public static String formatMarkdownText(final Message msg) { - String s = StringUtils.defaultString(msg.getText()).replaceAll(replyNumberRegex, String.format("$1[/$2](https://juick.com/m/%d#$2)$3", msg.getMid())); - return escapeMarkdown(s); - } - public static String escapeMarkdown(final String s) { - return s.replace("_", "\\_").replace("*", "\\*") - .replace("`", "\\`"); - } - public static String attachmentUrl(final Message jmsg) { - if (StringUtils.isEmpty(jmsg.getAttachmentType())) { - return StringUtils.EMPTY; - } - // FIXME: attachment does not serialized to xml - if (jmsg.getAttachment() == null) { - if (jmsg.getRid() > 0) { - return String.format("http://i.juick.com/photos-1024/%d-%d.%s", jmsg.getMid(), - jmsg.getRid(), jmsg.getAttachmentType()); - } else { - return String.format("http://i.juick.com/photos-1024/%d.%s", jmsg.getMid(), - jmsg.getAttachmentType()); - } - } else { - return jmsg.getAttachment().getMedium().getUrl(); - } - } - public static boolean replyStartsWithQuote(Message msg) { - return msg.getRid() > 0 && StringUtils.defaultString(msg.getText()).startsWith(">"); - } - public static List<Tag> parseTags(String strTags) { - List<Tag> tags = new ArrayList<>(); - if (StringUtils.isNotEmpty(strTags)) { - Set<Tag> tagSet = new TreeSet<>(tags); - for (String str : strTags.split(" ")) { - Tag tag = new Tag(str); - if (!tagSet.contains(tag)) { - tags.add(tag); - tagSet.add(tag); - } - } - } - return tags; - } - public static String getTagsString(Message msg) { - StringBuilder builder = new StringBuilder(); - List<Tag> tags = msg.getTags(); - if (!tags.isEmpty()) { - for (Tag Tag : tags) - builder.append(" *").append(Tag.getName()); - - if (msg.FriendsOnly) - builder.append(" *friends"); - - if (msg.getPrivacy() == -2) - builder.append(" *private"); - else if (msg.getPrivacy() == -1) - builder.append(" *friends"); - else if (msg.getPrivacy() == 2) - builder.append(" *public"); - - if (msg.ReadOnly) - builder.append(" *readonly"); - } - return builder.toString(); - } - public static boolean isPM(Message message) { - return message.getMid() == 0; - } - public static boolean isReply(Message message) { - return message.getRid() > 0; - } - - public static String stripNonSafeUrls(String input) { - // strip login urls - try { - Matcher urlMatcher = Pattern.compile(MessageUtils.urlRegex).matcher(input); - while (urlMatcher.find()) { - URI uri = URI.create(urlMatcher.group(0)); - if (uri.getHost().equals("juick.com")) { - UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUri(uri); - uriComponentsBuilder.replaceQueryParam("hash"); - input = input.replace(urlMatcher.group(0), uriComponentsBuilder.build().toUriString()); - } - } - } catch (IllegalArgumentException | NullPointerException e) { - return input; - } - return input; - } - private static List<String> collectMatches(Pattern pattern, String input) { - Matcher matcher = pattern.matcher(input); - List<String> result = new ArrayList<>(); - while (matcher.find()) { - result.add(matcher.group()); - } - return result; - } - public static List<String> getMentions(Message msg) { - return collectMatches(usernamePattern, msg.getText()); - } - public static List<String> getGlobalMentions(Message msg) { - return collectMatches(jidPattern, msg.getText()); - } -} diff --git a/juick-common/src/main/java/com/juick/util/PrettyTimeFormatter.java b/juick-common/src/main/java/com/juick/util/PrettyTimeFormatter.java deleted file mode 100644 index 383f4d9a..00000000 --- a/juick-common/src/main/java/com/juick/util/PrettyTimeFormatter.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.util; - -import org.ocpsoft.prettytime.PrettyTime; - -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.Locale; -import java.util.Map; - -/** - * Created by vitalyster on 04.05.2017. - */ -public class PrettyTimeFormatter { - private static final int MAX_CACHE_SIZE = 20; - - // Cache PrettyTime per locale. LRU cache to prevent memory leak. - private static final Map<Locale, PrettyTime> PRETTY_TIME_LOCALE_MAP = - new LinkedHashMap<Locale, PrettyTime>(MAX_CACHE_SIZE + 1, 1.1F, true) - { - @Override - protected boolean removeEldestEntry(Map.Entry<Locale, PrettyTime> eldest) - { - return size() > MAX_CACHE_SIZE; - } - }; - - public String format(final Locale locale, final Date value) - { - PrettyTime prettyTime; - - synchronized (PRETTY_TIME_LOCALE_MAP) { - prettyTime = PRETTY_TIME_LOCALE_MAP.computeIfAbsent(locale, PrettyTime::new); - } - return prettyTime.format(value); - } -} diff --git a/juick-common/src/main/java/com/juick/util/StreamUtils.java b/juick-common/src/main/java/com/juick/util/StreamUtils.java deleted file mode 100644 index 576107af..00000000 --- a/juick-common/src/main/java/com/juick/util/StreamUtils.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.juick.util; - -import java.util.Spliterator; -import java.util.Spliterators; -import java.util.function.Consumer; -import java.util.function.Predicate; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -/** - * @deprecated switch to JDK9+ Stream API when possible - */ -@Deprecated -public class StreamUtils { - private static <T> Spliterator<T> takeWhile( - Spliterator<T> splitr, Predicate<? super T> predicate) { - return new Spliterators.AbstractSpliterator<T>(splitr.estimateSize(), 0) { - boolean stillGoing = true; - @Override public boolean tryAdvance(Consumer<? super T> consumer) { - if (stillGoing) { - boolean hadNext = splitr.tryAdvance(elem -> { - if (predicate.test(elem)) { - consumer.accept(elem); - } else { - stillGoing = false; - } - }); - return hadNext && stillGoing; - } - return false; - } - }; - } - - public static <T> Stream<T> takeWhile(Stream<T> stream, Predicate<? super T> predicate) { - return StreamSupport.stream(takeWhile(stream.spliterator(), predicate), false); - } -} diff --git a/juick-common/src/test/java/com/juick/FormatterTest.java b/juick-common/src/test/java/com/juick/FormatterTest.java deleted file mode 100644 index da9f5d26..00000000 --- a/juick-common/src/test/java/com/juick/FormatterTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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; - -import com.juick.util.DateFormattersHolder; -import org.apache.commons.lang3.RandomUtils; -import org.junit.Test; - -import java.time.Instant; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.TimeZone; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; - -/** - * Created by aalexeev on 12/7/16. - */ -public class FormatterTest { - - @Test - public void forAnyDateFormatterShouldReturnNotEmptyString() throws Exception { - Instant ts = Instant.now(); - - assertThat(DateFormattersHolder.getMessageFormatterInstance().format(ts), not(isEmptyOrNullString())); - assertThat(DateFormattersHolder.getRssFormatterInstance().format(ts), not(isEmptyOrNullString())); - - ts = Instant.ofEpochMilli(RandomUtils.nextLong(1, Long.MAX_VALUE / 10000)); - - assertThat(DateFormattersHolder.getMessageFormatterInstance().format(ts), not(isEmptyOrNullString())); - assertThat(DateFormattersHolder.getRssFormatterInstance().format(ts), not(isEmptyOrNullString())); - } - - @Test - public void forConcreteDateShouldReturnCorrectString() throws Exception { - Calendar calendar = GregorianCalendar.getInstance(); - - calendar.set(2012, 0, 1, 0, 0, 0); - calendar.setTimeZone(TimeZone.getTimeZone("UTC")); - - Date date = calendar.getTime(); - - assertThat(DateFormattersHolder.getMessageFormatterInstance().format(date.toInstant()), equalTo("2012-01-01 00:00:00")); - assertThat(DateFormattersHolder.getRssFormatterInstance().format(date.toInstant()), equalTo("Sun, 1 Jan 2012 00:00:00")); - assertThat(DateFormattersHolder.getHttpDateFormatter().format(date.toInstant()), equalTo("Sun, 01 Jan 2012 00:00:00 GMT")); - } -} diff --git a/juick-common/src/test/java/com/juick/MessageTest.java b/juick-common/src/test/java/com/juick/MessageTest.java deleted file mode 100644 index 6197f861..00000000 --- a/juick-common/src/test/java/com/juick/MessageTest.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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; - -import com.juick.util.MessageUtils; -import org.apache.commons.lang3.RandomUtils; -import org.apache.commons.lang3.StringUtils; -import org.junit.Test; - -import java.util.List; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; - -/** - * Created by aalexeev on 12/7/16. - */ -public class MessageTest { - - @Test - public void equalsShouldBeReturnCorrectResult() { - Message message1 = new Message(); - - Message message2 = new Message(); - message2.setMid(RandomUtils.nextInt()); - - Message message3 = message1; - - assertThat(message1, equalTo(message3)); - assertThat(message3, equalTo(message1)); - - assertThat(message1, not(equalTo(message2))); - assertThat(message2, not(equalTo(message1))); - - int id = RandomUtils.nextInt(); - message1.setMid(id); - message2.setMid(id); - - id = RandomUtils.nextInt(); - message1.setRid(id); - message2.setRid(id); - - assertThat(message1, equalTo(message2)); - assertThat(message2, equalTo(message1)); - - message1.setMid(RandomUtils.nextInt()); - message1.setRid(RandomUtils.nextInt()); - - message2.setMid(RandomUtils.nextInt()); - message2.setRid(RandomUtils.nextInt()); - - assertThat(message1, not(equalTo(message2))); - assertThat(message2, not(equalTo(message1))); - } - - @Test - public void compareShouldBeReturnCorrectResult() { - Message message1 = new Message(); - - message1.setMid(RandomUtils.nextInt()); - message1.setRid(RandomUtils.nextInt()); - - Message message2 = message1; - - assertThat(message1.compareTo(message2), equalTo(0)); - assertThat(message2.compareTo(message1), equalTo(0)); - - Message message3 = new Message(); - - message3.setMid(message1.getMid()); - message3.setRid(message1.getRid()); - - assertThat(message1.compareTo(message3), equalTo(0)); - assertThat(message3.compareTo(message1), equalTo(0)); - } - - @Test - public void messageWithGreaterMidShouldBeLessThenMesageWithLessMid() { - Message message1 = new Message(); - - message1.setMid(RandomUtils.nextInt()); - message1.setRid(RandomUtils.nextInt()); - - Message message2 = new Message(); - - message2.setMid(message1.getMid() + RandomUtils.nextInt(1, 10000)); - message2.setRid(RandomUtils.nextInt()); - - assertThat(message1.compareTo(message2), equalTo(1)); - assertThat(message2.compareTo(message1), equalTo(-1)); - } - - @Test - public void messageWithGreaterRidAndEqualsMidShouldBeGreaterThenMessageWithLessRid() { - Message message1 = new Message(); - - message1.setMid(RandomUtils.nextInt()); - message1.setRid(RandomUtils.nextInt()); - - Message message2 = new Message(); - - message2.setMid(message1.getMid()); - message2.setRid(message1.getRid() + + RandomUtils.nextInt(1, 10000)); - - assertThat(message1.compareTo(message2), equalTo(-1)); - assertThat(message2.compareTo(message1), equalTo(1)); - } - - @Test - public void tagsStringShouldBeEmptyIfNoTags() { - Message message = new Message(); - - assertThat(MessageUtils.getTagsString(message), isEmptyString()); - - message.FriendsOnly = true; - - assertThat(MessageUtils.getTagsString(message), isEmptyString()); - - message.Hidden = true; - message.ReadOnly = true; - - assertThat(MessageUtils.getTagsString(message), isEmptyString()); - - message.setTags(MessageUtils.parseTags(" ")); - - assertThat(MessageUtils.getTagsString(message), isEmptyString()); - } - - @Test - public void tagsStringShouldHasNoTagDuplicates() { - Message message = new Message(); - - message.setTags(MessageUtils.parseTags("test")); - - assertThat(StringUtils.countMatches(MessageUtils.getTagsString(message), "*test"), equalTo(1)); - - message.setTags(MessageUtils.parseTags("test test")); - - assertThat(StringUtils.countMatches(MessageUtils.getTagsString(message), "*test"), equalTo(1)); - - message.setTags(MessageUtils.parseTags("test test ab test")); - - assertThat(StringUtils.countMatches(MessageUtils.getTagsString(message), "*test"), equalTo(1)); - assertThat(StringUtils.countMatches(MessageUtils.getTagsString(message), "*ab"), equalTo(1)); - } - @Test - public void markdownContentShouldNotHaveUnescapedReplyNumbersBecauseOfTelegram() { - Message msg = new Message(); - msg.setMid(1); - msg.setText("See /303 again"); - assertThat(MessageUtils.formatMarkdownText(msg), is("See [/303](https://juick.com/m/1#303) again")); - } - @Test - public void shouldNotThrowIfUrlContainsIllegalCharacters() { - String msg = "[te](http://juick.com/)[st](http://juick.com/)"; - assertThat(MessageUtils.stripNonSafeUrls(msg), is(msg)); - } - @Test - public void mentionsCount() { - Message msg = new Message(); - msg.setText("@ugnich go home"); - List<String> mentions = MessageUtils.getMentions(msg); - assertThat(mentions.size(), is(1)); - assertThat(mentions.get(0), is("@ugnich")); - msg.setText("And dick is @ugnich@jabber.zp.ua"); - assertThat(MessageUtils.getGlobalMentions(msg).size(), is(1)); - } -} diff --git a/juick-common/src/test/java/com/juick/UserTest.java b/juick-common/src/test/java/com/juick/UserTest.java deleted file mode 100644 index 13331426..00000000 --- a/juick-common/src/test/java/com/juick/UserTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.juick.test.util.MockUtils; -import org.junit.Assert; -import org.junit.Test; - -import java.io.IOException; - -public class UserTest { - @Test - public void userEqualityTest() throws IOException { - User ugnich = MockUtils.mockUser(1, "ugnich", "secret"); - String jsonUser = "{\"uid\" : 1, \"uname\": \"ugnich\"}"; - ObjectMapper jsonMapper = new ObjectMapper(); - User jsonUgnich = jsonMapper.readValue(jsonUser, User.class); - Assert.assertEquals(ugnich, jsonUgnich); - } -} diff --git a/juick-common/src/test/java/com/juick/test/util/MockUtils.java b/juick-common/src/test/java/com/juick/test/util/MockUtils.java deleted file mode 100644 index 017af4d1..00000000 --- a/juick-common/src/test/java/com/juick/test/util/MockUtils.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2008-2017, 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.test.util; - -import com.juick.Message; -import com.juick.User; -import org.apache.commons.text.RandomStringGenerator; - -import java.time.Instant; - -/** - * Created by vitalyster on 12.01.2017. - */ -public class MockUtils { - final static RandomStringGenerator generator = new RandomStringGenerator.Builder().withinRange('a', 'z').build(); - public static Message mockMessage(Integer mid, final User user, final String messageText) { - Message msg = new Message(); - - msg.setMid(mid); - msg.setUser(user); - msg.setText(messageText == null ? generator.generate(24) : messageText); - msg.setTimestamp(Instant.now()); - return msg; - } - - public static Message mockReply(Integer mid, Integer rid, final User user, Integer replyTo, final String messageText) { - Message msg = mockMessage(mid, user, messageText); - - msg.setRid(rid); - msg.setReplyto(replyTo); - return msg; - } - - public static User mockUser(final int uid, final String name, final String password) { - User user = new User(); - - user.setName(name); - user.setUid(uid); - user.setCredentials(password); - user.setBanned(false); - - return user; - } -} |