mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
Merge branch 'master' into develop
This commit is contained in:
@@ -229,6 +229,10 @@ Notes.assertPrivate = async (object) => {
|
||||
// Given an object, adds it to an existing chat or creates a new chat otherwise
|
||||
// todo: context stuff
|
||||
|
||||
if (!object || !object.id || !activitypub.helpers.isUri(object.id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const localUids = [];
|
||||
const recipients = new Set([...object.to, ...object.cc]);
|
||||
await Promise.all(Array.from(recipients).map(async (value) => {
|
||||
|
||||
@@ -52,6 +52,9 @@ utils.tokens.get = async (tokens) => {
|
||||
};
|
||||
|
||||
utils.tokens.generate = async ({ uid, description }) => {
|
||||
if (!srcUtils.isNumber(uid)) {
|
||||
throw new Error('[[error:invalid-uid]]');
|
||||
}
|
||||
if (parseInt(uid, 10) !== 0) {
|
||||
const uidExists = await user.exists(uid);
|
||||
if (!uidExists) {
|
||||
@@ -66,7 +69,7 @@ utils.tokens.generate = async ({ uid, description }) => {
|
||||
};
|
||||
|
||||
utils.tokens.add = async ({ token, uid, description = '', timestamp = Date.now() }) => {
|
||||
if (!token || uid === undefined) {
|
||||
if (!token || uid === undefined || !srcUtils.isNumber(uid)) {
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
|
||||
@@ -80,6 +83,9 @@ utils.tokens.add = async ({ token, uid, description = '', timestamp = Date.now()
|
||||
};
|
||||
|
||||
utils.tokens.update = async (token, { uid, description }) => {
|
||||
if (!srcUtils.isNumber(uid)) {
|
||||
throw new Error('[[error:invalid-uid]]');
|
||||
}
|
||||
await Promise.all([
|
||||
db.setObject(`token:${token}`, { uid, description }),
|
||||
db.sortedSetAdd(`tokens:uid`, uid, token),
|
||||
|
||||
@@ -11,8 +11,6 @@ const privileges = require('../privileges');
|
||||
const activitypub = require('../activitypub');
|
||||
const utils = require('../utils');
|
||||
|
||||
const isEmojiShortcode = /^:[\w]+:$/;
|
||||
|
||||
module.exports = function (Posts) {
|
||||
Posts.create = async function (data) {
|
||||
// This is an internal method, consider using Topics.reply instead
|
||||
@@ -54,9 +52,15 @@ module.exports = function (Posts) {
|
||||
if (_activitypub && _activitypub.tag && Array.isArray(_activitypub.tag)) {
|
||||
_activitypub.tag
|
||||
.filter(tag => tag.type === 'Emoji' &&
|
||||
isEmojiShortcode.test(tag.name) &&
|
||||
tag.icon && tag.icon.mediaType && tag.icon.mediaType.startsWith('image/'))
|
||||
tag.icon && tag.icon.type === 'Image')
|
||||
.forEach((tag) => {
|
||||
if (!tag.name.startsWith(':')) {
|
||||
tag.name = `:${tag.name}`;
|
||||
}
|
||||
if (!tag.name.endsWith(':')) {
|
||||
tag.name = `${tag.name}:`;
|
||||
}
|
||||
|
||||
postData.content = postData.content.replace(new RegExp(tag.name, 'g'), `<img class="not-responsive emoji" src="${tag.icon.url}" title="${tag.name}" />`);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<form role="form">
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="uid">[[admin/settings/api:uid]]</label>
|
||||
<input type="text" inputmode="numeric" pattern="\d+" name="uid" class="form-control" placeholder="0" value="{./uid}" />
|
||||
<input id="uid" type="number" inputmode="numeric" pattern="\d+" name="uid" class="form-control" placeholder="0" value="{./uid}" />
|
||||
<p class="form-text">
|
||||
[[admin/settings/api:uid-help-text]]
|
||||
</p>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="description">[[admin/settings/api:description]]</label>
|
||||
<input type="text" name="description" class="form-control" placeholder="Description" value="{./description}" />
|
||||
<input id="description" type="text" name="description" class="form-control" placeholder="Description" value="{./description}" />
|
||||
</div>
|
||||
</form>
|
||||
@@ -128,7 +128,7 @@ describe('Analytics', () => {
|
||||
let counters;
|
||||
({ counters } = analytics.peek());
|
||||
const before = { ...counters };
|
||||
|
||||
const { setTimeout } = require('timers/promises');
|
||||
const id = `https://example.org/activity/${utils.generateUUID()}`;
|
||||
await controllers.activitypub.postInbox({
|
||||
body: {
|
||||
@@ -141,13 +141,13 @@ describe('Analytics', () => {
|
||||
},
|
||||
},
|
||||
}, { sendStatus: () => {} });
|
||||
|
||||
await setTimeout(2000);
|
||||
({ counters } = analytics.peek());
|
||||
const after = { ...counters };
|
||||
|
||||
const metrics = ['activities', 'activities:byType:Like', 'activities:byHost:example.org'];
|
||||
metrics.forEach((metric) => {
|
||||
assert(before[metric] && after[metric]);
|
||||
assert(before[metric] && after[metric], JSON.stringify({ before, after }, null, 2));
|
||||
assert(before[metric] < after[metric]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user