Skip to content
Permalink
Browse files

Restore usage of base url for badges

  • Loading branch information...
lovett committed May 2, 2019
1 parent 6373d00 commit e50e8fc6366449ff640e9bf22f0ee70a6a445fb0
Showing with 25 additions and 4 deletions.
  1. +19 −3 server/Message.ts
  2. +1 −1 server/db.ts
  3. +1 −0 server/helpers/publish-message.ts
  4. +4 −0 server/routes/archive.ts
@@ -6,11 +6,11 @@ export default class Message {
public readonly localId?: string = undefined;
public readonly title?: string = undefined;
public readonly group?: string = undefined;
public readonly badge?: string = undefined;
public readonly source?: string = undefined;
public readonly url?: string = undefined;
public readonly received?: Date = undefined;
public readonly publicId: string;
public readonly publicId?: string = undefined;
public badge?: string = undefined;

constructor(bag: any) {
for (const key in this) {
@@ -23,6 +23,22 @@ export default class Message {
this.received = new Date();
}

this.publicId = uuid();
if (!this.publicId) {
this.publicId = uuid();
}
}

public urlizeBadge(baseUrl: string) {
if (!this.badge) {
return;
}

if (this.badge.startsWith('http')) {
return;
}

const baseWithoutTrailingSlash = baseUrl.replace(/\/%/, '');

this.badge = `${baseWithoutTrailingSlash}/${this.badge}`;
}
}
@@ -269,7 +269,7 @@ export async function getUnreadMessages(userId: number, startDate: Date, limit:

try {
const res = await pool.query(sql, [userId, startDate, limit]);
return res.rows as Message[];
return res.rows.map((row) => new Message(row));
} catch (err) {
console.log(err);
return [] as Message[];
@@ -26,6 +26,7 @@ export default (app: express.Application, userId: number, message: Message | nul
let jsonMessage: string | undefined;

if (message) {
message.urlizeBadge(app.locals.config.get('NOTIFIER_BADGE_BASE_URL'));
jsonMessage = JSON.stringify(message);
}

@@ -15,6 +15,10 @@ router.get('/:count?', async (req: express.Request, res: express.Response) => {
try {
const messages = await db.getUnreadMessages(req.user, startDate, count);

for (const message of messages) {
message.urlizeBadge(req.app.locals.config.get('NOTIFIER_BADGE_BASE_URL'));
}

res.send({
limit: count,
messages,

0 comments on commit e50e8fc

Please sign in to comment.
You can’t perform that action at this time.