fix: canonical usernames
This commit is contained in:
parent
5de08cf49d
commit
f3f4f7d265
|
@ -19,6 +19,8 @@ import defaultState, {channelsToHydrate} from './state';
|
|||
import joinChannel from './join-channel';
|
||||
import leaveChannel from './leave-channel';
|
||||
|
||||
export {ensureCanonical};
|
||||
|
||||
export * from './state';
|
||||
|
||||
export default {
|
||||
|
|
4
packages/user/src/client/effects.js
vendored
4
packages/user/src/client/effects.js
vendored
|
@ -25,13 +25,13 @@ export default ({config: {'%socket': socket}}) => ({
|
|||
[submitAddFriend]: async ({dispatch, getState}, {payload: name}) => {
|
||||
const state = getState();
|
||||
const userId = idSelector(state);
|
||||
const id = await socket.send(['AddFriend', {name}]);
|
||||
const [id, canonicalName] = await socket.send(['AddFriend', {name}]);
|
||||
dispatch(addFriendship({
|
||||
addeeId: id,
|
||||
adderId: userId,
|
||||
status: 'pending',
|
||||
}));
|
||||
dispatch(setUsernames({[id]: name}));
|
||||
dispatch(setUsernames({[id]: canonicalName}));
|
||||
},
|
||||
[submitBlock]: async ({dispatch}, {payload: id}) => {
|
||||
dispatch(block(id));
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import {ModelMap} from '@latus/db';
|
||||
import {parseChannel} from '@reddichat/core';
|
||||
import {ensureCanonical} from '@reddichat/chat';
|
||||
|
||||
import AddFriend from './add-friend';
|
||||
|
||||
|
@ -10,11 +12,13 @@ export default (latus) => class AddFriendServer extends AddFriend(latus) {
|
|||
Friendship,
|
||||
User,
|
||||
} = ModelMap(latus);
|
||||
const chat = await ensureCanonical(latus, {type: 'u', name});
|
||||
const canonical = parseChannel(chat.name);
|
||||
const adderId = req.user.id;
|
||||
const adderName = req.user.redditUsername;
|
||||
const user = (
|
||||
await User.findOne({where: {redditUsername: name}})
|
||||
|| await User.create({redditUsername: name})
|
||||
await User.findOne({where: {redditUsername: canonical.name}})
|
||||
|| await User.create({redditUsername: canonical.name})
|
||||
);
|
||||
const addeeId = user.id;
|
||||
const addeeName = user.redditUsername;
|
||||
|
@ -34,7 +38,7 @@ export default (latus) => class AddFriendServer extends AddFriend(latus) {
|
|||
: ['AddFriend', {addeeId, adderId, name: id === adderId ? addeeName : adderName}];
|
||||
socket.to(`/u/${id}`).send(packet);
|
||||
});
|
||||
return addeeId;
|
||||
return [addeeId, canonical.name];
|
||||
}
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user