refactor: Replace `Notifications` in favor of `sdk.stream`; (#31409)
parent
0c3a563b3a
commit
6526b2ff03
@ -1,6 +0,0 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
import { Notifications } from '../../../notifications/client'; |
||||
import { deleteEmojiCustom } from '../lib/emojiCustom'; |
||||
|
||||
Meteor.startup(() => Notifications.onLogged('deleteEmojiCustom', (data) => deleteEmojiCustom(data.emojiData))); |
||||
@ -1,6 +0,0 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
import { Notifications } from '../../../notifications/client'; |
||||
import { updateEmojiCustom } from '../lib/emojiCustom'; |
||||
|
||||
Meteor.startup(() => Notifications.onLogged('updateEmojiCustom', (data) => updateEmojiCustom(data.emojiData))); |
||||
@ -1,5 +1,3 @@ |
||||
import './notifications/deleteCustomUserStatus'; |
||||
import './notifications/updateCustomUserStatus'; |
||||
import './lib/customUserStatus'; |
||||
|
||||
export { userStatus } from './lib/userStatus'; |
||||
|
||||
@ -1,6 +0,0 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
import { Notifications } from '../../../notifications/client'; |
||||
import { deleteCustomUserStatus } from '../lib/customUserStatus'; |
||||
|
||||
Meteor.startup(() => Notifications.onLogged('deleteCustomUserStatus', (data) => deleteCustomUserStatus(data.userStatusData))); |
||||
@ -1,6 +0,0 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
import { Notifications } from '../../../notifications/client'; |
||||
import { updateCustomUserStatus } from '../lib/customUserStatus'; |
||||
|
||||
Meteor.startup(() => Notifications.onLogged('updateCustomUserStatus', (data) => updateCustomUserStatus(data.userStatusData))); |
||||
@ -0,0 +1 @@ |
||||
export { default } from './EmojiPickerProvider'; |
||||
@ -0,0 +1,17 @@ |
||||
import { useStream } from '@rocket.chat/ui-contexts'; |
||||
import { useEffect } from 'react'; |
||||
|
||||
import { updateEmojiCustom, deleteEmojiCustom } from '../../../app/emoji-custom/client/lib/emojiCustom'; |
||||
|
||||
export const useUpdateCustomEmoji = () => { |
||||
const notify = useStream('notify-logged'); |
||||
useEffect(() => { |
||||
const unsubUpdate = notify('updateEmojiCustom', (data) => updateEmojiCustom(data.emojiData)); |
||||
const unsubDelete = notify('deleteEmojiCustom', (data) => deleteEmojiCustom(data.emojiData)); |
||||
|
||||
return () => { |
||||
unsubUpdate(); |
||||
unsubDelete(); |
||||
}; |
||||
}, [notify]); |
||||
}; |
||||
@ -0,0 +1,32 @@ |
||||
import { useStream } from '@rocket.chat/ui-contexts'; |
||||
import { useEffect } from 'react'; |
||||
|
||||
import { ChatMessage } from '../../../../app/models/client'; |
||||
|
||||
export const useDeleteUser = () => { |
||||
const notify = useStream('notify-logged'); |
||||
|
||||
useEffect(() => { |
||||
return notify('Users:Deleted', ({ userId, messageErasureType, replaceByUser }) => { |
||||
if (messageErasureType === 'Unlink' && replaceByUser) { |
||||
return ChatMessage.update( |
||||
{ |
||||
'u._id': userId, |
||||
}, |
||||
{ |
||||
$set: { |
||||
'alias': replaceByUser.alias, |
||||
'u._id': replaceByUser._id, |
||||
'u.username': replaceByUser.username, |
||||
'u.name': undefined, |
||||
}, |
||||
}, |
||||
{ multi: true }, |
||||
); |
||||
} |
||||
ChatMessage.remove({ |
||||
'u._id': userId, |
||||
}); |
||||
}); |
||||
}, [notify]); |
||||
}; |
||||
@ -0,0 +1,15 @@ |
||||
import { useStream } from '@rocket.chat/ui-contexts'; |
||||
import { Meteor } from 'meteor/meteor'; |
||||
import { useEffect } from 'react'; |
||||
|
||||
export const useUpdateAvatar = () => { |
||||
const notify = useStream('notify-logged'); |
||||
useEffect(() => { |
||||
return notify('updateAvatar', (data) => { |
||||
if ('username' in data) { |
||||
const { username, etag } = data; |
||||
username && Meteor.users.update({ username }, { $set: { avatarETag: etag } }); |
||||
} |
||||
}); |
||||
}, [notify]); |
||||
}; |
||||
@ -0,0 +1,17 @@ |
||||
import { useStream } from '@rocket.chat/ui-contexts'; |
||||
import { useEffect } from 'react'; |
||||
|
||||
import { updateCustomUserStatus, deleteCustomUserStatus } from '../../../../app/user-status/client/lib/customUserStatus'; |
||||
|
||||
export const useUpdateCustomUserStatus = () => { |
||||
const notify = useStream('notify-logged'); |
||||
useEffect(() => { |
||||
const unsubUpdate = notify('updateCustomUserStatus', (data) => updateCustomUserStatus(data.userStatusData)); |
||||
const unsubDelete = notify('deleteCustomUserStatus', (data) => deleteCustomUserStatus(data.userStatusData)); |
||||
|
||||
return () => { |
||||
unsubUpdate(); |
||||
unsubDelete(); |
||||
}; |
||||
}, [notify]); |
||||
}; |
||||
@ -1,28 +0,0 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
import { ChatMessage } from '../../app/models/client'; |
||||
import { Notifications } from '../../app/notifications/client'; |
||||
|
||||
Meteor.startup(() => { |
||||
Notifications.onLogged('Users:Deleted', ({ userId, messageErasureType, replaceByUser }) => { |
||||
if (messageErasureType === 'Unlink' && replaceByUser) { |
||||
return ChatMessage.update( |
||||
{ |
||||
'u._id': userId, |
||||
}, |
||||
{ |
||||
$set: { |
||||
'alias': replaceByUser.alias, |
||||
'u._id': replaceByUser._id, |
||||
'u.username': replaceByUser.username, |
||||
'u.name': undefined, |
||||
}, |
||||
}, |
||||
{ multi: true }, |
||||
); |
||||
} |
||||
ChatMessage.remove({ |
||||
'u._id': userId, |
||||
}); |
||||
}); |
||||
}); |
||||
@ -1,12 +0,0 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
import { Notifications } from '../../../app/notifications/client'; |
||||
|
||||
Meteor.startup(() => { |
||||
Notifications.onLogged('updateAvatar', (data) => { |
||||
if ('username' in data) { |
||||
const { username, etag } = data; |
||||
username && Meteor.users.update({ username }, { $set: { avatarETag: etag } }); |
||||
} |
||||
}); |
||||
}); |
||||
@ -1,69 +0,0 @@ |
||||
import type { IUser } from '@rocket.chat/core-typings'; |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
import { Messages, Subscriptions } from '../../../app/models/client'; |
||||
import { Notifications } from '../../../app/notifications/client'; |
||||
|
||||
type UsersNameChangedEvent = Partial<IUser>; |
||||
|
||||
Meteor.startup(() => { |
||||
Notifications.onLogged('Users:NameChanged', ({ _id, name, username }: UsersNameChangedEvent) => { |
||||
Messages.update( |
||||
{ |
||||
'u._id': _id, |
||||
}, |
||||
{ |
||||
$set: { |
||||
'u.username': username, |
||||
'u.name': name, |
||||
}, |
||||
}, |
||||
{ |
||||
multi: true, |
||||
}, |
||||
); |
||||
|
||||
Messages.update( |
||||
{ |
||||
'editedBy._id': _id, |
||||
}, |
||||
{ |
||||
$set: { |
||||
'editedBy.username': username, |
||||
}, |
||||
}, |
||||
{ |
||||
multi: true, |
||||
}, |
||||
); |
||||
|
||||
Messages.update( |
||||
{ |
||||
mentions: { |
||||
$elemMatch: { _id }, |
||||
}, |
||||
}, |
||||
{ |
||||
$set: { |
||||
'mentions.$.username': username, |
||||
'mentions.$.name': name, |
||||
}, |
||||
}, |
||||
{ |
||||
multi: true, |
||||
}, |
||||
); |
||||
|
||||
Subscriptions.update( |
||||
{ |
||||
name: username, |
||||
t: 'd', |
||||
}, |
||||
{ |
||||
$set: { |
||||
fname: name, |
||||
}, |
||||
}, |
||||
); |
||||
}); |
||||
}); |
||||
@ -0,0 +1,69 @@ |
||||
import { useStream } from '@rocket.chat/ui-contexts'; |
||||
import { useEffect } from 'react'; |
||||
|
||||
import { Messages, Subscriptions } from '../../../../../app/models/client'; |
||||
|
||||
export const useUsersNameChanged = () => { |
||||
const notify = useStream('notify-logged'); |
||||
useEffect(() => { |
||||
return notify('Users:NameChanged', ({ _id, name, username }) => { |
||||
Messages.update( |
||||
{ |
||||
'u._id': _id, |
||||
}, |
||||
{ |
||||
$set: { |
||||
'u.username': username, |
||||
'u.name': name, |
||||
}, |
||||
}, |
||||
{ |
||||
multi: true, |
||||
}, |
||||
); |
||||
|
||||
Messages.update( |
||||
{ |
||||
'editedBy._id': _id, |
||||
}, |
||||
{ |
||||
$set: { |
||||
'editedBy.username': username, |
||||
}, |
||||
}, |
||||
{ |
||||
multi: true, |
||||
}, |
||||
); |
||||
|
||||
Messages.update( |
||||
{ |
||||
mentions: { |
||||
$elemMatch: { _id }, |
||||
}, |
||||
}, |
||||
{ |
||||
$set: { |
||||
'mentions.$.username': username, |
||||
'mentions.$.name': name, |
||||
}, |
||||
}, |
||||
{ |
||||
multi: true, |
||||
}, |
||||
); |
||||
|
||||
Subscriptions.update( |
||||
{ |
||||
name: username, |
||||
t: 'd', |
||||
}, |
||||
{ |
||||
$set: { |
||||
fname: name, |
||||
}, |
||||
}, |
||||
); |
||||
}); |
||||
}, [notify]); |
||||
}; |
||||
Loading…
Reference in new issue