aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/service
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server/src/main/java/com/juick/service')
-rw-r--r--juick-server/src/main/java/com/juick/service/CrosspostService.java28
-rw-r--r--juick-server/src/main/java/com/juick/service/CrosspostServiceImpl.java120
-rw-r--r--juick-server/src/main/java/com/juick/service/MessagesService.java2
-rw-r--r--juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java2
-rw-r--r--juick-server/src/main/java/com/juick/service/TagServiceImpl.java2
-rw-r--r--juick-server/src/main/java/com/juick/service/UserService.java6
-rw-r--r--juick-server/src/main/java/com/juick/service/UserServiceImpl.java19
7 files changed, 176 insertions, 3 deletions
diff --git a/juick-server/src/main/java/com/juick/service/CrosspostService.java b/juick-server/src/main/java/com/juick/service/CrosspostService.java
index 725ef297..812d798f 100644
--- a/juick-server/src/main/java/com/juick/service/CrosspostService.java
+++ b/juick-server/src/main/java/com/juick/service/CrosspostService.java
@@ -29,4 +29,32 @@ public interface CrosspostService {
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);
+
+ boolean setUserRef(int uid, int ref);
+
+ 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-server/src/main/java/com/juick/service/CrosspostServiceImpl.java b/juick-server/src/main/java/com/juick/service/CrosspostServiceImpl.java
index df748526..4b3bd618 100644
--- a/juick-server/src/main/java/com/juick/service/CrosspostServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/CrosspostServiceImpl.java
@@ -3,6 +3,7 @@ package com.juick.service;
import com.juick.server.helpers.ApplicationStatus;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
+import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
@@ -129,4 +130,123 @@ public class CrosspostServiceImpl extends BaseJdbcService implements CrosspostSe
public void deleteVKUser(Integer uid) {
getJdbcTemplate().update("DELETE FROM vk WHERE user_id=?", uid);
}
+
+ @Transactional(readOnly = true)
+ @Override
+ public int getUIDbyFBID(long fbID) {
+ try {
+ return getJdbcTemplate().queryForObject("SELECT user_id FROM facebook WHERE fb_id=? AND user_id IS NOT NULL",
+ Integer.class, fbID);
+ } catch (EmptyResultDataAccessException e) {
+ return 0;
+ }
+ }
+
+ @Transactional
+ @Override
+ public boolean createFacebookUser(long fbID, String loginhash, String token, String fbName, String fbLink) {
+ return getJdbcTemplate().update("INSERT INTO facebook(fb_id,loginhash,access_token,fb_name,fb_link) VALUES (?,?,?,?,?)",
+ fbID, loginhash, token, fbName, fbLink) > 0;
+ }
+
+ @Transactional
+ @Override
+ public boolean updateFacebookUser(long fbID, String token, String fbName, String fbLink) {
+ return getJdbcTemplate().update("UPDATE facebook SET access_token=?,fb_name=?,fb_link=? WHERE fb_id=?",
+ token, fbName, fbLink, fbID) > 0;
+ }
+
+ @Transactional(readOnly = true)
+ @Override
+ public int getUIDbyVKID(long vkID) {
+ try {
+ return getJdbcTemplate().queryForObject("SELECT user_id FROM vk WHERE vk_id=? AND user_id IS NOT NULL", Integer.class, vkID);
+ } catch (EmptyResultDataAccessException e) {
+ return 0;
+ }
+ }
+
+ @Transactional
+ @Override
+ public boolean createVKUser(long vkID, String loginhash, String token, String vkName, String vkLink) {
+ return getJdbcTemplate().update("INSERT INTO vk(vk_id,loginhash,access_token,vk_name,vk_link) VALUES (?,?,?,?,?)",
+ vkID, loginhash, token, vkName, vkLink) > 0;
+ }
+
+ @Transactional
+ @Override
+ public boolean setUserRef(int uid, int ref) {
+ return getJdbcTemplate().update("INSERT INTO users_refs(user_id,ref) VALUES (?,?)", uid, ref) > 0;
+ }
+
+ @Transactional(readOnly = true)
+ @Override
+ public String getFacebookNameByHash(String hash) {
+ try {
+ List<Pair<String, String>> fb = getJdbcTemplate().query("SELECT fb_name,fb_link FROM facebook WHERE loginhash=?",
+ (rs, num) -> Pair.of(rs.getString(1), rs.getString(2)), hash);
+ if (fb.size() > 0) {
+ return "<a href=\"" + fb.get(0).getRight() + "\" rel=\"nofollow\">" + fb.get(0).getLeft() + "</a>";
+ }
+ return null;
+ } catch (EmptyResultDataAccessException e) {
+ return null;
+ }
+ }
+
+ @Transactional
+ @Override
+ public String getTelegramNameByHash(String hash) {
+ try {
+ String name = getJdbcTemplate().queryForObject("SELECT tg_name FROM telegram WHERE loginhash=?", String.class, hash);
+ return "<a href=\"https://telegram.me/" + name + "\" rel=\"nofollow\">" + name + "</a>";
+ } catch (EmptyResultDataAccessException e) {
+ return null;
+ }
+ }
+
+ @Transactional
+ @Override
+ public boolean setFacebookUser(String hash, int uid) {
+ return getJdbcTemplate().update("UPDATE facebook SET user_id=?,loginhash=NULL WHERE loginhash=?", uid, hash) > 0;
+ }
+
+ @Transactional
+ @Override
+ public String getVKNameByHash(String hash) {
+ List<Pair<String, String>> logins = getJdbcTemplate().query("SELECT vk_name,vk_link FROM vk WHERE loginhash=?",
+ (rs, num) -> Pair.of(rs.getString(1), rs.getString(2)), hash);
+ if (logins.size() > 0) {
+ return "<a href=\"http://vk.com/" + logins.get(0).getRight() + "\" rel=\"nofollow\">" + logins.get(0).getLeft() + "</a>";
+ }
+ return null;
+ }
+
+ @Transactional
+ @Override
+ public boolean setVKUser(String hash, int uid) {
+ return getJdbcTemplate().update("UPDATE vk SET user_id=?,loginhash=NULL WHERE loginhash=?", uid, hash) > 0;
+ }
+
+ @Transactional
+ @Override
+ public boolean setTelegramUser(String hash, int uid) {
+ return getJdbcTemplate().update("UPDATE telegram SET user_id=?,loginhash=NULL WHERE loginhash=?", uid, hash) > 0;
+ }
+
+ @Transactional(readOnly = true)
+ @Override
+ public String getJIDByHash(String hash) {
+ try {
+ return getJdbcTemplate().queryForObject("SELECT jid FROM jids WHERE loginhash=?", String.class, hash);
+ } catch (EmptyResultDataAccessException e) {
+ return null;
+ }
+ }
+
+ @Transactional
+ @Override
+ public boolean setJIDUser(String hash, int uid) {
+ return getJdbcTemplate().update("UPDATE jids SET user_id=?,loginhash=NULL WHERE loginhash=?", uid, hash) > 0;
+ }
}
diff --git a/juick-server/src/main/java/com/juick/service/MessagesService.java b/juick-server/src/main/java/com/juick/service/MessagesService.java
index 8cb0782f..284b2018 100644
--- a/juick-server/src/main/java/com/juick/service/MessagesService.java
+++ b/juick-server/src/main/java/com/juick/service/MessagesService.java
@@ -66,7 +66,7 @@ public interface MessagesService {
List<Integer> getUserPhotos(int uid, int privacy, int before);
- List<Integer> getUserSearch(JdbcTemplate sqlSearch, int UID, String search, int privacy, int before);
+ List<Integer> getUserSearch(int UID, String search, int privacy, int before);
List<com.juick.Message> getMessages(Collection<Integer> mids);
diff --git a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
index 1ad29d00..736919a4 100644
--- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -627,7 +627,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
@Transactional(readOnly = true)
@Override
- public List<Integer> getUserSearch(final JdbcTemplate sqlSearch, final int UID, final String search, final int privacy, final int before) {
+ public List<Integer> getUserSearch(final int UID, final String search, final int privacy, final int before) {
List<Integer> mids = searchService.searchByStringAndUser(search, UID, before);
if (!mids.isEmpty()) {
diff --git a/juick-server/src/main/java/com/juick/service/TagServiceImpl.java b/juick-server/src/main/java/com/juick/service/TagServiceImpl.java
index 77100f1e..66566872 100644
--- a/juick-server/src/main/java/com/juick/service/TagServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/TagServiceImpl.java
@@ -103,7 +103,7 @@ public class TagServiceImpl extends BaseJdbcService implements TagService {
}
}
- return ret;
+ return ret.stream().distinct().collect(Collectors.toList());
}
@Transactional(readOnly = true)
diff --git a/juick-server/src/main/java/com/juick/service/UserService.java b/juick-server/src/main/java/com/juick/service/UserService.java
index 3fb2ae12..166cfeeb 100644
--- a/juick-server/src/main/java/com/juick/service/UserService.java
+++ b/juick-server/src/main/java/com/juick/service/UserService.java
@@ -115,4 +115,10 @@ public interface UserService {
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);
}
diff --git a/juick-server/src/main/java/com/juick/service/UserServiceImpl.java b/juick-server/src/main/java/com/juick/service/UserServiceImpl.java
index f226b402..05ef4c95 100644
--- a/juick-server/src/main/java/com/juick/service/UserServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/UserServiceImpl.java
@@ -674,4 +674,23 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
.addValue("hash", loginHash)
.addValue("uid", uid));
}
+
+ @Transactional
+ @Override
+ public void logout(int uid) {
+ getJdbcTemplate().update("DELETE FROM logins WHERE user_id=?", uid);
+ }
+
+ @Transactional
+ @Override
+ public boolean deleteJID(int uid, String jid) {
+ return getJdbcTemplate().update("DELETE FROM jids WHERE user_id=? AND jid=?", uid, jid) > 0;
+ }
+
+ @Transactional
+ @Override
+ public boolean unauthJID(int uid, String jid) {
+ return getJdbcTemplate()
+ .update("DELETE FROM auth WHERE user_id=? AND protocol='xmpp' AND account=?", uid, jid) > 0;
+ }
}