This repository was archived by the owner on Aug 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 604
Expand file tree
/
Copy pathmessage.coffee
More file actions
executable file
·62 lines (54 loc) · 1.71 KB
/
message.coffee
File metadata and controls
executable file
·62 lines (54 loc) · 1.71 KB
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
{Base,ObjectId,secure} = require 'bongo'
Module = require './module'
Attachment = require './attachment'
module.exports = class Message extends Module
@set
schema :
originType :
type : String
required : yes
originId :
type : ObjectId
required : yes
title : String # TODO: do we need title AND subject?
subject : String
body : String
repliesCount :
type : Number
default : 0
attachments : [Attachment]
meta : require 'bongo/bundles/meta'
# teaserFields : ['originType','originId','subject','repliesCount','meta.createdAt','meta.modifiedAt']
@getIsRepliable =-> yes
@getDefaultRole =-> 'message'
# constructor: (account, message)->
# if message and 'string' isnt typeof message
# {body, subject} = message
# unless account.getId?
# console.log account, account.constructor
# super {
# originType : account.constructor.name
# originId : account.getId()
# subject
# body
# }
fetchOrigin: (callback)->
originType = @getAt 'originType'
originId = @getAt 'originId'
if Base.constructors[originType]?
Base.constructors[originType].one {_id: originId}, callback
else
callback null
sign:(account)->
@originType = account.constructor.name
@originId = account.getId()
@
@create =(account, data, callback)->
constructor = @
message = new constructor data
message.sign account
message.validate (err)->
console.log arguments
message.save (err)->
callback? err, message
@setStructure =(structure)->