NAME
Ado::Model::Vest - A class for TABLE vest
SYNOPSIS
#select messages from a talk
my $messages =
Ado::Model::Vest->by_subject_message_id(
$user, $s_m_id, $limit, $offset)
#list them
foreach(@$messages){
..
}
# create a new message
Ado::Model::Vest->create(%params, tstamp => time);
Look at Ado::Control::Vest for a wealth of usage examples.
DESCRIPTION
This class provides methods for manipulating messages and talks. It uses the table vest
as storage. A message is a record in table vest
. A talk consists of a set of messages, having the same value in column "subject_message_id" and one record which column "id" has the same value. In other words, the record which "id" value is referenced by other records in "subject_message_id", is the parent record, that defines a talk. This is the first message in a talk.
COLUMNS
Each column from table vest
has an accessor in this class.
id
The primary key for the message. INTEGER PRIMARY KEY AUTOINCREMENT
.
from_uid
Id of the user who sends the message. INT(11) REFERENCES users(id) NOT NULL
.
to_uid
Id of the user to whom the message is sent. INT(11) REFERENCES users(id) DEFAULT 0
. Can be zero (0) in case the message is sent to the whole group. This way we can have group talks.
In case both to_uid and to_guid values are zero, the sender is talking to him self - Taking Notes. See "to_guid".
to_guid
Id of the group to which the message is sent. INT(11) REFERENCES groups(id) DEFAULT 0
. In case the value is zero (0) the message is private. If it has to_uid!=0
, the message can be seen by the user referenced by to_uid
, otherwise only the user referenced by from_uid
can see the message.
subject
Subject (topic) of the talk. VARCHAR(255) DEFAULT ''
. Only the first message in a talk has a subject. Every next message has subject=''
.
subject_message_id
Id of the first message in a talk. The first message in a talk has subject_message_id=0
. Eevery next message has subject_message_id
equal to the id
of the first message. There can be many conversations in a group or between two users.
tstamp
Last modification time. All dates are stored as seconds since the epoch(1970). In Perl we use a Time::Piece object to format this value as we wish.
message
The message it self. TEXT
.
message_assets
File-paths (relative to $app->home
) of Files attached to this message - TODO.
permissions
Can be used in case the message is published as status update and it should be readable only by certain users. VARCHAR(10) NOT NULL DEFAULT '-rw-r-----'
.
seen
Incremented by 1 by the client chat application when the message is displayed on the screen of the user referred by to_uid
or by some member of the group referred by to_guid
. INTEGER DEFAULT 0
. TODO.
METHODS
Ado::Model::Vest inherits all methods from Ado::Model and implements the following new ones.
by_subject_message_id
Selects messages from a talk within a given range, ordered by talk id descending and returns an ARRAY reference of HASHES. Only messages that are viewable by the current user are selected
my $messages = Ado::Model::Vest->by_subject_message_id(
$c->user, $subject_message_id, $limit, $offset
);
count_messages
Counts messages in a talk for a user by given subject_message_id Returns an integer.
my $count = Ado::Model::Vest->count_messages($user, $s_m_id);
create
Creates a new message. Performs a check If there is a talk with id
equal to the subject_message_id
of the message or if the subject of the message is equal to a talk subject. Depending on the results either creates a new talk or a new message within a talk. In case the message is part of an existing talk the subject
is set to ''; Returns $self
.
talks
Selects records which contain talk subjects(topics) (subject!=''
) from all messages within a given range, ordered by talk id descending and returns an ARRAYref of HASHES. Only messages that are viewable by the current user are selected.
my $messages = Ado::Model::Vest->talks($c->user, $limit, $offset);
GENERATOR
This class was initially generated using DBIx::Simple::Class::Schema and later edited and enriched by the author.
SEE ALSO
Ado::Model, DBIx::Simple::Class, DBIx::Simple::Class::Schema