Skip to content

Instantly share code, notes, and snippets.

@justin
Created April 22, 2014 19:19
Show Gist options
  • Save justin/11191090 to your computer and use it in GitHub Desktop.
Save justin/11191090 to your computer and use it in GitHub Desktop.
import statusInfo = require('./StatusInfo');
import commentInfo = require('./CommentInfo');
var uuid = require('node-uuid');
/**
Various types of user notifications that we can send.
The numeric values are sent to the client apps (Android, iOS, etc) so be careful changing them
*/
enum NotificationType {
// The numeric values are sent to the client apps (Android, iOS, etc) so be careful changing them
NewStatusNotification = 1,
NewCommentNotification = 2,
ExistingUserInvitation = 3,
NewUserInvitation = 4,
PasswordReset = 5,
NewUserValidationNotification = 6,
MonitorAlertNotification = 7,
RequestToJoinDecided = 8,
NewUserValidationReminder = 9,
UserAddedFromChairInvitation = 11,
InvoiceNotification = 12,
UserInfoUpdatedNotification = 13,
DeleteUserRequest = 14,
DeleteBoardRequest = 15,
SubscriptionCancelled = 16,
BoardExportAvailable = 17,
BoardExportFailed = 18,
ReplyByEmailFailed = 19,
AdminTestPushNotification = 20,
StatusUpdated = 21,
CommentUpdated = 22,
LikeAdded = 23,
LikeRemoved = 24,
BoardInfoUpdated = 25,
DeleteBoardMemberRequest = 26
}
class BaseNotificationInfo {
private _type: NotificationType;
constructor(public inType: NotificationType) {
this._type = inType;
}
// Accessor Methods
get type(): NotificationType {
return this._type;
}
set type(newType: NotificationType) {
if (this._type != newType) {
this._type = newType;
}
}
}
class NotificationInfo extends BaseNotificationInfo {
private _id: string;
private _boardId: string;
private _statusId: string;
private _commentId: string;
private _authorUserId: string;
private _invitationId: string;
private _invitationUserId: string;
private _invitationEmailAddress: string;
constructor(options?) { super(options); }
static createStatusNotification(inStatus: statusInfo.StatusInfo) {
var status = new NotificationInfo();
status.id = uuid.v4();
status.boardId = inStatus.boardId;
status.statusId = inStatus.id;
status.authorUserId = inStatus.authorId;
status.type = NotificationType.NewStatusNotification;
}
static createCommentNotification(inStatus: statusInfo.StatusInfo, inComment: commentInfo.CommentInfo) {
var comment = new NotificationInfo();
comment.id = uuid.v4();
comment.boardId = inStatus.boardId;
comment.statusId = inStatus.id;
comment.commentId = inComment.id;
comment.authorUserId = inComment.authorId;
comment.type = NotificationType.NewCommentNotification;
}
// Accessor Methods
get id(): string {
return this._id;
}
get boardId(): string {
return this._boardId;
}
get statusId(): string {
return this._statusId;
}
get commentId(): string {
return this._commentId;
}
get authorUserId(): string {
return this._authorUserId;
}
get invitationId(): string {
return this._invitationId;
}
get invitationUserId(): string {
return this._invitationUserId;
}
get invitationEmailAddress(): string {
return this._invitationEmailAddress;
}
}
class BoardInfoUpdatedNotification extends BaseNotificationInfo {
private _boardId: string;
constructor(inBoardId: string) {
this._boardId = inBoardId;
super(NotificationType.BoardInfoUpdated);
}
get boardId(): string {
return this._boardId;
}
set boardId(inBoardId: string) {
this._boardId = inBoardId;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment