Skip to content

Commit

Permalink
Published freedombase:[email protected].
Browse files Browse the repository at this point in the history
  • Loading branch information
StorytellerCZ committed Apr 28, 2024
1 parent 6e772da commit a1b4dbe
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 44 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@

### Deprecated

## v0.7.0 - 2024-04-28

### Breaking changes
* Replaced `simpl-schema` with `meteor/aldeed:simple-schema`

### Fixes
* Fix common display issues
* Added version range for Meteor `3.0-rc.0`

## v0.6.1 - 2024-01-02

### Fixes
* Add `ddp` dependency which is needed for properly working with Meteor 3.0

## v0.6.0 - 2023-12-30

### Breaking changes
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": "meteor-freedombase-flashnews",
"version": "0.6.0",
"version": "0.7.0",
"private": true,
"description": "Template Meteor package for FOSS",
"main": "package/freedombase-flashnews/package.js",
Expand Down
8 changes: 4 additions & 4 deletions package/freedombase-flashnews/.versions
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ [email protected]
[email protected]
[email protected]
[email protected]
freedombase:flashnews@0.6.0
freedombase:flashnews@0.7.0
[email protected]
[email protected]
[email protected]
[email protected]
matb33:[email protected]
[email protected].4
[email protected].5
[email protected]
[email protected]
[email protected]
Expand All @@ -51,6 +51,6 @@ [email protected]
tmeasday:[email protected]
[email protected]
[email protected]
underscore@1.0.13
[email protected].6
underscore@1.6.0
[email protected].8
[email protected]
29 changes: 22 additions & 7 deletions package/freedombase-flashnews/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SimpleSchema from 'simpl-schema'
import SimpleSchema from 'meteor/aldeed:simple-schema'
import { Mongo } from 'meteor/mongo'
import { Meteor } from 'meteor/meteor'
import { check, Match } from 'meteor/check'
Expand All @@ -7,15 +7,30 @@ import { BaseModel } from 'meteor/socialize:base-model'

export const APP_NEWS = 'meteorAppNews'

export const currentFlashNewsSelector = (now?: Date) => {
export const currentFlashNewsSelector = (now?: Date, language) => {
if (now || Meteor.isClient) {
// const twoWeeks = 1000 * 60 * 60 * 24 * 14
// const twoWeeksAgo = new Date(new Date().getTime() - twoWeeks)

if (Meteor.isClient && !now) now = new Date()
return {
startsAt: { $lte: now },
$or: [
{ endsAt: { $gte: new Date() } },
{ endsAt: null },
{ endsAt: { $exists: false } }
startsAt: { $lte: now /*, $gte: twoWeeksAgo */ },
$and: [
{
$or: [
{ endsAt: { $gte: new Date() } },
{ endsAt: null },
{ endsAt: { $exists: false } }
]
},
{
$or: [
{ onlyDisplayOn: { $in: [language] } },
{ onlyDisplayOn: { $exists: false } },
{ onlyDisplayOn: [] },
{ onlyDisplayOn: null }
]
}
]
}
}
Expand Down
8 changes: 4 additions & 4 deletions package/freedombase-flashnews/package.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global Package */
Package.describe({
name: 'freedombase:flashnews',
version: '0.6.0',
version: '0.7.0',
// Brief, one-line summary of the package.
summary: 'Timed and localized flash messages for your Meteor app ',
// URL to the Git repository containing the source code for this package.
Expand All @@ -12,10 +12,10 @@ Package.describe({
})

Package.onUse(function (api) {
api.versionsFrom(['2.8.1', '3.0-beta.0'])
api.use(['ecmascript', 'typescript', 'mongo', 'callback-hook'])
api.versionsFrom(['2.8.1', '3.0-rc.0'])
api.use(['ecmascript', 'typescript', 'mongo', 'ddp', 'callback-hook'])
api.use([
'aldeed:collection2@4.0.0-beta.6',
'aldeed:collection2@3.4.1',
'socialize:[email protected]'
])
api.mainModule('common.ts', 'client')
Expand Down
42 changes: 14 additions & 28 deletions package/freedombase-flashnews/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Meteor } from 'meteor/meteor'
import { check, Match } from 'meteor/check'
import {
APP_NEWS,
FlashNewsCollection,
afterFlashNewsInsert,
APP_NEWS,
beforeFlashNewsInsert,
setSanitizationFunction,
currentFlashNewsSelector,
FlashNewsCollection,
FlashNewsSchema,
currentFlashNewsSelector
setSanitizationFunction
} from '../common'

export {
Expand All @@ -22,13 +22,6 @@ export {

export type { FlashNewsType } from '../common'

// Indexes creation
FlashNewsCollection.createIndexAsync({ objectType: 1, endsAt: -1, onlyDisplayOn: 1 })
FlashNewsCollection.createIndexAsync({ objectType: 1, startsAt: -1, endsAt: -1, onlyDisplayOn: 1 })
FlashNewsCollection.createIndexAsync({ objectId: 1, objectType: 1, endsAt: -1, onlyDisplayOn: 1 })
FlashNewsCollection.createIndexAsync({ objectId: 1, objectType: 1, startsAt: -1, endsAt: -1, onlyDisplayOn: 1 })
FlashNewsCollection.createIndexAsync({ objectId: 1, objectType: 1 })

/**
* Gets current flash news for the site
* @param limit {Number}
Expand All @@ -37,19 +30,15 @@ FlashNewsCollection.createIndexAsync({ objectId: 1, objectType: 1 })
*/
Meteor.publish(
'freedombase:flashnews-getMain',
async (limit = 3, language = 'en', clientTime?: Date) => {
async function (limit = 3, language = 'en', clientTime?: Date) {
this.unblock()
check(limit, Match.Maybe(Number))
check(language, Match.Maybe(String))
check(clientTime, Match.Maybe(Date))
return FlashNewsCollection.find(
{
objectType: APP_NEWS,
...currentFlashNewsSelector(clientTime),
$or: [
{ onlyDisplayOn: { $in: [language] } },
{ onlyDisplayOn: { $exists: false } },
{ onlyDisplayOn: null }
]
...currentFlashNewsSelector(clientTime, language),
objectType: APP_NEWS
},
{ limit, sort: { startsAt: -1, createdAt: -1 } }
)
Expand All @@ -66,28 +55,25 @@ Meteor.publish(
*/
Meteor.publish(
'freedombase:flashnews-getFor',
(
function (
objectType: String,
objectId: String,
limit = 5,
language = 'en',
clientTime?: Date
) => {
) {
this.unblock()
check(objectType, String)
check(objectId, Match.Maybe(String))
check(limit, Match.Maybe(Number))
check(language, Match.Maybe(String))
check(clientTime, Match.Maybe(Date))

return FlashNewsCollection.find(
{
objectId,
...currentFlashNewsSelector(clientTime, language),
objectType,
...currentFlashNewsSelector(clientTime),
$or: [
{ onlyDisplayOn: { $in: [language] } },
{ onlyDisplayOn: { $exists: false } },
{ onlyDisplayOn: null }
]
objectId
},
{ limit, sort: { startsAt: -1, createdAt: -1 } }
)
Expand Down

0 comments on commit a1b4dbe

Please sign in to comment.