Browse Source

FEATURE: add support for "Messages" in the sidebar

This also cleans up internals a bit so tracked tags are directly fetched
from the patched current user serializer
master
Sam Saffron 3 months ago
parent
commit
c1d09263ba
5 changed files with 136 additions and 69 deletions
  1. +31
    -1
      common/common.scss
  2. +1
    -2
      javascripts/discourse/initializers/title-widget.js.es6
  3. +42
    -13
      javascripts/sidebar-theme/connectors/shortcut-nav/shortcut-nav.hbs
  4. +61
    -53
      javascripts/sidebar-theme/connectors/shortcut-nav/shortcut-nav.js.es6
  5. +1
    -0
      locales/en.yml

+ 31
- 1
common/common.scss View File

@@ -192,6 +192,11 @@ ol.category-breadcrumb {
}
}

> a.active {
font-weight: bold;
color: $primary;
}

> a {
padding: 0.35em;
display: flex;
@@ -241,7 +246,8 @@ ol.category-breadcrumb {
background: $tertiary-low;
}

&.custom-tag-list {
&.custom-tag-list,
&.personal-messages {
li {
font-size: 0.875em;
&.active {
@@ -512,3 +518,27 @@ tr.visited {
grid-column-start: 2;
}
}

body.user-messages-page .viewing-self {
.about,
.user-secondary-navigation ul,
.user-primary-navigation {
display: none;
}
.user-content-wrapper .user-content {
grid-column-start: 1 !important;
}

.user-secondary-navigation {
position: relative;
grid-column-start: 2 !important;
button {
position: absolute;
right: 0;
}
}
}

.custom-nav-list.personal-messages li a.archive {
margin-left: 8px;
}

+ 1
- 2
javascripts/discourse/initializers/title-widget.js.es6 View File

@@ -1,5 +1,4 @@
import { withPluginApi } from "discourse/lib/plugin-api";
import { queryRegistry } from "discourse/widgets/widget";
import { h } from "virtual-dom";

export default {
@@ -9,7 +8,7 @@ export default {
withPluginApi("0.8", api => {
api.createWidget("custom-header-title", {
tagName: "span",
html(attrs, state) {
html() {
const path = window.location.pathname;
const container = Discourse.__container__;


+ 42
- 13
javascripts/sidebar-theme/connectors/shortcut-nav/shortcut-nav.hbs View File

@@ -42,21 +42,50 @@
</ul>
</div>
{{/if}}
{{/if}}

<!--
{{#if assignedTopics}}
<div class="custom-nav-list custom-assign-list">
<h3><a class="all-link" href="my/activity/assigned">Assigned</a> </h3>
<ul>
{{#each assignedTopics as |asgn|}}
<li><a href="/t/{{asgn.slug}}/{{asgn.id}}/{{asgn.last_read_post_number}}">{{asgn.title}}</a></li>
{{/each}}
</ul>

</div>
<div class="custom-nav-list personal-messages">
<h3>
{{#link-to 'userPrivateMessages.index' currentUser class="all-link"}}
{{theme-i18n "sidebar_title.messages"}}
{{/link-to}}
</h3>
<ul>
<li>
{{#link-to 'userPrivateMessages.index' currentUser}}
{{i18n 'user.messages.inbox'}}
{{/link-to}}
</li>
{{#if showUserArchive}}
<li>
{{#link-to 'userPrivateMessages.archive' currentUser class="archive"}}
{{i18n 'user.messages.archive'}}
{{/link-to}}
</li>
{{/if}}
<li>
{{#link-to 'userPrivateMessages.sent' currentUser}}
{{i18n 'user.messages.sent'}}
{{/link-to}}
</li>

{{#each userGroups as |group|}}
{{#if group.has_messages}}
<li>
{{#link-to 'userPrivateMessages.group' currentUser.username_lower group.name}}
{{capitalize-string group.name}}
{{/link-to}}
</li>
{{#if group.showArchive}}
<li class='archive group-archive'>
{{#link-to 'userPrivateMessages.groupArchive' currentUser.username_lower group.name class="archive"}}
{{i18n 'user.messages.archive'}}
{{/link-to}}
</li>
{{/if}}
{{/if}}
{{/each}}
</ul>
</div>
{{/if}}
-->
</div>
</div>

+ 61
- 53
javascripts/sidebar-theme/connectors/shortcut-nav/shortcut-nav.js.es6 View File

@@ -1,6 +1,7 @@
import { ajax } from "discourse/lib/ajax";
import { withPluginApi } from "discourse/lib/plugin-api";
import NavItem from "discourse/models/nav-item";
import User from "discourse/models/user";

const container = Discourse.__container__;

export default {
@@ -14,7 +15,7 @@ export default {
}.property("href")
});

if (Discourse.User.current()) {
if (User.current()) {
I18n.translations.en.js.filters.bookmarked = {
title: I18n.t(themePrefix("sidebar_filters.bookmarks")),
help: I18n.t(themePrefix("sidebar_filters.bookmarks"))
@@ -27,10 +28,7 @@ export default {
);
}

if (
Discourse.Site._current.siteSettings.assign_enabled &&
Discourse.User.current()
) {
if (Discourse.Site._current.siteSettings.assign_enabled && User.current()) {
I18n.translations.en.js.filters.assigned = {
title: "Assigned",
help: "Topics assigned to you"
@@ -49,7 +47,7 @@ export default {
});

withPluginApi("0.1", api => {
api.onPageChange((url, title) => {
api.onPageChange(() => {
if (component.isDestroying && component.isDestroyed) {
return false;
}
@@ -57,18 +55,17 @@ export default {
var cleanPath = path.replace(/\//g, "");

let trackedCats = [];
let currentUser = Discourse.User.current();
let username = currentUser.username;
let currentUser = User.current();

component.set("currentUser", currentUser);

// Setting active state for All Topics pages
if (/^bookmarks/.test(cleanPath)) {
var filterMode = "bookmarked";
filterMode = "bookmarked";
} else if (/activityassigned/.test(cleanPath)) {
var filterMode = "assigned";
filterMode = "assigned";
} else {
var filterMode = cleanPath;
filterMode = cleanPath;
}
this.setProperties({
filterMode
@@ -97,6 +94,41 @@ export default {
}
});
component.set("trackedCats", trackedCats);
component.set("userGroups", currentUser.groups);

const router = api.container.lookup("router:main");
const route = router.currentRoute;
const isCurrentUserPath =
document.location.pathname.indexOf(
"/u/" + currentUser.username_lower
) > -1;
if (
route &&
(route.name === "userPrivateMessages.index" ||
route.name === "userPrivateMessages.sent" ||
route.name === "userPrivateMessages.archive") &&
isCurrentUserPath
) {
component.set("showUserArchive", true);
} else {
component.set("showUserArchive", false);
}

if (currentUser.groups) {
currentUser.groups.forEach(group => {
if (group.has_messages) {
let showArchive =
route &&
(route.name === "userPrivateMessages.group" ||
route.name === "userPrivateMessages.groupArchive") &&
isCurrentUserPath;
showArchive =
showArchive &&
document.location.pathname.indexOf("group/" + group.name) > 0;
group.set("showArchive", showArchive);
}
});
}

// This is for hiding the nav on the user assign page without loading jank
if (/\/u\//.test(path) && !/\/activity\/assigned/.test(path)) {
@@ -105,52 +137,28 @@ export default {
document.querySelector("body").classList.remove("show-nav");
}

$(function() {
// Get tracked tags
// Get tracked tags
let trackedTags = [];
let currentTag;

let trackedTags = [];
let currentTag;
if (/^\/tags\//.test(path)) {
const controller = container.lookup("controller:tags");
currentTag = controller.get("target.currentRoute.params.tag_id");
}

if (/^\/tags\//.test(path)) {
const controller = container.lookup("controller:tags");
currentTag = controller.get("target.currentRoute.params.tag_id");
const tagCombo = [].concat(
currentUser.watched_tags,
currentUser.tracked_tags
);
tagCombo.forEach(function(tag) {
if (tag === currentTag) {
trackedTags.push([tag, true]);
} else {
trackedTags.push([tag, false]);
}

ajax("/u/" + username + ".json").then(function(result) {
const tagCombo = [].concat(
result.user.watched_tags,
result.user.tracked_tags
);
tagCombo.forEach(function(tag) {
if (tag === currentTag) {
trackedTags.push([tag, true]);
} else {
trackedTags.push([tag, false]);
}
});

component.set("trackedTags", trackedTags);
});
});
/*
$(function() {
// Get assigned topics

if (Discourse.Site._current.siteSettings.assign_enabled) {
let assignedTopics = [];

ajax("/topics/messages-assigned/" + username + ".json").then(
function(assigned) {
assigned.topic_list.topics.forEach(function(topic) {
assignedTopics.push(topic);
});

component.set("assignedTopics", assignedTopics);
}
);
}
});
*/
component.set("trackedTags", trackedTags);
});
});
}

+ 1
- 0
locales/en.yml View File

@@ -3,6 +3,7 @@ en:
all_topics: "All topics"
categories: "Categories"
tags: "Tags"
messages: "Messages"
no_categories: "<a href='/my/preferences/categories'>Start tracking or watching categories</a> and they'll be listed here."
sidebar_filters:
bookmarks: "Bookmarked"

Loading…
Cancel
Save