Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
tibetsprague committed Nov 11, 2023
2 parents 0f94997 + 729e595 commit 565170a
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 39 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [5.6.1] - 2023-11-11

### Changed
- Notifications for new chats take you to the chat room on mobile, scrolled to that post, instead of opening the post itself
- Turn off ability for new groups to to be able to post in public and appear in the Group Explorer. In the future groups will have to apply to be able to post in public. This is a temporary measure to prevent spam.
- Improve performance by loading event invites only for events and post members only for projects
- For post related Zapier triggers set the post URL to be the post in the first group it is in, instead of in the "all" groups context. Normally this is what people will want, to see the post in its group context.

### Fixed
- Fix bug that broke notifications when dealing with a post that somehow doesn't have a group (still have to figure out why that can happen)
- "Null" post time in notification emails for posts that dont have a start time.
- Don't sort pinned posts first when getting posts for chat rooms

## [5.6.0] - 2023-09-23

### Added
Expand Down
4 changes: 2 additions & 2 deletions api/models/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,8 @@ module.exports = bookshelf.Model.extend(merge({
}
)

// XXX: for now allow all groups to appear in public by default
attrs.allow_in_public = true
// XXX: for now groups by default cannot post to public on production
attrs.allow_in_public = process.env.NODE_ENV === 'development'

// eslint-disable-next-line camelcase
const access_code = attrs.access_code || await Group.getNewAccessCode()
Expand Down
2 changes: 1 addition & 1 deletion api/models/Notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ module.exports = bookshelf.Model.extend({
unfollow_url: Frontend.Route.tokenLogin(reader, token,
Frontend.Route.unfollow(post, group) + '?ctt=announcement_email&cti=' + reader.id),
tracking_pixel_url: Analytics.pixelUrl('Announcement', { userId: reader.id }),
post_date: TextHelpers.formatDatePair(post.get('start_time'), post.get('end_time'), false, post.get('timezone'))
post_date: post.get('start_time') ? TextHelpers.formatDatePair(post.get('start_time'), post.get('end_time'), false, post.get('timezone')) : null
}
})))
},
Expand Down
17 changes: 8 additions & 9 deletions api/models/Post.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ module.exports = bookshelf.Model.extend(Object.assign({
return this.get('is_public')
},

isChat: function () {
return this.get('type') === Post.Type.CHAT
},

isWelcome: function () {
return this.get('type') === Post.Type.WELCOME
},
Expand Down Expand Up @@ -119,11 +123,7 @@ module.exports = bookshelf.Model.extend(Object.assign({

groups: function () {
return this.belongsToMany(Group).through(PostMembership)
.query({where: {'groups.active': true }})
},

invitees: function () {
return this.belongsToMany(User).through(EventInvitation)
.query({ where: { 'groups.active': true } })
},

async isFollowed (userId) {
Expand All @@ -143,15 +143,14 @@ module.exports = bookshelf.Model.extend(Object.assign({
},

locationObject: function () {
return this.belongsTo(Location, 'location_id')
return this.isChat() ? false : this.belongsTo(Location, 'location_id')
},

media: function (type) {
const relation = this.hasMany(Media)
return type ? relation.query({ where: { type } }) : relation
},

// TODO: rename postGroups?
postMemberships: function () {
return this.hasMany(PostMembership, 'post_id')
},
Expand Down Expand Up @@ -694,7 +693,7 @@ module.exports = bookshelf.Model.extend(Object.assign({

const entityUrl = (post.get('type') === Post.Type.CHAT && post.relations.groups.length > 0 && firstTag)
? Frontend.Route.chatPostForMobile(post, post.relations.groups[0], firstTag)
: Frontend.Route.post(post)
: Frontend.Route.post(post, post.relations.groups[0])

const creator = post.relations.user
const response = await fetch(trigger.get('target_url'), {
Expand All @@ -714,7 +713,7 @@ module.exports = bookshelf.Model.extend(Object.assign({
type: post.get('type'),
url: entityUrl,
groups: post.relations.groups.map(g => ({ id: g.id, name: g.get('name'), url: Frontend.Route.group(g), postUrl: Frontend.Route.post(post, g) })),
topics: post.relations.tags.map(t => ({ name: t.get('name')})),
topics: post.relations.tags.map(t => ({ name: t.get('name') }))
}),
headers: { 'Content-Type': 'application/json' }
})
Expand Down
2 changes: 1 addition & 1 deletion api/models/ZapierTrigger.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { castArray, isEmpty, isEqual, difference } from 'lodash'
import { castArray } from 'lodash'

module.exports = bookshelf.Model.extend(Object.assign({
tableName: 'zapier_triggers',
Expand Down
32 changes: 17 additions & 15 deletions api/models/comment/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,23 @@ export const sendDigests = async () => {

lastDigestAt = lastDigestAt ? new Date(Number(lastDigestAt)) : fallbackTime()

const posts = await Post.where('updated_at', '>', lastDigestAt)
.fetchAll({
withRelated: [
{
comments: q => {
q.where('created_at', '>', lastDigestAt)
q.orderBy('created_at', 'asc')
}
},
'user',
'groups',
'comments.user',
'comments.media'
]
})
const posts = await Post.query(q => {
q.where('updated_at', '>', lastDigestAt)
q.where('active', true)
}).fetchAll({
withRelated: [
{
comments: q => {
q.where('created_at', '>', lastDigestAt)
q.orderBy('created_at', 'asc')
}
},
'user',
'groups',
'comments.user',
'comments.media'
]
})

const numSends = await Promise.all(posts.map(async post => {
const { comments } = post.relations
Expand Down
5 changes: 3 additions & 2 deletions api/models/event/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ export default {
},

eventInvitees: function () {
return this.belongsToMany(User).through(EventInvitation, 'event_id', 'user_id')
.withPivot('response')
return this.isEvent()
? this.belongsToMany(User).through(EventInvitation, 'event_id', 'user_id').withPivot('response')
: false
},

eventInvitations: function () {
Expand Down
4 changes: 2 additions & 2 deletions api/models/project/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
},

members: function () {
return this.followers().query(q => q.whereRaw('project_role_id is not null'))
return this.isProject() ? this.followers().query(q => q.whereRaw('project_role_id is not null')) : false
},

addProjectMembers: async function (usersOrIds, opts) {
Expand Down Expand Up @@ -44,7 +44,7 @@ export default {
post_id: this.id,
name: ProjectRole.MEMBER_ROLE_NAME
})
.save({}, opts)
.save({}, opts)
}
}
}
3 changes: 2 additions & 1 deletion api/services/Search/forPosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ export default function forPosts (opts) {
filterAndSortPosts(Object.assign({}, opts, {
search: opts.term,
sortBy: opts.sort,
showPinnedFirst: get(opts.groupIds, 'length') === 1
// Sort pinned posts first only when looking at a single group and not looking at chat room
showPinnedFirst: opts.type !== 'chat' && get(opts.groupIds, 'length') === 1
}), qb)

if (opts.omit) {
Expand Down
10 changes: 5 additions & 5 deletions lib/group/digest2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ export const sendDigest = (id, type, opts = {}) => {
.then(ok => ok && getRecipients(id, type)
.then(users => Promise.each(users, user => sendToUser(user, type, data, opts)))
.then(users => users.length)))
}
}

export const sendAllDigests = (type, opts) =>
Group.where({active: true}).query().pluck('id')
.then(ids => Promise.map(ids, id =>
sendDigest(id, type, opts).then(count => count && [id, count]))
.then(compact))
Group.where({ active: true }).query().pluck('id')
.then(ids => Promise.map(ids, id =>
sendDigest(id, type, opts).then(count => count && [id, count]))
.then(compact))

export const sendSampleData = address =>
Email.sendSimpleEmail(address, templateId, sampleData)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Tibet Sprague <[email protected]>",
"license": "GNU AFFERO GENERAL PUBLIC LICENSE v3",
"private": true,
"version": "5.6.0",
"version": "5.6.1",
"repository": {
"type": "git",
"url": "git://github.com/Hylozoic/hylo-node.git"
Expand Down

0 comments on commit 565170a

Please sign in to comment.