mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 21:27:23 +01:00
* split component prepare new views / states
* extract empty and disabled state as components
* fix empty state mail icon
* first logic switching between modes, move page to /private-messages/index.vue
* extract autoCompleteHelper.js
* style header + start new message input
* style plus button + focus input
* state logic, types for sanity
* WIP PM new Message started
* add /members/username test
* first design changes to messageCard
* delete private message or chat - based on the mode
* copy as todo
* mention links to modal
* report chat or private message
* WIP likeButton
* likeButton styling
* hide like on private message cards
* fix unit test
* replace copy as todo - to just a copy to clipboard
* style changes
* menu position + like button width
* dropdown items background + like font
* fix like button padding
* move api endpoints and tests around to group inbox methods + like for inbox private messages
* restyle system messages
* Dropdown Radius and Padding
* WIP system messages
* fix lint
* copy delta commit of allowing liking own private messages
* enable liking private messages
* fix menu non hovered item icon color
* fix import path
* ignore background on system messages
* requested changes + migration
* update migration to update the unique id to some messages and delete the duplicates
* migration based on users pagination
* fix(migration): use Promise.all
* change to bulkWrites per User, and all messages in one run (of a user)
* check for array
* use rest operator ...
* skip sorting to get the users
* remove migration, disable like for private messages without uniqueMessageId
* lean+bulkWrite for likes, add time checks for like and auth for further debugging
* add a limit 2 get the messages by uniqueId
* Adding a simple server start script
* remove pinned nodemon dep
* fix inbox controller/tests
* fix / requested style changes
* fix empty state padding /
* hide avatar weapons on messages - fix avatar spacing on messages
* Hourglass Simplification (#15323)
* begin removing obsolete tests
* begin refactoring
* update cron tests
* cleanup
* finish basic implementation of new logic
* add more subscription tests
* subscription test improvements
* return nextHourglassDate again
* fix gem limit
* fix(test): short circuit this.
* fix(admin): correct logic and style for shrimple subs
* WIP(frontend): draft of main subs page view
* fix hourglass count
* Fix hourglass logic for upgrades
* fix admin panel display
* WIP(subs): extant Stripe state
* fix admin panel strings
* fix missing transaction type
* add new field for cumulative subscription count
* show date for hourglass bonus if it was received
* fix test
* feat(subscription): max Gems progress readout
* fix(css): correct and refactor heights and selection states
* fix(subs): correct border-radius and redirect
* fix(stripe): correct redirect after success
* Admin panel display fixes
* don’t give additional HG for new sub if they already got one this month
* fix issue with promo hourglasses
* fix(subscription): update layout when gifting
* fix(subscriptions): more gift layout revisions
* fix(subscriptions): minor visual updates
* fix(subs): pass autoRenews through Stripe
* fix(subs): gifts DON't renew
* fix(lint): unnecessary ternary
* fix(lint): do negate object ig
* fix(subs): try again on gifts
* fix(subs): unhovery and un-12-monthy
* fix bug with incorrectly giving HG bonus
* remove only
* fix test
* fix test
* fix(subs): also redirect to subs after gift sub
* fix(subs): fix typeError
* fix(g1g1): don't try to find Gems promo during bogo
---------
Co-authored-by: Phillip Thelen <phillip@habitica.com>
Co-authored-by: Kalista Payne <sabe@habitica.com>
* chore(sprites): update subproject
* fix(layout): tighten cancellation note
* fix(subs): Google wording and HG escape
* chore(testing): fake g1g1 dates
* fix(subs): don't hide HG preview entirely
* fix(subs): center next hourglass message
* working validatedTextInput.vue within start-new-conversation-input-header.vue 🎉
* fix(git): remove changes from old develop
* Revert "fix(git): remove changes from old develop"
This reverts commit 0e30f7df00.
* fix(git): no actually just this file i guesss
* adding an empty loading state, hiding
* fought the avatar arch nemesis again
* fix chatMessages (party chat) message spacing
* move disabled text back to above the input area - re-enable input area
* show disabled private messages top panel
* fix font color
* fixing uiStates - removing disabled - moving the own user check to the last
* fix(lint): add missing prop defaults
* fix(lint): object default should be fn
* fix(chat): correct grammar in error
---------
Co-authored-by: SabreCat <sabe@habitica.com>
Co-authored-by: Kalista Payne <sabrecat@gmail.com>
Co-authored-by: Phillip Thelen <phillip@habitica.com>
140 lines
3.7 KiB
JavaScript
140 lines
3.7 KiB
JavaScript
import { mapInboxMessage, inboxModel } from '../../models/message';
|
|
import { getUserInfo, sendTxn as sendTxnEmail } from '../email'; // eslint-disable-line import/no-cycle
|
|
import { sendNotification as sendPushNotification } from '../pushNotifications';
|
|
|
|
export async function sentMessage (sender, receiver, message, translate) {
|
|
const messageSent = await sender.sendMessage(receiver, { receiverMsg: message });
|
|
const senderName = getUserInfo(sender, ['name']).name;
|
|
|
|
if (receiver.preferences.emailNotifications.newPM !== false) {
|
|
sendTxnEmail(receiver, 'new-pm', [
|
|
{ name: 'SENDER', content: senderName },
|
|
]);
|
|
}
|
|
|
|
if (receiver.preferences.pushNotifications.newPM !== false && messageSent.unformattedText) {
|
|
await sendPushNotification(
|
|
receiver,
|
|
{
|
|
title: translate(
|
|
'newPMNotificationTitle',
|
|
{ name: getUserInfo(sender, ['name']).name },
|
|
receiver.preferences.language,
|
|
),
|
|
message: messageSent.unformattedText,
|
|
identifier: 'newPM',
|
|
category: 'newPM',
|
|
payload: { replyTo: sender._id, senderName, message: messageSent.unformattedText },
|
|
},
|
|
);
|
|
}
|
|
|
|
return messageSent;
|
|
}
|
|
const PM_PER_PAGE = 10;
|
|
|
|
const getUserInboxDefaultOptions = {
|
|
asArray: true,
|
|
page: undefined,
|
|
conversation: null,
|
|
mapProps: false,
|
|
};
|
|
|
|
export async function getUserInbox (user, optionParams = getUserInboxDefaultOptions) {
|
|
// if not all properties are passed, fill the default values
|
|
const options = { ...getUserInboxDefaultOptions, ...optionParams };
|
|
|
|
const findObj = { ownerId: user._id };
|
|
|
|
if (options.conversation) {
|
|
findObj.uuid = options.conversation;
|
|
}
|
|
|
|
let query = inboxModel
|
|
.find(findObj)
|
|
.sort({ timestamp: -1 });
|
|
|
|
if (typeof options.page !== 'undefined') {
|
|
query = query
|
|
.skip(PM_PER_PAGE * Number(options.page))
|
|
.limit(PM_PER_PAGE);
|
|
} else {
|
|
// Limit for legacy calls that are not paginated to prevent database issues
|
|
query = query.limit(200);
|
|
}
|
|
|
|
const messages = (await query.lean().exec()).map(msgObj => {
|
|
delete msgObj.__v;
|
|
if (options.mapProps) {
|
|
mapInboxMessage(msgObj, user);
|
|
}
|
|
|
|
return msgObj;
|
|
});
|
|
|
|
if (options.asArray) {
|
|
return messages;
|
|
}
|
|
const messagesObj = {};
|
|
messages.forEach(msg => { messagesObj[msg._id] = msg; });
|
|
|
|
return messagesObj;
|
|
}
|
|
|
|
export async function applyLikeToMessages (user, uniqueMessages) {
|
|
const bulkWriteOperations = [];
|
|
|
|
for (const message of uniqueMessages) {
|
|
if (!message.likes) {
|
|
message.likes = {};
|
|
}
|
|
|
|
message.likes[user._id] = !message.likes[user._id];
|
|
|
|
bulkWriteOperations.push({
|
|
updateOne: {
|
|
filter: { _id: message._id },
|
|
update: {
|
|
$set: {
|
|
likes: message.likes,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
}
|
|
|
|
await inboxModel.bulkWrite(bulkWriteOperations, {});
|
|
}
|
|
|
|
export async function getInboxMessagesByUniqueId (uniqueMessageId) {
|
|
return inboxModel
|
|
.find({ uniqueMessageId })
|
|
// prevents creating the proxies, no .save() and other stuff
|
|
.lean()
|
|
// since there can be only 2 messages maximum for this uniqueMessageId,
|
|
// this might speed up the query
|
|
.limit(2)
|
|
.exec();
|
|
}
|
|
|
|
export async function getUserInboxMessage (user, messageId) {
|
|
return inboxModel.findOne({ ownerId: user._id, _id: messageId }).exec();
|
|
}
|
|
|
|
export async function deleteMessage (user, messageId) {
|
|
const message = await inboxModel.findOne({ _id: messageId, ownerId: user._id }).exec();
|
|
if (!message) return false;
|
|
await inboxModel.deleteOne({ _id: message._id, ownerId: user._id }).exec();
|
|
|
|
return true;
|
|
}
|
|
|
|
export async function clearPMs (user) {
|
|
user.inbox.newMessages = 0;
|
|
|
|
await Promise.all([
|
|
user.save(),
|
|
inboxModel.deleteMany({ ownerId: user._id }).exec(),
|
|
]);
|
|
}
|