From bf5f2142d73a5745124d03f6b6f06c59873e47de Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 27 Dec 2017 16:23:28 +0300 Subject: Messenger bot --- juick-api/build.gradle | 1 + .../src/main/java/com/juick/api/MessengerBot.java | 33 - .../main/java/com/juick/api/MessengerManager.java | 143 ++++ .../juick/api/configuration/ApiInitializer.java | 2 +- .../api/configuration/MessengerConfiguration.java | 39 - .../juick/api/controllers/MessengerWebhook.java | 11 +- .../src/main/java/com/juick/service/Crosspost.java | 3 +- .../juick/service/rest/CrosspostRestService.java | 4 +- .../java/com/juick/service/CrosspostService.java | 2 +- .../java/com/juick/service/MessengerService.java | 14 + .../com/juick/service/CrosspostServiceImpl.java | 10 +- .../com/juick/service/MessengerServiceImpl.java | 77 ++ juick-www/package-lock.json | 912 --------------------- .../java/com/juick/www/controllers/NewMessage.java | 2 +- .../java/com/juick/www/controllers/SignUp.java | 12 +- 15 files changed, 263 insertions(+), 1002 deletions(-) delete mode 100644 juick-api/src/main/java/com/juick/api/MessengerBot.java create mode 100644 juick-api/src/main/java/com/juick/api/MessengerManager.java delete mode 100644 juick-api/src/main/java/com/juick/api/configuration/MessengerConfiguration.java create mode 100644 juick-server-core/src/main/java/com/juick/service/MessengerService.java create mode 100644 juick-server-jdbc/src/main/java/com/juick/service/MessengerServiceImpl.java diff --git a/juick-api/build.gradle b/juick-api/build.gradle index db2f080b..39475d94 100644 --- a/juick-api/build.gradle +++ b/juick-api/build.gradle @@ -16,6 +16,7 @@ dependencies { compile 'io.springfox:springfox-swagger-ui:2.7.0' compile 'com.github.pengrad:java-telegram-bot-api:3.5.2' + compile 'com.github.messenger4j:messenger4j:1.0.0-M2' compile 'org.apache.commons:commons-email:1.5' compile 'org.imgscalr:imgscalr-lib:4.2' diff --git a/juick-api/src/main/java/com/juick/api/MessengerBot.java b/juick-api/src/main/java/com/juick/api/MessengerBot.java deleted file mode 100644 index 8a568c42..00000000 --- a/juick-api/src/main/java/com/juick/api/MessengerBot.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 . - */ - -package com.juick.api; - -/** - * Created by vitalyster on 27.03.2017. - */ -public class MessengerBot { - private String verifyToken; - - public String getVerifyToken() { - return verifyToken; - } - - public void setVerifyToken(String verifyToken) { - this.verifyToken = verifyToken; - } -} diff --git a/juick-api/src/main/java/com/juick/api/MessengerManager.java b/juick-api/src/main/java/com/juick/api/MessengerManager.java new file mode 100644 index 00000000..9587dc11 --- /dev/null +++ b/juick-api/src/main/java/com/juick/api/MessengerManager.java @@ -0,0 +1,143 @@ +package com.juick.api; + +import com.github.messenger4j.Messenger; +import com.github.messenger4j.exception.MessengerApiException; +import com.github.messenger4j.exception.MessengerIOException; +import com.github.messenger4j.exception.MessengerVerificationException; +import com.github.messenger4j.send.MessagePayload; +import com.github.messenger4j.send.message.TemplateMessage; +import com.github.messenger4j.send.message.TextMessage; +import com.github.messenger4j.send.message.template.ButtonTemplate; +import com.github.messenger4j.send.message.template.button.UrlButton; +import com.github.messenger4j.userprofile.UserProfile; +import com.github.messenger4j.webhook.event.TextMessageEvent; +import com.juick.Message; +import com.juick.User; +import com.juick.server.component.MessageEvent; +import com.juick.service.MessagesService; +import com.juick.service.MessengerService; +import com.juick.service.SubscriptionService; +import com.juick.service.UserService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.ApplicationListener; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; + +import javax.annotation.Nonnull; +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import java.net.MalformedURLException; +import java.net.URL; +import java.time.Instant; +import java.util.Collections; +import java.util.Optional; + +import static com.juick.formatters.PlainTextFormatter.formatPost; +import static com.juick.formatters.PlainTextFormatter.formatUrl; + +@Component +public class MessengerManager implements ApplicationListener { + private static final Logger logger = LoggerFactory.getLogger(MessengerManager.class); + @Inject + private MessagesService messagesService; + @Inject + private SubscriptionService subscriptionService; + @Inject + private UserService userService; + @Inject + private MessengerService messengerService; + @Inject + private ApiServer apiServer; + + @Value("${fb_page_access_token}") + private String facebookPageAccessToken; + @Value("${fb_verify_token}") + private String facebookVerifyToken; + @Value("${fb_secret}") + private String facebookSecret; + + private Messenger messenger; + + @PostConstruct + public void init() { + messenger = Messenger.create(facebookPageAccessToken, facebookSecret, facebookVerifyToken); + } + + public String getFacebookVerifyToken() { + return facebookVerifyToken; + } + + public void processUpdate(String signature , String data) throws MessengerVerificationException { + messenger.onReceiveEvents(data, Optional.of(signature), event -> { + final String senderId = event.senderId(); + final Instant timestamp = event.timestamp(); + + User user_from = userService.getUserByUID(messengerService.getUserId(senderId)).orElse(new User()); + logger.info("Found juick user {}", user_from.getUid()); + if (user_from.getUid() == 0) { + try { + UserProfile profile = messenger.queryUserProfile(senderId); + signupNotify(senderId, messengerService.getSignUpHash(senderId, profile.firstName())); + } catch (MessengerApiException | MessengerIOException | MalformedURLException e) { + logger.warn("messenger profile error", e); + try { + signupNotify(senderId, messengerService.getSignUpHash(senderId, "anonymous")); + } catch (MalformedURLException | MessengerApiException | MessengerIOException e1) { + logger.warn("signup error", e1); + } + } + } else { + if (event.isTextMessageEvent()) { + final TextMessageEvent textMessageEvent = event.asTextMessageEvent(); + final String messageId = textMessageEvent.messageId(); + final String text = textMessageEvent.text(); + logger.info("Received text message from '{}' at '{}' with content: {} (mid: {})", + senderId, timestamp, text, messageId); + apiServer.processMessage(user_from, text, null); + messengerNotify(senderId, "Message sent", null); + } + } + }); + } + + @Override + public void onApplicationEvent(@Nonnull MessageEvent event) { + Message msg = event.getMessage(); + if (msg.getRid() == 0) { + String subject = formatPost(msg); + subscriptionService.getSubscribedUsers(msg.getUser().getUid(), msg.getMid()) + .forEach(user -> messengerService.getSenderId(user) + .ifPresent(t -> messengerNotify(t, subject, formatUrl(msg)))); + } else { + // get quote + com.juick.Message jmsg = messagesService.getReply(msg.getMid(), msg.getRid()); + String subject = formatPost(jmsg); + subscriptionService.getUsersSubscribedToComments(msg.getMid(), msg.getUser().getUid()) + .forEach(user -> messengerService.getSenderId(user) + .ifPresent(t -> messengerNotify(t, subject, formatUrl(jmsg)))); + } + } + + void messengerNotify(String messengerUser, String text, String url) { + try { + if (!StringUtils.isEmpty(url)) { + final UrlButton showMessage = UrlButton.create("VIEW MESSAGE", new URL(url)); + ButtonTemplate template = ButtonTemplate.create(text, Collections.singletonList(showMessage)); + messenger.send(MessagePayload.create(messengerUser, TemplateMessage.create(template))); + } else { + messenger.send(MessagePayload.create(messengerUser, TextMessage.create(text))); + } + } catch (MessengerApiException | MessengerIOException | MalformedURLException e) { + logger.warn("messenger error", e); + } + } + void signupNotify(String messengerUser, String hash) throws MalformedURLException, MessengerApiException, MessengerIOException { + final UrlButton urlButton = UrlButton.create("LOGIN", + new URL("https://juick.com/signup?type=messenger&hash=" + hash)); + ButtonTemplate template = ButtonTemplate.create("Login to receive notifications", + Collections.singletonList(urlButton)); + messenger.send(MessagePayload.create(messengerUser, TemplateMessage.create(template))); + } +} diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java b/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java index 3380df10..32a88a0c 100644 --- a/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java +++ b/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java @@ -43,7 +43,7 @@ public class ApiInitializer extends AbstractAnnotationConfigDispatcherServletIni @Override protected Class[] getServletConfigClasses() { - return new Class[]{ MessengerConfiguration.class }; + return null; } @Override diff --git a/juick-api/src/main/java/com/juick/api/configuration/MessengerConfiguration.java b/juick-api/src/main/java/com/juick/api/configuration/MessengerConfiguration.java deleted file mode 100644 index a9f07af4..00000000 --- a/juick-api/src/main/java/com/juick/api/configuration/MessengerConfiguration.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 . - */ - -package com.juick.api.configuration; - -import com.juick.api.MessengerBot; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * Created by vital on 28.03.2017. - */ -@Configuration -public class MessengerConfiguration { - @Value("${fb_verify_token}") - private String messengerBotVerifyToken; - - @Bean - public MessengerBot fbBot() { - MessengerBot bot = new MessengerBot(); - bot.setVerifyToken(messengerBotVerifyToken); - return bot; - } -} diff --git a/juick-api/src/main/java/com/juick/api/controllers/MessengerWebhook.java b/juick-api/src/main/java/com/juick/api/controllers/MessengerWebhook.java index fa57c017..835165ba 100644 --- a/juick-api/src/main/java/com/juick/api/controllers/MessengerWebhook.java +++ b/juick-api/src/main/java/com/juick/api/controllers/MessengerWebhook.java @@ -17,7 +17,8 @@ package com.juick.api.controllers; -import com.juick.api.MessengerBot; +import com.github.messenger4j.exception.MessengerVerificationException; +import com.juick.api.MessengerManager; import com.juick.server.util.HttpForbiddenException; import org.apache.commons.io.IOUtils; import org.slf4j.Logger; @@ -41,21 +42,21 @@ public class MessengerWebhook { private static Logger logger = LoggerFactory.getLogger(MessengerWebhook.class); @Inject - MessengerBot fbBot; + private MessengerManager messengerManager; @RequestMapping(value = "/fbwbhk", method = RequestMethod.GET) public ResponseEntity verifyHook(@RequestParam(name = "hub.mode") String hubMode, @RequestParam(name = "hub.challenge") Integer hubChallenge, @RequestParam(name = "hub.verify_token") String verifyToken) { - if (hubMode.equals("subscribe") && verifyToken.equals(fbBot.getVerifyToken())) { + if (hubMode.equals("subscribe") && verifyToken.equals(messengerManager.getFacebookVerifyToken())) { return new ResponseEntity<>(hubChallenge, HttpStatus.OK); } throw new HttpForbiddenException(); } @RequestMapping(value = "/fbwbhk", method = RequestMethod.POST) @ResponseStatus(value = HttpStatus.OK) - public void processUpdate(InputStream body) throws IOException { + public void processUpdate(@RequestHeader(name = "X-Hub-Signature", required = false) String signature, InputStream body) throws IOException, MessengerVerificationException { String data = IOUtils.toString(body, StandardCharsets.UTF_8); - logger.info("got data: {}", data); + messengerManager.processUpdate(signature, data); } } diff --git a/juick-crosspost/src/main/java/com/juick/service/Crosspost.java b/juick-crosspost/src/main/java/com/juick/service/Crosspost.java index 55c4407c..7fcb9a52 100644 --- a/juick-crosspost/src/main/java/com/juick/service/Crosspost.java +++ b/juick-crosspost/src/main/java/com/juick/service/Crosspost.java @@ -68,7 +68,8 @@ public class Crosspost implements ApplicationListener { } public boolean facebookPost(final com.juick.Message jmsg) { - String token = crosspostService.getFacebookToken(jmsg.getUser().getUid()).orElse(StringUtils.EMPTY); + String token = crosspostService.getFacebookTokens(jmsg.getUser().getUid()) + .orElse(Pair.of(StringUtils.EMPTY, StringUtils.EMPTY)).getRight(); if (token.isEmpty()) { return false; } diff --git a/juick-crosspost/src/main/java/com/juick/service/rest/CrosspostRestService.java b/juick-crosspost/src/main/java/com/juick/service/rest/CrosspostRestService.java index 52b72c3f..dbc0bdc9 100644 --- a/juick-crosspost/src/main/java/com/juick/service/rest/CrosspostRestService.java +++ b/juick-crosspost/src/main/java/com/juick/service/rest/CrosspostRestService.java @@ -33,8 +33,8 @@ public class CrosspostRestService implements CrosspostService { } @Override - public Optional getFacebookToken(int uid) { - return null; + public Optional> getFacebookTokens(int uid) { + return Optional.empty(); } @Override diff --git a/juick-server-core/src/main/java/com/juick/service/CrosspostService.java b/juick-server-core/src/main/java/com/juick/service/CrosspostService.java index 2ece8305..b82621e5 100644 --- a/juick-server-core/src/main/java/com/juick/service/CrosspostService.java +++ b/juick-server-core/src/main/java/com/juick/service/CrosspostService.java @@ -33,7 +33,7 @@ public interface CrosspostService { boolean deleteTwitterToken(Integer uid); - Optional getFacebookToken(int uid); + Optional> getFacebookTokens(int uid); ApplicationStatus getFbCrossPostStatus(int uid); diff --git a/juick-server-core/src/main/java/com/juick/service/MessengerService.java b/juick-server-core/src/main/java/com/juick/service/MessengerService.java new file mode 100644 index 00000000..e07c73fe --- /dev/null +++ b/juick-server-core/src/main/java/com/juick/service/MessengerService.java @@ -0,0 +1,14 @@ +package com.juick.service; + +import com.juick.User; + +import java.util.Optional; + +public interface MessengerService { + Integer getUserId(String senderId); + Optional 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-server-jdbc/src/main/java/com/juick/service/CrosspostServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/CrosspostServiceImpl.java index dec8db5b..fb9ef167 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/CrosspostServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/CrosspostServiceImpl.java @@ -63,13 +63,13 @@ public class CrosspostServiceImpl extends BaseJdbcService implements CrosspostSe @Transactional(readOnly = true) @Override - public Optional getFacebookToken(final int uid) { - List list = getJdbcTemplate().queryForList( - "SELECT access_token FROM facebook WHERE user_id = ? AND access_token IS NOT NULL AND crosspost = 1", - String.class, + public Optional> getFacebookTokens(final int uid) { + List>> list = getJdbcTemplate().query( + "SELECT fb_id, access_token FROM facebook WHERE user_id = ? AND access_token IS NOT NULL AND crosspost = 1", + (rs, num) -> Optional.of(Pair.of(rs.getString(1), rs.getString(2))), uid); return list.isEmpty() ? - Optional.empty() : Optional.of(list.get(0)); + Optional.empty() : list.get(0); } @Transactional(readOnly = true) diff --git a/juick-server-jdbc/src/main/java/com/juick/service/MessengerServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/MessengerServiceImpl.java new file mode 100644 index 00000000..fe7165b3 --- /dev/null +++ b/juick-server-jdbc/src/main/java/com/juick/service/MessengerServiceImpl.java @@ -0,0 +1,77 @@ +package com.juick.service; + +import com.juick.User; +import org.springframework.dao.EmptyResultDataAccessException; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + +import javax.inject.Inject; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +@Repository +public class MessengerServiceImpl extends BaseJdbcService implements MessengerService { + @Inject + protected MessengerServiceImpl(JdbcTemplate jdbcTemplate) { + super(jdbcTemplate, null); + } + + @Transactional(readOnly = true) + @Override + public Integer getUserId(String senderId) { + List list = getJdbcTemplate().queryForList( + "SELECT id FROM users INNER JOIN messenger " + + "ON messenger.user_id = users.id WHERE messenger.sender_id=?", Integer.class, senderId); + + return list.isEmpty() ? 0 : list.get(0); + } + @Transactional(readOnly = true) + @Override + public Optional getSenderId(User user) { + List list = getJdbcTemplate().queryForList( + "SELECT sender_id FROM messenger " + + "WHERE user_id=?", String.class, user.getUid()); + + return list.isEmpty() ? Optional.empty() : Optional.of(list.get(0)); + } + + @Transactional + @Override + public boolean createMessengerUser(String senderId, String displayName) { + return getJdbcTemplate().update( + "INSERT INTO messenger(sender_id, display_name, loginhash) VALUES(?,?,?)", + senderId, displayName, UUID.randomUUID().toString()) > 0; + } + @Transactional(readOnly = true) + @Override + public String getDisplayName(String hash) { + try { + return getJdbcTemplate().queryForObject("SELECT display_name FROM messenger WHERE loginhash=?", String.class, hash); + } catch (EmptyResultDataAccessException e) { + return null; + } + } + @Transactional + @Override + public String getSignUpHash(final String senderId, final String username) { + List list = getJdbcTemplate().queryForList( + "SELECT loginhash FROM messenger WHERE sender_id = ? AND user_id IS NULL", + String.class, + senderId); + + if (list.isEmpty()) { + String hash = UUID.randomUUID().toString(); + getJdbcTemplate().update( + "INSERT INTO messenger(sender_id, loginhash, display_name) VALUES (?, ?, ?)", senderId, hash, username); + return hash; + } + return list.get(0); + } + @Transactional + @Override + public boolean linkMessengerUser(String hash, int uid) { + return getJdbcTemplate().update("UPDATE messenger SET user_id=?, loginhash=NULL WHERE loginhash=?", uid, hash) > 0; + } +} diff --git a/juick-www/package-lock.json b/juick-www/package-lock.json index c4c58e88..a0bc404b 100644 --- a/juick-www/package-lock.json +++ b/juick-www/package-lock.json @@ -1489,7 +1489,6 @@ "requires": { "anymatch": "1.3.2", "async-each": "1.0.1", - "fsevents": "1.1.3", "glob-parent": "2.0.0", "inherits": "2.0.3", "is-binary-path": "1.0.1", @@ -3753,910 +3752,6 @@ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, - "fsevents": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.1.3.tgz", - "integrity": "sha512-WIr7iDkdmdbxu/Gh6eKEZJL6KPE74/5MEsf2whTOFNxbIoIixogroLdKYqB6FDav4Wavh/lZdzzd3b2KxIXC5Q==", - "dev": true, - "optional": true, - "requires": { - "nan": "2.8.0", - "node-pre-gyp": "0.6.39" - }, - "dependencies": { - "abbrev": { - "version": "1.1.0", - "bundled": true, - "dev": true, - "optional": true - }, - "ajv": { - "version": "4.11.8", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "co": "4.6.0", - "json-stable-stringify": "1.0.1" - } - }, - "ansi-regex": { - "version": "2.1.1", - "bundled": true, - "dev": true - }, - "aproba": { - "version": "1.1.1", - "bundled": true, - "dev": true, - "optional": true - }, - "are-we-there-yet": { - "version": "1.1.4", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "delegates": "1.0.0", - "readable-stream": "2.2.9" - } - }, - "asn1": { - "version": "0.2.3", - "bundled": true, - "dev": true, - "optional": true - }, - "assert-plus": { - "version": "0.2.0", - "bundled": true, - "dev": true, - "optional": true - }, - "asynckit": { - "version": "0.4.0", - "bundled": true, - "dev": true, - "optional": true - }, - "aws-sign2": { - "version": "0.6.0", - "bundled": true, - "dev": true, - "optional": true - }, - "aws4": { - "version": "1.6.0", - "bundled": true, - "dev": true, - "optional": true - }, - "balanced-match": { - "version": "0.4.2", - "bundled": true, - "dev": true - }, - "bcrypt-pbkdf": { - "version": "1.0.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "tweetnacl": "0.14.5" - } - }, - "block-stream": { - "version": "0.0.9", - "bundled": true, - "dev": true, - "requires": { - "inherits": "2.0.3" - } - }, - "boom": { - "version": "2.10.1", - "bundled": true, - "dev": true, - "requires": { - "hoek": "2.16.3" - } - }, - "brace-expansion": { - "version": "1.1.7", - "bundled": true, - "dev": true, - "requires": { - "balanced-match": "0.4.2", - "concat-map": "0.0.1" - } - }, - "buffer-shims": { - "version": "1.0.0", - "bundled": true, - "dev": true - }, - "caseless": { - "version": "0.12.0", - "bundled": true, - "dev": true, - "optional": true - }, - "co": { - "version": "4.6.0", - "bundled": true, - "dev": true, - "optional": true - }, - "code-point-at": { - "version": "1.1.0", - "bundled": true, - "dev": true - }, - "combined-stream": { - "version": "1.0.5", - "bundled": true, - "dev": true, - "requires": { - "delayed-stream": "1.0.0" - } - }, - "concat-map": { - "version": "0.0.1", - "bundled": true, - "dev": true - }, - "console-control-strings": { - "version": "1.1.0", - "bundled": true, - "dev": true - }, - "core-util-is": { - "version": "1.0.2", - "bundled": true, - "dev": true - }, - "cryptiles": { - "version": "2.0.5", - "bundled": true, - "dev": true, - "requires": { - "boom": "2.10.1" - } - }, - "dashdash": { - "version": "1.14.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "assert-plus": "1.0.0" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - } - } - }, - "debug": { - "version": "2.6.8", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "ms": "2.0.0" - } - }, - "deep-extend": { - "version": "0.4.2", - "bundled": true, - "dev": true, - "optional": true - }, - "delayed-stream": { - "version": "1.0.0", - "bundled": true, - "dev": true - }, - "delegates": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - }, - "detect-libc": { - "version": "1.0.2", - "bundled": true, - "dev": true, - "optional": true - }, - "ecc-jsbn": { - "version": "0.1.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "jsbn": "0.1.1" - } - }, - "extend": { - "version": "3.0.1", - "bundled": true, - "dev": true, - "optional": true - }, - "extsprintf": { - "version": "1.0.2", - "bundled": true, - "dev": true - }, - "forever-agent": { - "version": "0.6.1", - "bundled": true, - "dev": true, - "optional": true - }, - "form-data": { - "version": "2.1.4", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "asynckit": "0.4.0", - "combined-stream": "1.0.5", - "mime-types": "2.1.15" - } - }, - "fs.realpath": { - "version": "1.0.0", - "bundled": true, - "dev": true - }, - "fstream": { - "version": "1.0.11", - "bundled": true, - "dev": true, - "requires": { - "graceful-fs": "4.1.11", - "inherits": "2.0.3", - "mkdirp": "0.5.1", - "rimraf": "2.6.1" - } - }, - "fstream-ignore": { - "version": "1.0.5", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "fstream": "1.0.11", - "inherits": "2.0.3", - "minimatch": "3.0.4" - } - }, - "gauge": { - "version": "2.7.4", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "aproba": "1.1.1", - "console-control-strings": "1.1.0", - "has-unicode": "2.0.1", - "object-assign": "4.1.1", - "signal-exit": "3.0.2", - "string-width": "1.0.2", - "strip-ansi": "3.0.1", - "wide-align": "1.1.2" - } - }, - "getpass": { - "version": "0.1.7", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "assert-plus": "1.0.0" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - } - } - }, - "glob": { - "version": "7.1.2", - "bundled": true, - "dev": true, - "requires": { - "fs.realpath": "1.0.0", - "inflight": "1.0.6", - "inherits": "2.0.3", - "minimatch": "3.0.4", - "once": "1.4.0", - "path-is-absolute": "1.0.1" - } - }, - "graceful-fs": { - "version": "4.1.11", - "bundled": true, - "dev": true - }, - "har-schema": { - "version": "1.0.5", - "bundled": true, - "dev": true, - "optional": true - }, - "har-validator": { - "version": "4.2.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "ajv": "4.11.8", - "har-schema": "1.0.5" - } - }, - "has-unicode": { - "version": "2.0.1", - "bundled": true, - "dev": true, - "optional": true - }, - "hawk": { - "version": "3.1.3", - "bundled": true, - "dev": true, - "requires": { - "boom": "2.10.1", - "cryptiles": "2.0.5", - "hoek": "2.16.3", - "sntp": "1.0.9" - } - }, - "hoek": { - "version": "2.16.3", - "bundled": true, - "dev": true - }, - "http-signature": { - "version": "1.1.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "assert-plus": "0.2.0", - "jsprim": "1.4.0", - "sshpk": "1.13.0" - } - }, - "inflight": { - "version": "1.0.6", - "bundled": true, - "dev": true, - "requires": { - "once": "1.4.0", - "wrappy": "1.0.2" - } - }, - "inherits": { - "version": "2.0.3", - "bundled": true, - "dev": true - }, - "ini": { - "version": "1.3.4", - "bundled": true, - "dev": true, - "optional": true - }, - "is-fullwidth-code-point": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "requires": { - "number-is-nan": "1.0.1" - } - }, - "is-typedarray": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - }, - "isarray": { - "version": "1.0.0", - "bundled": true, - "dev": true - }, - "isstream": { - "version": "0.1.2", - "bundled": true, - "dev": true, - "optional": true - }, - "jodid25519": { - "version": "1.0.2", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "jsbn": "0.1.1" - } - }, - "jsbn": { - "version": "0.1.1", - "bundled": true, - "dev": true, - "optional": true - }, - "json-schema": { - "version": "0.2.3", - "bundled": true, - "dev": true, - "optional": true - }, - "json-stable-stringify": { - "version": "1.0.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "jsonify": "0.0.0" - } - }, - "json-stringify-safe": { - "version": "5.0.1", - "bundled": true, - "dev": true, - "optional": true - }, - "jsonify": { - "version": "0.0.0", - "bundled": true, - "dev": true, - "optional": true - }, - "jsprim": { - "version": "1.4.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "assert-plus": "1.0.0", - "extsprintf": "1.0.2", - "json-schema": "0.2.3", - "verror": "1.3.6" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - } - } - }, - "mime-db": { - "version": "1.27.0", - "bundled": true, - "dev": true - }, - "mime-types": { - "version": "2.1.15", - "bundled": true, - "dev": true, - "requires": { - "mime-db": "1.27.0" - } - }, - "minimatch": { - "version": "3.0.4", - "bundled": true, - "dev": true, - "requires": { - "brace-expansion": "1.1.7" - } - }, - "minimist": { - "version": "0.0.8", - "bundled": true, - "dev": true - }, - "mkdirp": { - "version": "0.5.1", - "bundled": true, - "dev": true, - "requires": { - "minimist": "0.0.8" - } - }, - "ms": { - "version": "2.0.0", - "bundled": true, - "dev": true, - "optional": true - }, - "node-pre-gyp": { - "version": "0.6.39", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "detect-libc": "1.0.2", - "hawk": "3.1.3", - "mkdirp": "0.5.1", - "nopt": "4.0.1", - "npmlog": "4.1.0", - "rc": "1.2.1", - "request": "2.81.0", - "rimraf": "2.6.1", - "semver": "5.3.0", - "tar": "2.2.1", - "tar-pack": "3.4.0" - } - }, - "nopt": { - "version": "4.0.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "abbrev": "1.1.0", - "osenv": "0.1.4" - } - }, - "npmlog": { - "version": "4.1.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "are-we-there-yet": "1.1.4", - "console-control-strings": "1.1.0", - "gauge": "2.7.4", - "set-blocking": "2.0.0" - } - }, - "number-is-nan": { - "version": "1.0.1", - "bundled": true, - "dev": true - }, - "oauth-sign": { - "version": "0.8.2", - "bundled": true, - "dev": true, - "optional": true - }, - "object-assign": { - "version": "4.1.1", - "bundled": true, - "dev": true, - "optional": true - }, - "once": { - "version": "1.4.0", - "bundled": true, - "dev": true, - "requires": { - "wrappy": "1.0.2" - } - }, - "os-homedir": { - "version": "1.0.2", - "bundled": true, - "dev": true, - "optional": true - }, - "os-tmpdir": { - "version": "1.0.2", - "bundled": true, - "dev": true, - "optional": true - }, - "osenv": { - "version": "0.1.4", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "os-homedir": "1.0.2", - "os-tmpdir": "1.0.2" - } - }, - "path-is-absolute": { - "version": "1.0.1", - "bundled": true, - "dev": true - }, - "performance-now": { - "version": "0.2.0", - "bundled": true, - "dev": true, - "optional": true - }, - "process-nextick-args": { - "version": "1.0.7", - "bundled": true, - "dev": true - }, - "punycode": { - "version": "1.4.1", - "bundled": true, - "dev": true, - "optional": true - }, - "qs": { - "version": "6.4.0", - "bundled": true, - "dev": true, - "optional": true - }, - "rc": { - "version": "1.2.1", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "deep-extend": "0.4.2", - "ini": "1.3.4", - "minimist": "1.2.0", - "strip-json-comments": "2.0.1" - }, - "dependencies": { - "minimist": { - "version": "1.2.0", - "bundled": true, - "dev": true, - "optional": true - } - } - }, - "readable-stream": { - "version": "2.2.9", - "bundled": true, - "dev": true, - "requires": { - "buffer-shims": "1.0.0", - "core-util-is": "1.0.2", - "inherits": "2.0.3", - "isarray": "1.0.0", - "process-nextick-args": "1.0.7", - "string_decoder": "1.0.1", - "util-deprecate": "1.0.2" - } - }, - "request": { - "version": "2.81.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "aws-sign2": "0.6.0", - "aws4": "1.6.0", - "caseless": "0.12.0", - "combined-stream": "1.0.5", - "extend": "3.0.1", - "forever-agent": "0.6.1", - "form-data": "2.1.4", - "har-validator": "4.2.1", - "hawk": "3.1.3", - "http-signature": "1.1.1", - "is-typedarray": "1.0.0", - "isstream": "0.1.2", - "json-stringify-safe": "5.0.1", - "mime-types": "2.1.15", - "oauth-sign": "0.8.2", - "performance-now": "0.2.0", - "qs": "6.4.0", - "safe-buffer": "5.0.1", - "stringstream": "0.0.5", - "tough-cookie": "2.3.2", - "tunnel-agent": "0.6.0", - "uuid": "3.0.1" - } - }, - "rimraf": { - "version": "2.6.1", - "bundled": true, - "dev": true, - "requires": { - "glob": "7.1.2" - } - }, - "safe-buffer": { - "version": "5.0.1", - "bundled": true, - "dev": true - }, - "semver": { - "version": "5.3.0", - "bundled": true, - "dev": true, - "optional": true - }, - "set-blocking": { - "version": "2.0.0", - "bundled": true, - "dev": true, - "optional": true - }, - "signal-exit": { - "version": "3.0.2", - "bundled": true, - "dev": true, - "optional": true - }, - "sntp": { - "version": "1.0.9", - "bundled": true, - "dev": true, - "requires": { - "hoek": "2.16.3" - } - }, - "sshpk": { - "version": "1.13.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "asn1": "0.2.3", - "assert-plus": "1.0.0", - "bcrypt-pbkdf": "1.0.1", - "dashdash": "1.14.1", - "ecc-jsbn": "0.1.1", - "getpass": "0.1.7", - "jodid25519": "1.0.2", - "jsbn": "0.1.1", - "tweetnacl": "0.14.5" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "optional": true - } - } - }, - "string-width": { - "version": "1.0.2", - "bundled": true, - "dev": true, - "requires": { - "code-point-at": "1.1.0", - "is-fullwidth-code-point": "1.0.0", - "strip-ansi": "3.0.1" - } - }, - "string_decoder": { - "version": "1.0.1", - "bundled": true, - "dev": true, - "requires": { - "safe-buffer": "5.0.1" - } - }, - "stringstream": { - "version": "0.0.5", - "bundled": true, - "dev": true, - "optional": true - }, - "strip-ansi": { - "version": "3.0.1", - "bundled": true, - "dev": true, - "requires": { - "ansi-regex": "2.1.1" - } - }, - "strip-json-comments": { - "version": "2.0.1", - "bundled": true, - "dev": true, - "optional": true - }, - "tar": { - "version": "2.2.1", - "bundled": true, - "dev": true, - "requires": { - "block-stream": "0.0.9", - "fstream": "1.0.11", - "inherits": "2.0.3" - } - }, - "tar-pack": { - "version": "3.4.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "debug": "2.6.8", - "fstream": "1.0.11", - "fstream-ignore": "1.0.5", - "once": "1.4.0", - "readable-stream": "2.2.9", - "rimraf": "2.6.1", - "tar": "2.2.1", - "uid-number": "0.0.6" - } - }, - "tough-cookie": { - "version": "2.3.2", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "punycode": "1.4.1" - } - }, - "tunnel-agent": { - "version": "0.6.0", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "safe-buffer": "5.0.1" - } - }, - "tweetnacl": { - "version": "0.14.5", - "bundled": true, - "dev": true, - "optional": true - }, - "uid-number": { - "version": "0.0.6", - "bundled": true, - "dev": true, - "optional": true - }, - "util-deprecate": { - "version": "1.0.2", - "bundled": true, - "dev": true - }, - "uuid": { - "version": "3.0.1", - "bundled": true, - "dev": true, - "optional": true - }, - "verror": { - "version": "1.3.6", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "extsprintf": "1.0.2" - } - }, - "wide-align": { - "version": "1.1.2", - "bundled": true, - "dev": true, - "optional": true, - "requires": { - "string-width": "1.0.2" - } - }, - "wrappy": { - "version": "1.0.2", - "bundled": true, - "dev": true - } - } - }, "function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", @@ -6033,13 +5128,6 @@ "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=", "dev": true }, - "nan": { - "version": "2.8.0", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.8.0.tgz", - "integrity": "sha1-7XFfP+neArV6XmJS2QqWZ14fCFo=", - "dev": true, - "optional": true - }, "natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", diff --git a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java index d188dfbe..9e022557 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java +++ b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java @@ -190,7 +190,7 @@ public class NewMessage { sharetwi += " http://juick.com/" + mid; model.addAttribute("sharetwi", sharetwi); } - if (!crosspostService.getFacebookToken(visitor.getUid()).isPresent()) { + if (!crosspostService.getFacebookTokens(visitor.getUid()).isPresent()) { model.addAttribute("facebook", 1); } model.addAttribute("tags", tagService.getUserTagStats(visitor.getUid()).stream() diff --git a/juick-www/src/main/java/com/juick/www/controllers/SignUp.java b/juick-www/src/main/java/com/juick/www/controllers/SignUp.java index c8c64ef5..a5851215 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/SignUp.java +++ b/juick-www/src/main/java/com/juick/www/controllers/SignUp.java @@ -20,6 +20,7 @@ import com.juick.server.util.HttpBadRequestException; import com.juick.server.util.HttpForbiddenException; import com.juick.server.util.UserUtils; import com.juick.service.CrosspostService; +import com.juick.service.MessengerService; import com.juick.service.UserService; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; @@ -42,6 +43,8 @@ public class SignUp { private UserService userService; @Inject private CrosspostService crosspostService; + @Inject + private MessengerService messengerService; @GetMapping("/signup") @@ -67,6 +70,9 @@ public class SignUp { case "durov": account = crosspostService.getTelegramNameByHash(hash); break; + case "messenger": + account = messengerService.getDisplayName(hash); + break; } if (account == null) { throw new HttpBadRequestException(); @@ -113,7 +119,8 @@ public class SignUp { if (!(type.charAt(0) == 'f' && crosspostService.setFacebookUser(hash, uid)) && !(type.charAt(0) == 'v' && crosspostService.setVKUser(hash, uid)) && !(type.charAt(0) == 'd' && crosspostService.setTelegramUser(hash, uid)) - && !(type.charAt(0) == 'x' && crosspostService.setJIDUser(hash, uid))) { + && !(type.charAt(0) == 'x' && crosspostService.setJIDUser(hash, uid)) + && !(type.charAt(0) == 'm' && messengerService.linkMessengerUser(hash, uid))) { throw new HttpBadRequestException(); } @@ -132,7 +139,8 @@ public class SignUp { if (!(type.charAt(0) == 'f' && crosspostService.setFacebookUser(hash, uid)) && !(type.charAt(0) == 'v' && crosspostService.setVKUser(hash, uid)) && !(type.charAt(0) == 'd' && crosspostService.setTelegramUser(hash, uid)) - && !(type.charAt(0) == 'x' && crosspostService.setJIDUser(hash, uid))) { + && !(type.charAt(0) == 'x' && crosspostService.setJIDUser(hash, uid)) + && !(type.charAt(0) == 'm' && messengerService.linkMessengerUser(hash, uid))) { throw new HttpBadRequestException(); } } -- cgit v1.2.3