From 1c46c4ca4443bbb7345f0a9ee86c11beb007cabc Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 24 Oct 2015 17:56:52 +0300 Subject: moving to Gradle --- src/main/java/com/juick/Group.java | 29 ++++++ src/main/java/com/juick/Message.java | 173 +++++++++++++++++++++++++++++++++++ src/main/java/com/juick/Place.java | 33 +++++++ src/main/java/com/juick/Tag.java | 35 +++++++ src/main/java/com/juick/User.java | 53 +++++++++++ 5 files changed, 323 insertions(+) create mode 100644 src/main/java/com/juick/Group.java create mode 100644 src/main/java/com/juick/Message.java create mode 100644 src/main/java/com/juick/Place.java create mode 100644 src/main/java/com/juick/Tag.java create mode 100644 src/main/java/com/juick/User.java (limited to 'src/main') diff --git a/src/main/java/com/juick/Group.java b/src/main/java/com/juick/Group.java new file mode 100644 index 00000000..008d3af2 --- /dev/null +++ b/src/main/java/com/juick/Group.java @@ -0,0 +1,29 @@ +/* + * Juick + * Copyright (C) 2008-2013, Ugnich Anton + * + * 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 . + */ +package com.juick; + +/** + * + * @author Ugnich Anton + */ +public class Group { + + public String Name = null; + public int GID = 0; + public int UsersCnt = 0; +} diff --git a/src/main/java/com/juick/Message.java b/src/main/java/com/juick/Message.java new file mode 100644 index 00000000..3d2b8227 --- /dev/null +++ b/src/main/java/com/juick/Message.java @@ -0,0 +1,173 @@ +/* + * Juick + * Copyright (C) 2008-2011, Ugnich Anton + * + * 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 . + */ +package com.juick; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; + +/** + * + * @author Ugnich Anton + */ +public class Message { + + public int MID = 0; + public int RID = 0; + public int ReplyTo = 0; + public String Text = null; + public User User = null; + public ArrayList Tags = new ArrayList(); + public Date Timestamp = null; + public String TimestampString = null; + public int TimeAgo = 0; + public int Privacy = 1; + public boolean FriendsOnly = false; + public boolean ReadOnly = false; + public boolean Hidden = false; + public boolean VisitorCanComment = true; + public int Replies = 0; + public String RepliesBy = null; + public String AttachmentType = null; + public String Photo = null; + public String Video = null; + public Place Place = null; + public int Likes = 0; + public boolean UserLike = false; + public ArrayList childs = new ArrayList(); + + public Message() { + } + + public Message(Message msg) { + MID = msg.MID; + RID = msg.RID; + ReplyTo = msg.ReplyTo; + Text = msg.Text; + User = msg.User; + Tags = msg.Tags; + Timestamp = msg.Timestamp; + TimestampString = msg.TimestampString; + TimeAgo = msg.TimeAgo; + Privacy = msg.Privacy; + FriendsOnly = msg.FriendsOnly; + ReadOnly = msg.ReadOnly; + Hidden = msg.Hidden; + Replies = msg.Replies; + AttachmentType = msg.AttachmentType; + Photo = msg.Photo; + Video = msg.Video; + Place = msg.Place; + Likes = msg.Likes; + UserLike = msg.UserLike; + childs = msg.childs; + } + + public void parseTags(String strTags) { + Tags.addAll(Arrays.asList(strTags.split(" "))); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Message)) { + return false; + } + Message jmsg = (Message) obj; + return (this.MID == jmsg.MID && this.RID == jmsg.RID); + } + + public int compareTo(Object obj) throws ClassCastException { + if (!(obj instanceof Message)) { + throw new ClassCastException(); + } + Message jmsg = (Message) obj; + + if (this.MID != jmsg.MID) { + if (this.MID > jmsg.MID) { + return -1; + } else { + return 1; + } + } + + if (this.RID != jmsg.RID) { + if (this.RID < jmsg.RID) { + return -1; + } else { + return 1; + } + } + + return 0; + } + + public int getChildsCount() { + int cnt = childs.size(); + for (int i = 0; i < childs.size(); i++) { + cnt += childs.get(i).getChildsCount(); + } + return cnt; + } + + public void cleanupChilds() { + if (!childs.isEmpty()) { + for (int i = 0; i < childs.size(); i++) { + childs.get(i).cleanupChilds(); + } + childs.clear(); + } + } + + public String getAttachmentURL() { + if (AttachmentType != null) { + String url = "http://i.juick.com/"; + url += AttachmentType.equals("mp4") ? "video" : "photos-1024"; + url += "/" + MID; + if (RID > 0) { + url += "-" + RID; + } + url += "." + AttachmentType; + return url; + } else { + return null; + } + } + + public String getTagsString() { + String ret = ""; + for (int i = 0; i < Tags.size(); i++) { + ret += " *" + Tags.get(i); + } + if (FriendsOnly) { + ret += " *friends"; + } + if (Privacy == -2) { + ret += " *private"; + } + if (Privacy == -1) { + ret += " *friends"; + } + if (Privacy == 2) { + ret += " *public"; + } + if (ReadOnly) { + ret += " *readonly"; + } + return ret; + } +} diff --git a/src/main/java/com/juick/Place.java b/src/main/java/com/juick/Place.java new file mode 100644 index 00000000..7174ed6e --- /dev/null +++ b/src/main/java/com/juick/Place.java @@ -0,0 +1,33 @@ +/* + * Juick + * Copyright (C) 2008-2011, Ugnich Anton + * + * 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 . + */ +package com.juick; + +/** + * + * @author Ugnich Anton + */ +public class Place { + + public int pid = 0; + public double lat = 0; + public double lon = 0; + public String name = null; + public int users = 0; + public int messages = 0; + public int distance = 0; +} diff --git a/src/main/java/com/juick/Tag.java b/src/main/java/com/juick/Tag.java new file mode 100644 index 00000000..3cee3358 --- /dev/null +++ b/src/main/java/com/juick/Tag.java @@ -0,0 +1,35 @@ +/* + * Juick + * Copyright (C) 2008-2011, Ugnich Anton + * + * 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 . + */ +package com.juick; + +/** + * + * @author Ugnich Anton + */ +public class Tag implements Comparable { + + public String Name = null; + public int TID = 0; + public int SynonymID = 0; + public int UsageCnt = 0; + + @Override + public int compareTo(Tag o) { + return this.Name.compareTo(o.Name); + } +} diff --git a/src/main/java/com/juick/User.java b/src/main/java/com/juick/User.java new file mode 100644 index 00000000..e3fc0ae7 --- /dev/null +++ b/src/main/java/com/juick/User.java @@ -0,0 +1,53 @@ +/* + * Juick + * Copyright (C) 2008-2011, Ugnich Anton + * + * 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 . + */ +package com.juick; + +/** + * + * @author Ugnich Anton + */ +public class User { + + public int UID = 0; + public String UName = null; + public Object Avatar = null; + public String FullName = null; + public String JID = null; + public int MessagesCount = 0; + public String AuthHash = null; + public boolean Banned = false; + + public User() { + } + + public User(User u) { + UID = u.UID; + UName = u.UName; + Avatar = u.Avatar; + FullName = u.FullName; + JID = u.JID; + MessagesCount = u.MessagesCount; + AuthHash = u.AuthHash; + Banned = u.Banned; + } + + @Override + public boolean equals(Object obj) { + return (obj instanceof User && ((User) obj).UID == this.UID); + } +} -- cgit v1.2.3 From b52670824b48675cfa87a903ea155c699abd0afe Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 26 Oct 2015 17:17:08 +0300 Subject: fix tags string --- src/main/java/com/juick/Message.java | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'src/main') diff --git a/src/main/java/com/juick/Message.java b/src/main/java/com/juick/Message.java index 3d2b8227..4db2620e 100644 --- a/src/main/java/com/juick/Message.java +++ b/src/main/java/com/juick/Message.java @@ -150,23 +150,25 @@ public class Message { public String getTagsString() { String ret = ""; - for (int i = 0; i < Tags.size(); i++) { - ret += " *" + Tags.get(i); - } - if (FriendsOnly) { - ret += " *friends"; - } - if (Privacy == -2) { - ret += " *private"; - } - if (Privacy == -1) { - ret += " *friends"; - } - if (Privacy == 2) { - ret += " *public"; - } - if (ReadOnly) { - ret += " *readonly"; + if (!Tags.isEmpty()) { + for (int i = 0; i < Tags.size(); i++) { + ret += " *" + Tags.get(i); + } + if (FriendsOnly) { + ret += " *friends"; + } + if (Privacy == -2) { + ret += " *private"; + } + if (Privacy == -1) { + ret += " *friends"; + } + if (Privacy == 2) { + ret += " *public"; + } + if (ReadOnly) { + ret += " *readonly"; + } } return ret; } -- cgit v1.2.3 From 7668b411895053aebb1e6b122a9ba54301a257ba Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 4 Nov 2015 14:19:11 +0300 Subject: refactoring --- src/main/java/com/juick/Message.java | 66 +++++++++++++++++++------ src/main/java/com/juick/User.java | 62 ++++++++++++++++++----- src/test/java/com/juick/tests/MessageTests.java | 2 + 3 files changed, 103 insertions(+), 27 deletions(-) (limited to 'src/main') diff --git a/src/main/java/com/juick/Message.java b/src/main/java/com/juick/Message.java index 4db2620e..03573aed 100644 --- a/src/main/java/com/juick/Message.java +++ b/src/main/java/com/juick/Message.java @@ -27,11 +27,13 @@ import java.util.Date; */ public class Message { - public int MID = 0; - public int RID = 0; + private int MID = 0; + + private int RID = 0; + public int ReplyTo = 0; - public String Text = null; - public User User = null; + private String Text = null; + private User User = null; public ArrayList Tags = new ArrayList(); public Date Timestamp = null; public String TimestampString = null; @@ -55,11 +57,11 @@ public class Message { } public Message(Message msg) { - MID = msg.MID; - RID = msg.RID; + setMID(msg.getMID()); + setRID(msg.getRID()); ReplyTo = msg.ReplyTo; - Text = msg.Text; - User = msg.User; + setText(msg.getText()); + setUser(msg.getUser()); Tags = msg.Tags; Timestamp = msg.Timestamp; TimestampString = msg.TimestampString; @@ -88,7 +90,7 @@ public class Message { return false; } Message jmsg = (Message) obj; - return (this.MID == jmsg.MID && this.RID == jmsg.RID); + return (this.getMID() == jmsg.getMID() && this.getRID() == jmsg.getRID()); } public int compareTo(Object obj) throws ClassCastException { @@ -97,16 +99,16 @@ public class Message { } Message jmsg = (Message) obj; - if (this.MID != jmsg.MID) { - if (this.MID > jmsg.MID) { + if (this.getMID() != jmsg.getMID()) { + if (this.getMID() > jmsg.getMID()) { return -1; } else { return 1; } } - if (this.RID != jmsg.RID) { - if (this.RID < jmsg.RID) { + if (this.getRID() != jmsg.getRID()) { + if (this.getRID() < jmsg.getRID()) { return -1; } else { return 1; @@ -137,9 +139,9 @@ public class Message { if (AttachmentType != null) { String url = "http://i.juick.com/"; url += AttachmentType.equals("mp4") ? "video" : "photos-1024"; - url += "/" + MID; - if (RID > 0) { - url += "-" + RID; + url += "/" + getMID(); + if (getRID() > 0) { + url += "-" + getRID(); } url += "." + AttachmentType; return url; @@ -172,4 +174,36 @@ public class Message { } return ret; } + + 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 com.juick.User getUser() { + return User; + } + + public void setUser(com.juick.User user) { + User = user; + } + + public String getText() { + return Text; + } + + public void setText(String text) { + Text = text; + } } diff --git a/src/main/java/com/juick/User.java b/src/main/java/com/juick/User.java index e3fc0ae7..40a3df96 100644 --- a/src/main/java/com/juick/User.java +++ b/src/main/java/com/juick/User.java @@ -23,31 +23,71 @@ package com.juick; */ public class User { - public int UID = 0; - public String UName = null; + private int UID = 0; + private String UName = null; public Object Avatar = null; - public String FullName = null; - public String JID = null; + private String FullName = null; + private String JID = null; public int MessagesCount = 0; - public String AuthHash = null; + private String AuthHash = null; public boolean Banned = false; public User() { } public User(User u) { - UID = u.UID; - UName = u.UName; + setUID(u.getUID()); + setUName(u.getUName()); Avatar = u.Avatar; - FullName = u.FullName; - JID = u.JID; + setFullName(u.getFullName()); + setJID(u.getJID()); MessagesCount = u.MessagesCount; - AuthHash = u.AuthHash; + setAuthHash(u.getAuthHash()); Banned = u.Banned; } @Override public boolean equals(Object obj) { - return (obj instanceof User && ((User) obj).UID == this.UID); + return (obj instanceof User && ((User) obj).getUID() == this.getUID()); + } + + public int getUID() { + return UID; + } + + public void setUID(int UID) { + this.UID = UID; + } + + public String getUName() { + return UName; + } + + public void setUName(String UName) { + this.UName = UName; + } + + public String getFullName() { + return FullName; + } + + public void setFullName(String fullName) { + FullName = fullName; + } + + public String getJID() { + return JID; + } + + public void setJID(String JID) { + this.JID = JID; + } + + public String getAuthHash() { + return AuthHash; + } + + public void setAuthHash(String authHash) { + AuthHash = authHash; } } diff --git a/src/test/java/com/juick/tests/MessageTests.java b/src/test/java/com/juick/tests/MessageTests.java index 47b2d13c..0392c7b3 100644 --- a/src/test/java/com/juick/tests/MessageTests.java +++ b/src/test/java/com/juick/tests/MessageTests.java @@ -1,3 +1,5 @@ +package com.juick.tests; + import static org.junit.Assert.assertEquals; import org.junit.Test; -- cgit v1.2.3 From 77d86f9aaf5aa20542baa25685bb70bd77ae9b16 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 16 Jan 2016 17:37:02 +0300 Subject: fix possible NPE --- src/main/java/com/juick/Message.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/java/com/juick/Message.java b/src/main/java/com/juick/Message.java index 03573aed..ea1d550b 100644 --- a/src/main/java/com/juick/Message.java +++ b/src/main/java/com/juick/Message.java @@ -81,7 +81,9 @@ public class Message { } public void parseTags(String strTags) { - Tags.addAll(Arrays.asList(strTags.split(" "))); + if (strTags != null) { + Tags.addAll(Arrays.asList(strTags.split(" "))); + } } @Override -- cgit v1.2.3 From 15ceb8125d4f5c99af53ff0606076518aa4e292e Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 16 Jan 2016 18:23:47 +0300 Subject: do not keep date in string --- src/main/java/com/juick/Message.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/main') diff --git a/src/main/java/com/juick/Message.java b/src/main/java/com/juick/Message.java index ea1d550b..003622ec 100644 --- a/src/main/java/com/juick/Message.java +++ b/src/main/java/com/juick/Message.java @@ -35,8 +35,7 @@ public class Message { private String Text = null; private User User = null; public ArrayList Tags = new ArrayList(); - public Date Timestamp = null; - public String TimestampString = null; + private Date date = null; public int TimeAgo = 0; public int Privacy = 1; public boolean FriendsOnly = false; @@ -63,8 +62,7 @@ public class Message { setText(msg.getText()); setUser(msg.getUser()); Tags = msg.Tags; - Timestamp = msg.Timestamp; - TimestampString = msg.TimestampString; + setDate(msg.getDate()); TimeAgo = msg.TimeAgo; Privacy = msg.Privacy; FriendsOnly = msg.FriendsOnly; @@ -208,4 +206,13 @@ public class Message { public void setText(String text) { Text = text; } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + + this.date = date; + } } -- cgit v1.2.3