All files / src/model SeamailThread.ts

65.22% Statements 15/23
100% Branches 0/0
57.14% Functions 4/7
68.42% Lines 13/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 634x 4x   4x               4x   19x   17x   17x 17x   43x     20x     17x             18x           18x                                              
import { SeamailMessage } from './SeamailMessage';
import { User } from './User';
 
import { Util } from '../internal/Util';
 
import { Moment } from 'moment';
 
/**
 * Represents a Seamail thread.
 * @module SeamailThread
 */
export class SeamailThread {
  public static fromRest(data: any) {
    Util.assertHasProperties(data, 'id', 'subject', 'timestamp');
 
    const ret = new SeamailThread();
 
    Util.setProperties(ret, data, 'id', 'subject', 'message_count', 'count_is_unread', 'is_unread');
    Util.setDateProperties(ret, data, 'timestamp');
    if (!Util.isEmpty(data.users)) {
      ret.users = data.users.map((user: any) => User.fromRest(user));
    }
    if (!Util.isEmpty(data.messages)) {
      ret.messages = data.messages.map((message: any) => SeamailMessage.fromRest(message));
    }
 
    return ret;
  }
 
  /** The unique thread id. */
  public id: string;
 
  /** The users involved in the message. */
  public users: User[] = [];
 
  /** The subject of the thread. */
  public subject: string;
 
  /** The messages in the thread. */
  public messages: SeamailMessage[] = [];
 
  /** The number of messages (or unread messages) in the thread. */
  public message_count: number;
 
  /** The time the most recent message was created. */
  public timestamp: Moment;
 
  /** Whether `message_count` is unread or total. */
  public count_is_unread: false;
 
  /** Whether there are unread messages in the thread. */
  public is_unread: false;
 
  public toJSON() {
    const ret = {} as any;
    Util.setProperties(ret, this, 'id', 'subject', 'message_count', 'count_is_unread', 'is_unread');
    ret.users = this.users.map(user => user.toJSON());
    ret.messages = this.messages.map(message => message.toJSON());
    ret.timestamp = this.timestamp.valueOf();
    return ret;
  }
}