Merge pull request #16703 from danielpetri1/unread-notification
fix: Notes notification perpetually unread
This commit is contained in:
commit
ad6eef4d12
@ -63,7 +63,6 @@ const Notes = ({
|
||||
isToSharedNotesBeShow,
|
||||
shouldShowSharedNotesOnPresentationArea,
|
||||
}) => {
|
||||
useEffect(() => () => Service.setLastRev(), []);
|
||||
const [shouldRenderNotes, setShouldRenderNotes] = useState(false);
|
||||
const { isChrome } = browserInfo;
|
||||
const isOnMediaArea = area === 'media';
|
||||
|
@ -34,28 +34,13 @@ const hasPermission = () => {
|
||||
return true;
|
||||
};
|
||||
|
||||
const getLastRev = () => {
|
||||
const lastRev = Session.get('notesLastRev');
|
||||
if (!lastRev) return -1;
|
||||
const getLastRev = () => (Session.get('notesLastRev') || 0);
|
||||
|
||||
return lastRev;
|
||||
};
|
||||
const getRev = () => PadsService.getRev(NOTES_CONFIG.id);
|
||||
|
||||
const setLastRev = () => {
|
||||
const rev = PadsService.getRev(NOTES_CONFIG.id);
|
||||
const lastRev = getLastRev();
|
||||
const markNotesAsRead = () => Session.set('notesLastRev', getRev());
|
||||
|
||||
if (rev !== 0 && rev > lastRev) {
|
||||
Session.set('notesLastRev', rev);
|
||||
}
|
||||
};
|
||||
|
||||
const hasUnreadNotes = () => {
|
||||
const rev = PadsService.getRev(NOTES_CONFIG.id);
|
||||
const lastRev = getLastRev();
|
||||
|
||||
return rev !== 0 && rev > lastRev;
|
||||
};
|
||||
const hasUnreadNotes = () => (getRev() > getLastRev());
|
||||
|
||||
const isEnabled = () => isSharedNotesEnabled();
|
||||
|
||||
@ -87,8 +72,7 @@ export default {
|
||||
toggleNotesPanel,
|
||||
hasPermission,
|
||||
isEnabled,
|
||||
setLastRev,
|
||||
getLastRev,
|
||||
markNotesAsRead,
|
||||
hasUnreadNotes,
|
||||
isSharedNotesPinned,
|
||||
pinSharedNotes,
|
||||
|
@ -10,7 +10,8 @@ const propTypes = {
|
||||
intl: PropTypes.shape({
|
||||
formatMessage: PropTypes.func.isRequired,
|
||||
}).isRequired,
|
||||
rev: PropTypes.number.isRequired,
|
||||
isPinned: PropTypes.bool.isRequired,
|
||||
sidebarContentPanel: PropTypes.string.isRequired,
|
||||
};
|
||||
|
||||
const intlMessages = defineMessages({
|
||||
@ -51,28 +52,29 @@ class UserNotes extends Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const {
|
||||
rev,
|
||||
} = this.props;
|
||||
|
||||
const lastRev = NotesService.getLastRev();
|
||||
|
||||
if (rev !== 0 && rev > lastRev) this.setUnread(true);
|
||||
this.setUnread(NotesService.hasUnreadNotes());
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
const { sidebarContentPanel, rev, isPinned } = this.props;
|
||||
const { sidebarContentPanel, isPinned } = this.props;
|
||||
const { unread } = this.state;
|
||||
|
||||
if (sidebarContentPanel !== PANELS.SHARED_NOTES && !unread) {
|
||||
if (prevProps.rev !== rev) this.setUnread(true);
|
||||
const notesOpen = sidebarContentPanel === PANELS.SHARED_NOTES && !isPinned;
|
||||
const notesClosed = (prevProps.sidebarContentPanel === PANELS.SHARED_NOTES
|
||||
&& sidebarContentPanel !== PANELS.SHARED_NOTES)
|
||||
|| (prevProps.isPinned && !isPinned);
|
||||
|
||||
if (notesOpen && unread) {
|
||||
NotesService.markNotesAsRead();
|
||||
this.setUnread(false);
|
||||
} else if (!unread && NotesService.hasUnreadNotes()) {
|
||||
this.setUnread(true);
|
||||
}
|
||||
|
||||
if (sidebarContentPanel === PANELS.SHARED_NOTES && unread) {
|
||||
if (notesClosed) {
|
||||
NotesService.markNotesAsRead();
|
||||
this.setUnread(false);
|
||||
}
|
||||
|
||||
if (!isPinned && prevProps.isPinned && unread) this.setUnread(false);
|
||||
}
|
||||
|
||||
setUnread(unread) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
import React from 'react';
|
||||
import { withTracker } from 'meteor/react-meteor-data';
|
||||
import PadsService from '/imports/ui/components/pads/service';
|
||||
import NotesService from '/imports/ui/components/notes/service';
|
||||
import lockContextContainer from '/imports/ui/components/lock-viewers/context/container';
|
||||
import UserNotes from './component';
|
||||
@ -16,7 +15,7 @@ const UserNotesContainer = (props) => {
|
||||
export default lockContextContainer(withTracker(({ userLocks }) => {
|
||||
const shouldDisableNotes = userLocks.userNotes;
|
||||
return {
|
||||
rev: PadsService.getRev(NotesService.ID),
|
||||
unread: NotesService.hasUnreadNotes(),
|
||||
disableNotes: shouldDisableNotes,
|
||||
isPinned: NotesService.isSharedNotesPinned(),
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user