This repository was archived by the owner on Sep 25, 2022. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,14 +13,104 @@ module.exports = class Message {
1313 this . channel = channelId ;
1414 this . team = teamId ;
1515 this . id = id ;
16- this . content = content ;
16+ this . content = this . parseDom ( content ) ;
1717 this . createdAt = new Date ( createdAt ) ;
1818 this . createdAtTimestamp = this . createdAt . getTime ( ) ;
1919 this . author = authorId ;
2020 }
2121
22+ parseDom ( dom ) {
23+ dom = dom . document . nodes ;
24+ let message = {
25+ lines : [ ] ,
26+ text : ''
27+ } ;
28+
29+ dom . forEach ( node => {
30+ switch ( node . type ) {
31+
32+ case 'paragraph' : {
33+ let line = {
34+ text : '' ,
35+ nodes : [ ]
36+ } ;
37+ node . nodes . forEach ( p => {
38+ switch ( p . object ) {
39+
40+ case 'text' : {
41+ p . leaves . forEach ( l => {
42+ let text = l . text ;
43+ if ( text != '' ) {
44+ line . nodes . push ( {
45+ type : 'text' ,
46+ text : text . replace ( / \r / g, '' )
47+ } ) ;
48+ line . text += text ;
49+ }
50+ } ) ;
51+ break ;
52+ }
53+
54+ case 'inline' : {
55+ switch ( p . type ) {
56+
57+ case 'reaction' : {
58+ line . nodes . push ( {
59+ type : 'emoji' ,
60+ emoji : {
61+ id : p . data . reaction . id ,
62+ name : p . data . reaction . customReaction . name ,
63+ image : p . data . reaction . customReaction . png
64+ }
65+ } ) ;
66+ line . text += `${ p . nodes [ 0 ] . leaves [ 0 ] . text } ` ;
67+ break ;
68+ }
69+
70+ case 'mention' : {
71+ line . nodes . push ( {
72+ type : 'mention' ,
73+ user : p . data . mention . id
74+ } ) ;
75+ line . text += `@${ p . data . mention . name } ` ;
76+ break ;
77+ }
78+
79+ case 'channel' : {
80+ line . nodes . push ( {
81+ type : 'channel' ,
82+ channel : p . data . channel . id
83+ } ) ;
84+ line . text += `#${ p . data . channel . name } ` ;
85+ break ;
86+ }
87+
88+ }
89+ break ;
90+ }
91+
92+ }
93+ } ) ;
94+ message . lines . push ( line . nodes ) ;
95+ message . text += line . text + '\n' ;
96+ break ;
97+ }
98+
99+ case 'block-quote-container' : {
100+ break ;
101+ }
102+
103+ case 'markdown-plain-text' : {
104+ break ;
105+ }
106+
107+ }
108+ } ) ;
109+ message . text = message . text . replace ( / \r / g, '' ) . substring ( 0 , message . text . length - 1 ) ;
110+ return message ;
111+ }
112+
22113 async update ( ) {
23114
24115 }
25116} ;
26-
You can’t perform that action at this time.
0 commit comments