本文整理汇总了Java中codeu.chat.common.Message类的典型用法代码示例。如果您正苦于以下问题:Java Message类的具体用法?Java Message怎么用?Java Message使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Message类属于codeu.chat.common包,在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newMessage
import codeu.chat.common.Message; //导入依赖的package包/类
@Override
public Message newMessage(Uuid author, Uuid conversation, String body) {
Message response = null;
try (final Connection connection = source.connect()) {
Serializers.INTEGER.write(connection.out(), NetworkCode.NEW_MESSAGE_REQUEST);
Uuid.SERIALIZER.write(connection.out(), author);
Uuid.SERIALIZER.write(connection.out(), conversation);
Serializers.STRING.write(connection.out(), body);
if (Serializers.INTEGER.read(connection.in()) == NetworkCode.NEW_MESSAGE_RESPONSE) {
response = Serializers.nullable(Message.SERIALIZER).read(connection.in());
} else {
LOG.error("Response from server failed.");
}
} catch (Exception ex) {
System.out.println("ERROR: Exception during call on server. Check log for details.");
LOG.error(ex, "Exception during call on server.");
}
return response;
}
示例2: getMessages
import codeu.chat.common.Message; //导入依赖的package包/类
@Override
public Collection<Message> getMessages(Collection<Uuid> ids) {
final Collection<Message> messages = new ArrayList<>();
try (final Connection connection = source.connect()) {
Serializers.INTEGER.write(connection.out(), NetworkCode.GET_MESSAGES_BY_ID_REQUEST);
Serializers.collection(Uuid.SERIALIZER).write(connection.out(), ids);
if (Serializers.INTEGER.read(connection.in()) == NetworkCode.GET_MESSAGES_BY_ID_RESPONSE) {
messages.addAll(Serializers.collection(Message.SERIALIZER).read(connection.in()));
} else {
LOG.error("Response from server failed.");
}
} catch (Exception ex) {
System.out.println("ERROR: Exception during call on server. Check log for details.");
LOG.error(ex, "Exception during call on server.");
}
return messages;
}
示例3: createSendToRelayEvent
import codeu.chat.common.Message; //导入依赖的package包/类
private Runnable createSendToRelayEvent(final Uuid userId,
final Uuid conversationId,
final Uuid messageId) {
return new Runnable() {
@Override
public void run() {
final User user = view.findUser(userId);
final ConversationHeader conversation = view.findConversation(conversationId);
final Message message = view.findMessage(messageId);
relay.write(id,
secret,
relay.pack(user.id, user.name, user.creation),
relay.pack(conversation.id, conversation.title, conversation.creation),
relay.pack(message.id, message.content, message.creation));
}
};
}
示例4: countRecentMessages
import codeu.chat.common.Message; //导入依赖的package包/类
private int countRecentMessages(Time lastUpdate, Uuid searchConversation) {
// Given a time value for the last time that a check for recent messages was
// requested and the UUID of the conversation to search through, return a count
// of messages in the specified conversation that were created after the
// specified time.
int newMessages = 0;
final ConversationPayload searchConversationPayload = model.conversationPayloadById().first(searchConversation);
Message currentMessage = model.messageById().first(searchConversationPayload.firstMessage);
while(currentMessage != null) {
if(lastUpdate.compareTo(currentMessage.creation) < 0) {
newMessages++;
}
currentMessage = model.messageById().first(currentMessage.next);
}
return newMessages;
}
示例5: testAddMessage
import codeu.chat.common.Message; //导入依赖的package包/类
@Test
public void testAddMessage() {
final User user = controller.newUser("user");
assertFalse(
"Check that user has a valid reference",
user == null);
final ConversationHeader conversation = controller.newConversation(
"conversation",
user.id);
assertFalse(
"Check that conversation has a valid reference",
conversation == null);
final Message message = controller.newMessage(
user.id,
conversation.id,
"Hello World");
assertFalse(
"Check that the message has a valid reference",
message == null);
}
示例6: createSendToRelayEvent
import codeu.chat.common.Message; //导入依赖的package包/类
private Runnable createSendToRelayEvent(final Uuid userId,
final Uuid conversationId,
final Uuid messageId) {
return new Runnable() {
@Override
public void run() {
final User user = view.findUser(userId);
final Conversation conversation = view.findConversation(conversationId);
final Message message = view.findMessage(messageId);
relay.write(id,
secret,
relay.pack(user.id, user.name, user.creation),
relay.pack(conversation.id, conversation.title, conversation.creation),
relay.pack(message.id, message.content, message.creation));
}
};
}
示例7: getMessages
import codeu.chat.common.Message; //导入依赖的package包/类
@Override
public Collection<Message> getMessages(Uuid conversation, Time start, Time end) {
final Conversation foundConversation = model.conversationById().first(conversation);
final List<Message> foundMessages = new ArrayList<>();
Message current = (foundConversation == null) ?
null :
model.messageById().first(foundConversation.firstMessage);
while (current != null && current.creation.compareTo(start) < 0) {
current = model.messageById().first(current.next);
}
while (current != null && current.creation.compareTo(end) <= 0) {
foundMessages.add(current);
current = model.messageById().first(current.next);
}
return foundMessages;
}
示例8: testAddMessage
import codeu.chat.common.Message; //导入依赖的package包/类
@Test
public void testAddMessage() {
final User user = controller.newUser("user");
assertFalse(
"Check that user has a valid reference",
user == null);
final Conversation conversation = controller.newConversation(
"conversation",
user.id);
assertFalse(
"Check that conversation has a valid reference",
conversation == null);
final Message message = controller.newMessage(
user.id,
conversation.id,
"Hello World");
assertFalse(
"Check that the message has a valid reference",
message == null);
}
示例9: add
import codeu.chat.common.Message; //导入依赖的package包/类
public MessageContext add(String messageBody) {
final Message message = controller.newMessage(user.id,
conversation.id,
messageBody);
return message == null ?
null :
new MessageContext(message, view);
}
示例10: restoreJsonObjects
import codeu.chat.common.Message; //导入依赖的package包/类
private void restoreJsonObjects(String lineBeingRead) {
// lineElements[0] will contain the proper identifier (Convo, Message, User)
// Then, according to the identifier, the proper object will be restored
String[] lineElements = lineBeingRead.split(";");
switch (lineElements[0]) {
// Each case will feed the object directly into model except Messages
case "User":
User loadUser = gson.fromJson(lineElements[1], User.class);
model.add(loadUser);
break;
case "Convo":
ConversationHeader loadConvo = gson.fromJson(lineElements[1], ConversationHeader.class);
model.add(loadConvo);
break;
case "Message":
// Message object cannot be directly fed into model
// Instead, each value, and the original conversation value, is
// passed into the Controller method
Uuid messageConvo = gson.fromJson(lineElements[1], Uuid.class);
Message loadMessage = gson.fromJson(lineElements[2], Message.class);
controller.newMessage(loadMessage.id, loadMessage.author, messageConvo, loadMessage.content, loadMessage.creation);
break;
default:
break;
}
}
示例11: addToContributions
import codeu.chat.common.Message; //导入依赖的package包/类
private void addToContributions(Message newCurrentMessage, boolean newFoundMessage, Time lastUpdate, Uuid searchUser) {
// go through every message
while(currentMessage != null && foundMessage == false) {
// check for a matching user UUID and a creation time after the last status update
if(lastUpdate.compareTo(currentMessage.creation) < 0 && currentMessage.author.equals(searchUser)) {
// add the conversation's title to the collection and break the loop for this conversation
contributions.add(convoPayloadId.title);
foundMessage = true;
}
currentMessage = model.messageById().first(currentMessage.next);
}
}
示例12: testAddMessage
import codeu.chat.common.Message; //导入依赖的package包/类
@Test
public void testAddMessage() {
final User user = controller.newUser(userId, "user", Time.now());
assertFalse(
"Check that user has a valid reference",
user == null);
assertTrue(
"Check that the user has the correct id",
Uuid.equals(user.id, userId));
final ConversationHeader conversation = controller.newConversation(
conversationId,
"conversation",
user.id,
Time.now());
assertFalse(
"Check that conversation has a valid reference",
conversation == null);
assertTrue(
"Check that the conversation has the correct id",
Uuid.equals(conversation.id, conversationId));
final Message message = controller.newMessage(
messageId,
user.id,
conversation.id,
"Hello World",
Time.now());
assertFalse(
"Check that the message has a valid reference",
message == null);
assertTrue(
"Check that the message has the correct id",
Uuid.equals(message.id, messageId));
}
示例13: getAllMessages
import codeu.chat.common.Message; //导入依赖的package包/类
private void getAllMessages(ConversationSummary conversation) {
messageListModel.clear();
for (final Message m : clientContext.message.getConversationContents(conversation)) {
// Display author name if available. Otherwise display the author UUID.
final String authorName = clientContext.user.getName(m.author);
final String displayString = String.format("%s: [%s]: %s",
((authorName == null) ? m.author : authorName), m.creation, m.content);
messageListModel.addElement(displayString);
}
}
示例14: addMessage
import codeu.chat.common.Message; //导入依赖的package包/类
public void addMessage(Uuid author, Uuid conversation, String body) {
final boolean validInputs = isValidBody(body) && (author != null) && (conversation != null);
final Message message = (validInputs) ? controller.newMessage(author, conversation, body) : null;
if (message == null) {
System.out.format("Error: message not created - %s.\n",
(validInputs) ? "server error" : "bad input value");
} else {
LOG.info("New message:, Author= %s UUID= %s", author, message.id);
current = message;
}
updateMessages(false);
}
示例15: showAllMessages
import codeu.chat.common.Message; //导入依赖的package包/类
public void showAllMessages() {
if (conversationContents.size() == 0) {
System.out.println(" Current Conversation has no messages");
} else {
for (final Message m : conversationContents) {
printMessage(m, userContext);
}
}
}