mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Attach client to chat messages (#10845)
* Attach client to chat messages * Word * Design tweaks * Fix potential error
This commit is contained in:
committed by
Matteo Pagliazzi
parent
2bebaf2cf8
commit
42b146d5d0
@@ -15,7 +15,8 @@ div
|
|||||||
p.time
|
p.time
|
||||||
span.mr-1(v-if="msg.username") @{{ msg.username }}
|
span.mr-1(v-if="msg.username") @{{ msg.username }}
|
||||||
span.mr-1(v-if="msg.username") •
|
span.mr-1(v-if="msg.username") •
|
||||||
span(v-b-tooltip="", :title="msg.timestamp | date") {{ msg.timestamp | timeAgo }}
|
span(v-b-tooltip="", :title="msg.timestamp | date") {{ msg.timestamp | timeAgo }}
|
||||||
|
span(v-if="msg.client && user.contributor.level >= 4") ({{ msg.client }})
|
||||||
.text(v-html='atHighlight(parseMarkdown(msg.text))')
|
.text(v-html='atHighlight(parseMarkdown(msg.text))')
|
||||||
hr
|
hr
|
||||||
.d-flex(v-if='msg.id')
|
.d-flex(v-if='msg.id')
|
||||||
|
|||||||
@@ -175,7 +175,11 @@ api.postChat = {
|
|||||||
throw new NotAuthorized(res.t('messageGroupChatSpam'));
|
throw new NotAuthorized(res.t('messageGroupChatSpam'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const newChatMessage = group.sendChat(req.body.message, user);
|
let client = req.headers['x-client'] || '3rd Party';
|
||||||
|
if (client) {
|
||||||
|
client = client.replace('habitica-', '');
|
||||||
|
}
|
||||||
|
const newChatMessage = group.sendChat(req.body.message, user, null, client);
|
||||||
let toSave = [newChatMessage.save()];
|
let toSave = [newChatMessage.save()];
|
||||||
|
|
||||||
if (group.type === 'party') {
|
if (group.type === 'party') {
|
||||||
|
|||||||
@@ -480,8 +480,8 @@ schema.methods.getMemberCount = async function getMemberCount () {
|
|||||||
return await User.count(query).exec();
|
return await User.count(query).exec();
|
||||||
};
|
};
|
||||||
|
|
||||||
schema.methods.sendChat = function sendChat (message, user, metaData) {
|
schema.methods.sendChat = function sendChat (message, user, metaData, client) {
|
||||||
let newMessage = messageDefaults(message, user);
|
let newMessage = messageDefaults(message, user, client);
|
||||||
let newChatMessage = new Chat();
|
let newChatMessage = new Chat();
|
||||||
newChatMessage = Object.assign(newChatMessage, newMessage);
|
newChatMessage = Object.assign(newChatMessage, newMessage);
|
||||||
newChatMessage.groupId = this._id;
|
newChatMessage.groupId = this._id;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ const defaultSchema = () => ({
|
|||||||
flags: {$type: mongoose.Schema.Types.Mixed, default: {}},
|
flags: {$type: mongoose.Schema.Types.Mixed, default: {}},
|
||||||
flagCount: {$type: Number, default: 0},
|
flagCount: {$type: Number, default: 0},
|
||||||
likes: {$type: mongoose.Schema.Types.Mixed},
|
likes: {$type: mongoose.Schema.Types.Mixed},
|
||||||
|
client: String,
|
||||||
_meta: {$type: mongoose.Schema.Types.Mixed},
|
_meta: {$type: mongoose.Schema.Types.Mixed},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -100,7 +101,7 @@ export function setUserStyles (newMessage, user) {
|
|||||||
newMessage.markModified('userStyles');
|
newMessage.markModified('userStyles');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function messageDefaults (msg, user) {
|
export function messageDefaults (msg, user, client) {
|
||||||
const id = uuid();
|
const id = uuid();
|
||||||
const message = {
|
const message = {
|
||||||
id,
|
id,
|
||||||
@@ -110,6 +111,7 @@ export function messageDefaults (msg, user) {
|
|||||||
likes: {},
|
likes: {},
|
||||||
flags: {},
|
flags: {},
|
||||||
flagCount: 0,
|
flagCount: 0,
|
||||||
|
client,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
|
|||||||
Reference in New Issue
Block a user