MyChat Server event: OnUserStateChange, changing a user's status
The event is generated when the user's status changes. For example, when they connect to the server, disconnect from it, change their status manually ("Free" / "Do Not Disturb") or automatically when there is no activity ("Away").
When working with user statuses, there are many nuances that the server somehow resolves, because there can be several devices online at once logged in under the same account. For example, Windows application, WEB browser connection, and iPhone applications. The server keeps track of all combinations of statuses for each specific connection and displays some approximate result according to a complex algorithm.
Event template
procedure OnUserStateChange(const iUIN, iState: integer);
begin
// your own code
end;
begin
end.
You can put your code instead of the comment.
Description of parameters
Parameter |
Type |
Value |
iUIN |
integer |
user's ID; |
iState |
integer |
status type of a user. |
Example
const
WATCH_USER_UIN = 3;
INFORM_USER_UIN = 6;
procedure OnUserStateChange(const iUIN, iState: integer);
var
s: string;
begin
if iUIN = WATCH_USER_UIN then begin
case iState of
-1: s := 'offline';
0: s := 'free, online';
1: s := 'away, online';
2: s := 'do not disturb, online';
end;
mSendPrivateMessage(0, INFORM_USER_UIN,
'User ' + mGetUserAttribute(WATCH_USER_UIN, 'DisplayName') + ' is ' + s, 1);
end;
end;
begin
end.
The script detects when the status changes and notifies another user about thi by a private message on behalf of the built-in bot Elisa (UIN 0).