message: Refactor status-messages service
diff: @@ -2,6 +2,13 @@ import { service } from '@ember-decorators/service';
  import Service from '@ember/service';
  import config from 'ember-get-config';
  +const {
  + OSF: {
  + cookieDomain,
  + statusCookie,
  + },
  +} = config;
  +
  export interface StatusMessage {
  id: string;
  jumbo?: boolean;
  @@ -18,39 +25,33 @@ export default class StatusMessages extends Service {
  constructor() {
  super();
  - this.nextMessages = this._getCookieMessages();
  + this.nextMessages = this.getCookieMessages();
  }
  - _getCookieMessages(this: StatusMessages): StatusMessage[] {
  + getCookieMessages(this: StatusMessages): StatusMessage[] {
  const cookies = this.get('cookies');
  - if (!cookies.read(config.OSF.statusCookie)) {
  + const readCookie: string = cookies.read(statusCookie);
  +
  + if (!readCookie) {
  return [];
  }
  - // decode commas and \\
  - let status = cookies.read(config.OSF.statusCookie).replace(/\\054/g, ',').replace(/\\/g, '');
  - // remove outside quotes
  - status = status.slice(1, -1);
  - let messages = JSON.parse(status);
  - messages = messages.map(each => {
  - const updated = each;
  - updated.id = `status.${each.id}`;
  - return updated;
  - });
  - cookies.clear(config.OSF.statusCookie, {
  - domain: config.OSF.cookieDomain,
  +
  + cookies.clear(statusCookie, {
  + domain: cookieDomain,
  path: '/',
  });
  - return messages;
  - }
  - addMessage(this: StatusMessages): void {
  - // add status message to the messages array
  + const status = readCookie
  + .replace(/\\054/g, ',')
  + .replace(/^"|\\|"$/g, '');
  +
  + return JSON.parse(status)
  + .map(message => ({ ...message, id: `status.${message.id}` }));
  }
  updateMessages(this: StatusMessages): void {
  - const messages = this.get('nextMessages') || [];
  this.setProperties({
  - messages,
  + messages: this.get('nextMessages') || [],
  nextMessages: [],
  });
  }
  