From d017f46088bc1f485f4966e232967324c6bd3c85 Mon Sep 17 00:00:00 2001 From: Maximilian Stoiber Date: Thu, 29 Mar 2018 18:44:49 +0200 Subject: [PATCH 1/4] Track userThreadLastSeen on new message in subscription and message send --- api/mutations/message/addMessage.js | 7 +++++++ api/subscriptions/message.js | 13 ++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/api/mutations/message/addMessage.js b/api/mutations/message/addMessage.js index 17361e0d18..f326233281 100644 --- a/api/mutations/message/addMessage.js +++ b/api/mutations/message/addMessage.js @@ -11,6 +11,7 @@ import { createParticipantWithoutNotificationsInThread, } from '../../models/usersThreads'; import addCommunityMember from '../communityMember/addCommunityMember'; +import { trackUserThreadLastSeenQueue } from 'shared/bull/queues'; import type { FileUpload } from 'shared/types'; type AddMessageInput = { @@ -169,6 +170,12 @@ export default async ( isOwner: communityPermissions ? communityPermissions.isOwner : false, }; + trackUserThreadLastSeenQueue.add({ + userId: currentUser.id, + threadId: message.threadId, + timestamp: Date.now(), + }); + return { ...dbMessage, contextPermissions, diff --git a/api/subscriptions/message.js b/api/subscriptions/message.js index 6f2d4b8c38..19343550de 100644 --- a/api/subscriptions/message.js +++ b/api/subscriptions/message.js @@ -57,7 +57,18 @@ module.exports = { debug(`${moniker} listening to new messages in ${thread}`); try { return addMessageListener({ - filter: message => message.threadId === thread, + filter: message => { + if (message.threadId === thread) { + trackUserThreadLastSeenQueue.add({ + userId: user.id, + threadId: message.threadId, + timestamp: new Date(message.timestamp).getTime() + 100, + }); + return true; + } + + return false; + }, onError: err => { // Don't crash the whole API server on error in the listener console.error(err); From 78ba52b1f8ddfd948b8c28e035ff35c5085be2bb Mon Sep 17 00:00:00 2001 From: Maximilian Stoiber Date: Fri, 30 Mar 2018 16:01:12 +0200 Subject: [PATCH 2/4] Fix messages in private channels Resolves #2675 --- api/mutations/message/addMessage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/mutations/message/addMessage.js b/api/mutations/message/addMessage.js index 835a3ba3e4..2e4fca8301 100644 --- a/api/mutations/message/addMessage.js +++ b/api/mutations/message/addMessage.js @@ -103,7 +103,7 @@ export default async ( currentUser.id, thread.communityId, ]), - loaders.userPermissionsInChannel.load([thread.channelId, currentUser.id]), + loaders.userPermissionsInChannel.load([currentUser.id, thread.channelId]), loaders.channel.load(thread.channelId), ] ); From 3464b3b88f831ab17d7a703af8578bb2bbb4c681 Mon Sep 17 00:00:00 2001 From: Brian Lovin Date: Fri, 30 Mar 2018 11:07:58 -0700 Subject: [PATCH 3/4] Fix github auth retries --- api/authentication.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/api/authentication.js b/api/authentication.js index 5e725ba52e..ab4c71c72b 100644 --- a/api/authentication.js +++ b/api/authentication.js @@ -274,6 +274,12 @@ const init = () => { async (req, token, tokenSecret, profile, done) => { const name = profile.displayName || profile.username || profile._json.name || ''; + + const splitProfileUrl = profile.profileUrl.split('/'); + const fallbackUsername = splitProfileUrl[splitProfileUrl.length - 1]; + const githubUsername = + profile.username || profile._json.login || fallbackUsername; + if (req.user) { // if a user exists in the request body, it means the user is already // authed and is trying to connect a github account. Before we do so @@ -284,6 +290,23 @@ const init = () => { // 1 // if the user already has a githubProviderId, don't override it if (req.user.githubProviderId) { + if (!req.user.githubUsername) { + return saveUserProvider( + req.user.id, + 'githubProviderId', + profile.id, + { githubUsername: githubUsername } + ) + .then(user => { + done(null, user); + return user; + }) + .catch(err => { + done(err); + return null; + }); + } + return done(null, req.user); } @@ -299,7 +322,7 @@ const init = () => { req.user.id, 'githubProviderId', profile.id, - { githubUsername: profile.username } + { githubUsername: githubUsername } ) .then(user => { done(null, user); @@ -322,7 +345,7 @@ const init = () => { fbProviderId: null, googleProviderId: null, githubProviderId: profile.id, - githubUsername: profile.username, + githubUsername: githubUsername, username: null, name: name, description: profile._json.bio, From 90b2c8b58653d68f92f4fbe9608589526b30ed77 Mon Sep 17 00:00:00 2001 From: Brian Lovin Date: Mon, 2 Apr 2018 15:51:26 -0700 Subject: [PATCH 4/4] Version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e8b77cb0b0..bbb078dd8a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Spectrum", - "version": "2.2.2", + "version": "2.2.3", "private": true, "devDependencies": { "babel-cli": "^6.24.1",