33namespace wcf \form ;
44
55use wcf \data \conversation \Conversation ;
6+ use wcf \data \conversation \message \ConversationMessageAction ;
7+ use wcf \data \conversation \message \ConversationMessageList ;
68use wcf \system \exception \IllegalLinkException ;
9+ use wcf \system \form \builder \data \processor \CustomFormDataProcessor ;
10+ use wcf \system \form \builder \IFormDocument ;
711use wcf \system \WCF ;
812
913/**
@@ -20,6 +24,11 @@ class ConversationDraftEditForm extends ConversationAddForm
2024 */
2125 public $ templateName = 'conversationAdd ' ;
2226
27+ /**
28+ * @inheritDoc
29+ */
30+ public $ formAction = 'edit ' ;
31+
2332 #[\Override]
2433 public function readParameters ()
2534 {
@@ -33,4 +42,72 @@ public function readParameters()
3342 throw new IllegalLinkException ();
3443 }
3544 }
45+
46+ #[\Override]
47+ public function finalizeForm ()
48+ {
49+ parent ::finalizeForm ();
50+
51+ $ this ->form ->getDataHandler ()
52+ ->addProcessor (
53+ new CustomFormDataProcessor (
54+ 'messageDataProcessor ' ,
55+ function (IFormDocument $ document , array $ parameters ) {
56+ $ messageData = [
57+ 'htmlInputProcessor ' => $ parameters ['message_htmlInputProcessor ' ],
58+ 'attachmentHandler ' => $ parameters ['message_attachmentHandler ' ],
59+ 'data ' => [],
60+ ];
61+ if ($ parameters ['data ' ]['isDraft ' ]) {
62+ $ messageData ['data ' ]['time ' ] = TIME_NOW ;
63+ }
64+
65+ unset($ parameters ['message_htmlInputProcessor ' ], $ parameters ['message_attachmentHandler ' ]);
66+
67+ $ parameters ['messageData ' ] = $ messageData ;
68+
69+ return $ parameters ;
70+ }
71+ )
72+ )
73+ ->addProcessor (
74+ new CustomFormDataProcessor ('timeProcessor ' , function (IFormDocument $ document , array $ parameters ) {
75+ if (!$ parameters ['data ' ]['isDraft ' ]) {
76+ $ parameters ['data ' ]['time ' ] = $ parameters ['data ' ]['lastPostTime ' ] = TIME_NOW ;
77+ }
78+
79+ return $ parameters ;
80+ })
81+ );
82+ }
83+
84+ #[\Override]
85+ public function saved ()
86+ {
87+ // Reload conversation object to get updated data.
88+ $ conversation = new Conversation ($ this ->formObject ->conversationID );
89+
90+ // Update timestamp of other messages in this draft.
91+ if (!$ conversation ->isDraft ) {
92+ $ list = new ConversationMessageList ();
93+ $ list ->getConditionBuilder ()->add ('conversationID = ? ' , [$ conversation ->conversationID ]);
94+ $ list ->getConditionBuilder ()->add ('messageID <> ? ' , [$ conversation ->getFirstMessage ()->messageID ]);
95+ $ list ->readObjectIDs ();
96+
97+ if (\count ($ list ->getObjectIDs ())) {
98+ $ messageAction = new ConversationMessageAction (
99+ $ list ->getObjectIDs (),
100+ 'update ' ,
101+ [
102+ 'data ' => [
103+ 'time ' => TIME_NOW ,
104+ ],
105+ ]
106+ );
107+ $ messageAction ->executeAction ();
108+ }
109+ }
110+
111+ parent ::saved ();
112+ }
36113}
0 commit comments