1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Threema message callback listener. (example). |
4
|
|
|
* |
5
|
|
|
* @package ThreemaGateway |
6
|
|
|
* @author rugk |
7
|
|
|
* @copyright Copyright (c) 2015-2016 rugk |
8
|
|
|
* @license MIT |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Listeners for custom activity when a text message is received. |
13
|
|
|
*/ |
14
|
|
|
class ThreemaGateway_Listener_MessageCallback |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Receives text messages. |
18
|
|
|
* |
19
|
|
|
* @param ThreemaGateway_Handler_Action_Callback $handler |
20
|
|
|
* @param Threema\MsgApi\Helpers\ReceiveMessageResult $receiveResult |
21
|
|
|
* @param Threema\MsgApi\Messages\ThreemaMessage $threemaMsg |
22
|
|
|
* @param array|string $output [$logType, $debugLog, $publicLog] |
23
|
|
|
* @param bool $saveMessage |
24
|
|
|
* @param bool $debugMode |
25
|
|
|
* |
26
|
|
|
* @throws XenForo_Exception |
27
|
|
|
*/ |
28
|
|
|
public static function testCallbackPreSave(ThreemaGateway_Handler_Action_Callback $handler, |
29
|
|
|
Threema\MsgApi\Helpers\ReceiveMessageResult $receiveResult, |
30
|
|
|
Threema\MsgApi\Messages\ThreemaMessage $threemaMsg, |
31
|
|
|
&$output, |
32
|
|
|
&$saveMessage, |
33
|
|
|
$debugMode) |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
// for performance reasons you should check first, whether the message |
36
|
|
|
// meets your requirements respectively needs to be handled by the |
37
|
|
|
// listener. |
38
|
|
|
if ($threemaMsg->getText() != 'test message') { |
39
|
|
|
// IMPORTANT: Do not return false as this would cause all other |
40
|
|
|
// registered listeners to stop! You may not want to do that. |
41
|
|
|
return; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
// first check whether message has already been saved to prevent replay attacks |
45
|
|
|
$handler->assertNoReplayAttack($receiveResult->getMessageId()); |
46
|
|
|
|
47
|
|
|
// it is useful to add some logging messages for easier debugging |
48
|
|
|
$handler->addLog($output, 'Message will not be saved to database!'); |
49
|
|
|
|
50
|
|
|
// here you can do something with your text messages |
51
|
|
|
$saveMessage = false; // e.g. prevent saving! |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Receives text messages after saving them. |
56
|
|
|
* |
57
|
|
|
* @param ThreemaGateway_Handler_Action_Callback $handler |
58
|
|
|
* @param Threema\MsgApi\Helpers\ReceiveMessageResult $receiveResult |
59
|
|
|
* @param Threema\MsgApi\Messages\ThreemaMessage $threemaMsg |
60
|
|
|
* @param array|string $output [$logType, $debugLog, $publicLog] |
61
|
|
|
* @param bool $debugMode |
62
|
|
|
*/ |
63
|
|
|
public static function testCallbackPostSave(ThreemaGateway_Handler_Action_Callback $handler, |
64
|
|
|
Threema\MsgApi\Helpers\ReceiveMessageResult $receiveResult, |
|
|
|
|
65
|
|
|
Threema\MsgApi\Messages\ThreemaMessage $threemaMsg, |
|
|
|
|
66
|
|
|
&$output, |
67
|
|
|
$messageSaved, |
68
|
|
|
$debugMode) |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
if (!$messageSaved) { |
71
|
|
|
// this should only be shown when testCallbackPreSave has been executed |
72
|
|
|
// or another listener prevented saving of the data. |
73
|
|
|
$handler->addLog($output, 'This is the message, which has not been saved!'); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.