Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ Controllers.renderAdminPage = (req, res) => {
});
};

Controllers.renderProfilePage = async (req, res) => {
res.send(`
<html>
<head></head>
<body></body>
<script>
window.onload = function () {
loadPageOutsideIFrame();
}
function loadPageOutsideIFrame() {
if (window !== window.parent) {
console.log('breaking out of iframe')
location.parent.href = ${req.params.redirectUrl}
} else {
location.href = ${req.params.redirectUrl}
}
}
</script>
</html>`);
res.end();
};

Controllers.renderThemeSettings = async (req, res, next) => {
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, req.query);
if (!userData) {
Expand Down
37 changes: 22 additions & 15 deletions library.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,20 +191,6 @@ library.filterTeasersConfigureStripTags = function (hookData) {
return hookData;
};

library.filterProfileLinks = async function (data) {
const postContent = data.postData.content;
const config = await library.loadThemeConfig(0);

const regex = /<a class="plugin-mentions-user plugin-mentions-a" href="(https:\/\/(.+))\/uid\/(\d+)">@(.*)<\/a>/gi;
const newContent = postContent.replace(regex, (atag, schemehost, host, uid, uname) => {
let result = atag.replace(`${schemehost}/uid`, config.catalystProfileUrl);
result = result.replace(`class="`, `target="_top" class="`);
return result;
});

return { ...data, postData: { ...data.postData, content: newContent } };
};

library.createUser = function (data, callback) {
data.user.did = data.data.did;
callback(null, data);
Expand All @@ -231,7 +217,7 @@ const getChatroomForGroup = async (slug) => {
};

library.addChatToCategory = function (data, callback) {
privileges.categories.list(data.category.cid).then((res, err) => {
privileges.categories.list(data.category.cid).then((res) => {
const projectGroup = res.groups.find(group => group.isPrivate && group.name.startsWith('Project '));
if (!projectGroup) {
return callback(null, data);
Expand All @@ -243,3 +229,24 @@ library.addChatToCategory = function (data, callback) {
});
});
};
const removeTrailingSlash = (url) => {
if (url.endsWith('/')) {
return url.slice(0, -1);
}
return url;
};

library.redirectToCatalystProfile = async function (data) {
const config = await library.loadThemeConfig(0);
const baseUrl = removeTrailingSlash(config.catalystUrl.replace('https://', ''));
return controllers.renderProfilePage(
{
params: {
...data.req.params,
redirectUrl: `https://${baseUrl}/profile/${data.templateData.username}`,
},
...data.req,
},
data.res
);
};
3 changes: 2 additions & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
{ "hook": "filter:user.whitelistFields", "method": "whitelistFields" },

{ "hook": "filter:category.get", "method": "addChatToCategory"},
{ "hook": "filter:parse.post", "method": "filterProfileLinks", "priority": 11}
{ "hook": "filter:parse.post", "method": "filterProfileLinks", "priority": 11},
{ "hook": "filter:account/profile.build", "method": "redirectToCatalystProfile", "priority": 11}

],
"scripts": [
Expand Down
76 changes: 0 additions & 76 deletions templates/partials/chats/message.tpl

This file was deleted.

3 changes: 1 addition & 2 deletions templates/partials/topic/post.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@


<span class="text-nowrap">
<!--a class="fw-bold" href="{{{ if ./user.userslug }}}{config.relative_path}/user/{./user.userslug}{{{ else }}}#{{{ end }}}" data-username="{posts.user.username}" data-uid="{posts.user.uid}" target="_parent">{posts.user.displayname}</a -->
<a class="fw-bold" href="{config.theme.catalystProfileUrl}/{./user.uid}" target="_parent">{posts.user.displayname}</a>
<a id="testing-parent" class="fw-bold" href="{{{ if ./user.userslug }}}{config.relative_path}/user/{./user.userslug}{{{ else }}}#{{{ end }}}" data-username="{posts.user.username}" data-uid="{posts.user.uid}">{posts.user.displayname} hello world</a>
</span>

{{{ each posts.user.selectedGroups }}}
Expand Down