-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #292 from scarmuega/refactor-utils
Refactor utils into stand-alone functions
- Loading branch information
Showing
6 changed files
with
91 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import moment from 'moment'; | ||
|
||
const DEPRECATION_MESSAGE = 'isSameUser and isSameDay should be imported from the utils module instead of using the props functions'; | ||
|
||
export function isSameDay(currentMessage = {}, diffMessage = {}) { | ||
|
||
let currentCreatedAt = moment(currentMessage.createdAt); | ||
let diffCreatedAt = moment(diffMessage.createdAt); | ||
|
||
if (!currentCreatedAt.isValid() || !diffCreatedAt.isValid()) { | ||
return false; | ||
} | ||
|
||
return currentCreatedAt.isSame(diffCreatedAt, 'day'); | ||
|
||
} | ||
|
||
export function isSameUser(currentMessage = {}, diffMessage = {}) { | ||
|
||
return !!(diffMessage.user && currentMessage.user && diffMessage.user._id === currentMessage.user._id); | ||
|
||
} | ||
|
||
export function warnDeprecated(fn) { | ||
|
||
return (...args) => { | ||
console.warn(DEPRECATION_MESSAGE); | ||
return fn(...args); | ||
}; | ||
|
||
} |