diff options
| -rw-r--r-- | bucky/app/api.js | 4 | ||||
| -rw-r--r-- | bucky/app/bucky.js | 8 | ||||
| -rw-r--r-- | bucky/db/index.js | 3 | ||||
| -rw-r--r-- | public/assets/css/bucky.css | 19 | ||||
| -rw-r--r-- | public/assets/js/lib/views/index/index.js | 9 | ||||
| -rw-r--r-- | public/assets/js/lib/views/index/threadform.js | 22 | ||||
| -rw-r--r-- | public/assets/js/lib/views/mail/mailbox.js | 13 | ||||
| -rw-r--r-- | views/pages/index.ejs | 1 | ||||
| -rw-r--r-- | views/pages/mailbox.ejs | 4 |
9 files changed, 64 insertions, 19 deletions
diff --git a/bucky/app/api.js b/bucky/app/api.js index 63e480e..f0474a4 100644 --- a/bucky/app/api.js +++ b/bucky/app/api.js @@ -52,11 +52,13 @@ function route (app){ bucky.ensureKeywordsForThreads, bucky.ensureHootbox, bucky.bumpLastSeen, + bucky.checkMail, function(req, res){ res.json({ threads: res.threads, hootbox: res.hootbox, lastlog: res.lastlog, + mail: res.mail, }) }) app.post("/api/keyword/new", @@ -75,12 +77,14 @@ function route (app){ bucky.ensureFileCountsForThreads, bucky.ensureKeywordsForThreads, bucky.ensureHootbox, + bucky.checkMail, function(req, res){ res.json({ keyword: res.keyword, threads: res.threads, hootbox: res.hootbox, lastlog: res.lastlog, + mail: res.mail, }) }) app.get("/api/thread/:id", diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js index cd70790..47eb7e1 100644 --- a/bucky/app/bucky.js +++ b/bucky/app/bucky.js @@ -611,9 +611,15 @@ var bucky = module.exports = { next() }) }, + checkMail: function(req, res, next){ + db.checkMail(req.user.get('username')).then(function(mail){ + res.mail = mail ? mail[0] : { count: 0 } + next() + }) + }, markMessageUnread: function(req, res, next){ if (res.message.get('unread')) { - res.message.set('unread', false) + res.message.set('unread', 0) res.message.save().then(() => next()) } else { next() diff --git a/bucky/db/index.js b/bucky/db/index.js index d3ee2ea..b10e3d8 100644 --- a/bucky/db/index.js +++ b/bucky/db/index.js @@ -252,6 +252,9 @@ db.createMailbox = function(data){ db.bumpMailboxCount = function(mbox){ new db.Mailbox({ mbox: mbox }).fetch() } +db.checkMail = function(username){ + return knex.count('* as count').select().from('messages').where('recipient', '=', username).andWhere('unread', '=', 1) +} /* MESSAGES */ diff --git a/public/assets/css/bucky.css b/public/assets/css/bucky.css index 1dadaf0..e0c5be0 100644 --- a/public/assets/css/bucky.css +++ b/public/assets/css/bucky.css @@ -82,6 +82,21 @@ h1 { margin-top: 2px; margin-bottom: 4px; } +.bluebox.alert { + display: none; + background-color: #ff6666; +} +.bluebox.alert a { + font-family: georgia, garamond, serif; + font-weight: bold; + color: #000; + display: block; + padding: 10px; + font-size: 12px; +} +.desktop .bluebox.alert a:hover { + color: #000; +} a.headline:link, a.headline:visited { color: #111; text-decoration: none; } a.headline h1 { text-decoration: none; } @@ -835,6 +850,10 @@ pre br { #messages { width: 100%; } +#messages .unread { + font-weight: bold; + text-decoration: underline; +} #messages tr td:nth-child(1) { text-align: right; padding-right: 3px; diff --git a/public/assets/js/lib/views/index/index.js b/public/assets/js/lib/views/index/index.js index 3f217fc..edf5483 100644 --- a/public/assets/js/lib/views/index/index.js +++ b/public/assets/js/lib/views/index/index.js @@ -34,6 +34,15 @@ var IndexView = View.extend({ this.hootbox.load(data.hootbox) this.threadbox.load(data) this.lastlog.load(data.lastlog) + if (data.mail.count) { + $(".alert").show().html( + "<a href='/mail'>" + + "You have " + + data.mail.count + + " new message" + + courtesy_s(data.mail.count) + + "!</a>") + } $(".search_form input").focus() }, diff --git a/public/assets/js/lib/views/index/threadform.js b/public/assets/js/lib/views/index/threadform.js index 7a8e8ed..b2e1963 100644 --- a/public/assets/js/lib/views/index/threadform.js +++ b/public/assets/js/lib/views/index/threadform.js @@ -1,18 +1,18 @@ var ThreadForm = FormView.extend({ - + el: "#thread_form", - + events: { }, - + action: "/api/thread", method: "POST", - + initialize: function(){ this.__super__.initialize.call(this) this.template = this.$(".template").html() }, - + load: function(selected_keyword){ $.get("/api/keywords", function(data){ var tags = {} @@ -21,17 +21,19 @@ var ThreadForm = FormView.extend({ var opt = document.createElement('option') opt.value = kw opt.innerHTML = kw - if (selected_keyword === kw) { - opt.setAttribute("selected", "selected") - } tags[kw] = opt }) var sorted = Object.keys(tags).sort().map(kw => tags[kw]) this.$('[name=keyword]').append(sorted) + if (selected_keyword) { + this.$('[name=keyword]').val(selected_keyword) + } else { + this.$('[name=keyword]').val('unsorted') + } $("body").removeClass('loading') }.bind(this)) }, - + validate: function(){ var errors = [] var title = this.$("[name=title]").val() @@ -52,4 +54,4 @@ var ThreadForm = FormView.extend({ } window.location.href = "/details/" + data.id } -})
\ No newline at end of file +}) diff --git a/public/assets/js/lib/views/mail/mailbox.js b/public/assets/js/lib/views/mail/mailbox.js index 22a49c5..5635a7d 100644 --- a/public/assets/js/lib/views/mail/mailbox.js +++ b/public/assets/js/lib/views/mail/mailbox.js @@ -1,24 +1,24 @@ var MailboxView = View.extend({ el: "#messages", - + events: { 'click .discard_link': 'discard', }, - + action: "/api/mailbox/", - + initialize: function(){ this.__super__.initialize.call(this) this.template = this.$(".template").html() this.boxlist = new BoxList () }, - + load: function(name){ name = sanitize(name) || "inbox" $("h1").html(name) $.get(this.action + name, this.populate.bind(this)) }, - + populate: function(data){ if (data.boxes) { this.boxlist.load(data.boxes) @@ -37,7 +37,7 @@ var MailboxView = View.extend({ } $("body").removeClass('loading') }, - + parse: function(message, user){ var datetime = verbose_date(message.date) var size = hush_size(message.size) @@ -47,6 +47,7 @@ var MailboxView = View.extend({ var t = this.template .replace(/{{id}}/g, message.id) .replace(/{{to}}/g, is_sender ? "to " : "") + .replace(/{{unread}}/g, message.unread ? "unread" : "") .replace(/{{username}}/g, is_sender ? message.recipient : message.sender) .replace(/{{subject}}/g, message.subject) .replace(/{{date}}/g, datetime[0]) diff --git a/views/pages/index.ejs b/views/pages/index.ejs index 8b4e033..1a6255b 100644 --- a/views/pages/index.ejs +++ b/views/pages/index.ejs @@ -8,6 +8,7 @@ <div id="sidebar"> <% include ../partials/searchform %> + <div class="bluebox alert"></div> <span class="lastlog bluebox"> <script class="template" type="text/html"> <a href="/profile/{{username}}">{{username}}</a> diff --git a/views/pages/mailbox.ejs b/views/pages/mailbox.ejs index d06bd7a..a0304d7 100644 --- a/views/pages/mailbox.ejs +++ b/views/pages/mailbox.ejs @@ -6,7 +6,7 @@ </div> <div id="content"> - + <h3 id="no_messages"> No messages </h3> @@ -19,7 +19,7 @@ {{to}} <a href="/profile/{{username}}">{{username}}</a> · </td> <td class="ivory"> - <a href="/mail/read/{{id}}">{{subject}}</a> + <a href="/mail/read/{{id}}" class="{{unread}}">{{subject}}</a> </td> <td class="{{date_class}}"> {{date}} <small>{{time}}</small> |
