Messaging Module
Using the messaging module you can send messages to other users. Each user has then an inbox where his income messages are stored.
Configuration
Nothing to configure here.
Usage
The messaging module provides you the class message model, which covers a message. To send a message, simply set the message text and the receivers user name (an other users user name) and post the message. The code:
Android
String textOfTheMessage =
"Hello world!"
;
String recipientUserName =
"exampleUser"
;
MessageModel mm =
new
MessageModel( );
mm.setMessageText( textOfTheMessage );
mm.setReceiverUserName( recipientUserName );
mm.saveAsync(
new
AOMEmptyCallback() {
@Override
public
void
isDone(ApiomatRequestException exception) {
if
(exception !=
null
) {
// ...
}
}
});
iOS
AOMMessageModel *mm = [[AOMMessageModel alloc] init];
[mm setMessageText:textOfTheMessage];
[mm setReceiverUserName:recipientUserUserName];
[mm saveAsyncWithBlock:^(NSError *error) {
}];
JavaScript
var
textOfTheMessage =
"Hello world!"
;
var
recipientUserName =
"exampleUser"
;
var
mm=
new
Apiomat.MessageModel();
mm.setMessageText(textOfTheMessage);
mm.setReceiverUserName(recipientUserName);
var
saveCB = {
onOk :
function
() {
console.log(
"saved"
);
},
onError :
function
(error) {
console.log(
"Some error occured: ("
+ error.statusCode +
")"
+ error.message);
}
};
mm.save(saveCB);
The user model for all your users is enriched with an inbox field, which is a list of message models containing all messages sent to this user. To fetch these messages just to the following:
Android
private
void
test() {
final
User user =
new
User();
user.loadAsync(
new
AOMEmptyCallback() {
@Override
public
void
isDone(ApiomatRequestException exception) {
if
(exception !=
null
) {
// ...
processMessages(user);
}
}
});
}
private
void
processMessages(
final
User user) {
String query =
"receiverUserName == \""
+ user.getUserName() +
"\""
;
MessageModel.getMessageModelsAsync(query,
new
AOMCallback<List<MessageModel>>() {
@Override
public
void
isDone(List<MessageModel> resultObject, ApiomatRequestException exception) {
if
( resultObject !=
null
&& exception !=
null
) {
for
( MessageModel m : resultObject ) {
System.out.println(m.getMessageText());
}
}
}
});
}
iOS
//To fetch these messages just to the following:
AOMUser *user = [[AOMUser alloc] init];
[user loadMeAsyncWithFinishingBlock:^(NSError *error) {
NSString query = [NSString stringWithFormat:@
"receiverUserName == \"%@\""
, [user userName] ];
[AOMMessageModel getAsyncWithQuery:query withBlock:^(NSMutableArray *messages, NSError *error) {
if
(error == FALSE && messages != NULL)
{
for
(AOMMessageModel *m in messages)
{
NSLog(@
"%@"
, [m messageText]);
}
}
}];
}];
JavaScript
function
test() {
var
user=
new
Apiomat.User();
var
loadCB = {
onOk :
function
() {
processMessages(user);
},
onError :
function
(error) {
console.log(
"Some error occured: ("
+ error.statusCode +
")"
+ error.message);
}
};
user.load(loadCB);
}
function
processMessages(user) {
var
query=
"receiverUserName == \""
+ user.getUserName() +
"\""
;
//TODO
Apiomat.MessageModel.getMessageModels(query,
new
AOMCallback<list <messagemodel=
""
>>() {
@Override
public void isDone(List<messagemodel> resultObject, ApiomatRequestException exception) {
if
( resultObject !=
null
&& exception !=
null
) {
for
( MessageModel m : resultObject ) {
System.out.println(m.getMessageText());
}
}
}
});
}
</messagemodel></list>
* link only available in Enterprise Documentation