Skip to content
This repository has been archived by the owner on Oct 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2685 from withspectrum/2.2.3
Browse files Browse the repository at this point in the history
2.2.3
  • Loading branch information
brianlovin authored Apr 2, 2018
2 parents 8b4dd44 + 90b2c8b commit 221b379
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
27 changes: 25 additions & 2 deletions api/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

Expand All @@ -299,7 +322,7 @@ const init = () => {
req.user.id,
'githubProviderId',
profile.id,
{ githubUsername: profile.username }
{ githubUsername: githubUsername }
)
.then(user => {
done(null, user);
Expand All @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions api/mutations/message/addMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -189,6 +190,12 @@ export default async (
isOwner: communityPermissions ? communityPermissions.isOwner : false,
};

trackUserThreadLastSeenQueue.add({
userId: currentUser.id,
threadId: message.threadId,
timestamp: Date.now(),
});

return {
...dbMessage,
contextPermissions,
Expand Down
13 changes: 12 additions & 1 deletion api/subscriptions/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Spectrum",
"version": "2.2.2",
"version": "2.2.3",
"private": true,
"devDependencies": {
"babel-cli": "^6.24.1",
Expand Down

0 comments on commit 221b379

Please sign in to comment.