本文整理汇总了Java中org.jivesoftware.smack.chat.Chat类的典型用法代码示例。如果您正苦于以下问题:Java Chat类的具体用法?Java Chat怎么用?Java Chat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Chat类属于org.jivesoftware.smack.chat包,在下文中一共展示了Chat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendDisplayedReceipt
import org.jivesoftware.smack.chat.Chat; //导入依赖的package包/类
public void sendDisplayedReceipt(String receiverJid, String stanzaId, String dialog_id) {
Chat chat;
if ((chat = privateChats.get(receiverJid)) == null) {
chat = ChatManager.getInstanceFor(privateChatConnection).createChat(receiverJid, this);
privateChats.put(receiverJid, chat);
}
Message message = new Message(receiverJid);
Displayed read = new Displayed(stanzaId);
QuickbloxChatExtension extension = new QuickbloxChatExtension();
extension.setProperty("dialog_id", dialog_id);
message.setStanzaId(StanzaIdUtil.newStanzaId());
message.setType(Message.Type.chat);
message.addExtension(read);
message.addExtension(extension);
try {
chat.sendMessage(message);
} catch (SmackException.NotConnectedException ex) {
Logger.logExceptionToFabric(ex);
offlineMessages.add(message);
}
}
示例2: sendReceivedReceipt
import org.jivesoftware.smack.chat.Chat; //导入依赖的package包/类
public void sendReceivedReceipt(String receiverJid, String stanzaId, String dialog_id) {
Chat chat;
if ((chat = privateChats.get(receiverJid)) == null) {
chat = ChatManager.getInstanceFor(privateChatConnection).createChat(receiverJid, this);
privateChats.put(receiverJid, chat);
}
Message message = new Message(receiverJid);
Received delivered = new Received(stanzaId);
QuickbloxChatExtension extension = new QuickbloxChatExtension();
extension.setProperty("dialog_id", dialog_id);
message.setStanzaId(StanzaIdUtil.newStanzaId());
message.setType(Message.Type.chat);
message.addExtension(delivered);
message.addExtension(extension);
try {
chat.sendMessage(message);
} catch (SmackException.NotConnectedException ex) {
offlineMessages.add(message);
}
}
示例3: sendPrivateMessage
import org.jivesoftware.smack.chat.Chat; //导入依赖的package包/类
public void sendPrivateMessage(String body, String receiverJid, long timestamp, String stanzaId) {
Log.d(TAG, "Sending message to : " + receiverJid);
Chat chat;
if ((chat = privateChats.get(receiverJid)) == null) {
chat = ChatManager.getInstanceFor(privateChatConnection).createChat(receiverJid, this);
privateChats.put(receiverJid, chat);
}
QuickbloxChatExtension extension = new QuickbloxChatExtension();
extension.setProperty("date_sent", timestamp + "");
extension.setProperty("save_to_history", "1");
Message message = new Message(receiverJid);
message.setStanzaId(stanzaId);
message.setBody(body);
message.setType(Message.Type.chat);
message.addExtension(new Markable());
message.addExtension(extension);
try {
chat.sendMessage(message);
} catch (SmackException.NotConnectedException ex) {
offlineMessages.add(message);
}
}
示例4: processMessage
import org.jivesoftware.smack.chat.Chat; //导入依赖的package包/类
public void processMessage(Chat chat, Message message) {
ExtensionElement extension = message.getExtension(NAMESPACE);
if (extension == null) {
return;
}
ChatState state;
try {
state = ChatState.valueOf(extension.getElementName());
}
catch (Exception ex) {
return;
}
fireNewChatState(chat, state);
}
示例5: sendMessage
import org.jivesoftware.smack.chat.Chat; //导入依赖的package包/类
@Test
@BenchmarkOptions(benchmarkRounds = 10, warmupRounds = 0, concurrency = 10)
// round: 1.05 [+- 0.07], round.block: 0.74 [+- 0.25], round.gc: 0.00 [+-
// 0.00], GC.calls: 1, GC.time: 0.01, time.total: 1.08, time.warmup: 0.00,
// time.bench: 1.08
public void sendMessage() throws Exception {
XMPPConnection xmppConnection = xmppConnectionFactory.getXMPPConnection();
System.out.println(xmppConnection);
//
ChatManager chatManager = ChatManager.getInstanceFor(xmppConnection);
Chat chat = chatManager.createChat("[email protected]");
chat.sendMessage("test_123");
//
PoolableXmppConnection conn = (PoolableXmppConnection) xmppConnection;
conn.disconnect();
}
示例6: processMessage
import org.jivesoftware.smack.chat.Chat; //导入依赖的package包/类
@Override
public void processMessage(Chat chat, Message message) {
if (message.getBody() == null) {
return;
}
if (message.getType() == Message.Type.groupchat) {
messageService.get().processPublicMessage(message);
return;
}
messageService.get().processPrivateMessage(message);
}
示例7: chatCreated
import org.jivesoftware.smack.chat.Chat; //导入依赖的package包/类
@Override
public void chatCreated(Chat chat, boolean createdLocally) {
if (!privateChats.containsKey(chat.getParticipant())) {
chat.addMessageListener(this);
privateChats.put(chat.getParticipant().split("/")[0], chat);
}
}
示例8: onChatCreated
import org.jivesoftware.smack.chat.Chat; //导入依赖的package包/类
void onChatCreated(Chat chatCreated) {
if (chat != null) {
if (chat.getParticipant().equals(chatCreated.getParticipant())) {
chat.removeMessageListener(messageListener);
chat = chatCreated;
chat.addMessageListener(messageListener);
}
} else {
chat = chatCreated;
chat.addMessageListener(messageListener);
}
}
示例9: sendRaw
import org.jivesoftware.smack.chat.Chat; //导入依赖的package包/类
/**
* send the raw string as a message without wrapping it with xml attributes
* @param message the message to be sent
* @param buddyJID the buddy to send the message to
*/
public void sendRaw(String message, String buddyJID){
ChatManager chatManager = ChatManager.getInstanceFor(connection);
if (connection != null && connection.isConnected() && chatManager != null){
try{
Chat chat = chatManager.createChat(buddyJID);
chat.sendMessage(message);
}catch (Exception e){
e.printStackTrace();
}
}
}
示例10: sendTextMessage
import org.jivesoftware.smack.chat.Chat; //导入依赖的package包/类
/**
* sends a text message
*
* @param message the message text to send
* @param buddyJID the Buddy to receive the message
* @return true if sending was successful
*/
public boolean sendTextMessage(String message, String buddyJID, long id){
ChatManager chatManager = ChatManager.getInstanceFor(connection);
if (connection != null && connection.isConnected() && chatManager != null){
if (buddyJID.indexOf('@') == -1)
buddyJID += "@" + service;
Chat chat = chatManager.createChat(buddyJID);
try{
// wrap the message with all necessary xml attributes
Document doc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().newDocument();
Element msg = doc.createElement("message");
doc.appendChild(msg);
msg.setAttribute("type", MessageHistory.TYPE_TEXT);
msg.setAttribute("id", String.valueOf(id));
Element file = doc.createElement("content");
msg.appendChild(file);
file.setTextContent(message);
// transform everything to a string
Transformer t = TransformerFactory.newInstance().newTransformer();
StringWriter writer = new StringWriter();
StreamResult r = new StreamResult(writer);
t.transform(new DOMSource(doc), r);
message = writer.toString();
// send the message
chat.sendMessage(message);
Log.d("DEBUG", "Success: Sent message");
return true;
}catch (Exception e){
Log.e("ERROR", "Couldn't send message.");
Log.e("ERROR", e.toString());
return false;
}
}
Log.e("ERROR", "Sending failed: No connection.");
return false;
}
示例11: sendAcknowledgement
import org.jivesoftware.smack.chat.Chat; //导入依赖的package包/类
/**
* send an acknowledgement
* @param buddyId the buddyId to receive the acknowledgement
* @param othersId the id the buddy has sent the message with
* @param type the type of acknowledgement to send
* @return true if sending was successful
*/
public boolean sendAcknowledgement(String buddyId, long othersId, String type){
ChatManager chatManager = ChatManager.getInstanceFor(connection);
if (connection != null && connection.isConnected() && chatManager != null){
if (buddyId.indexOf('@') == -1)
buddyId += "@" + service;
Chat chat = chatManager.createChat(buddyId);
try{
// create the message structure
Document doc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().newDocument();
Element ack = doc.createElement("acknowledgement");
doc.appendChild(ack);
ack.setAttribute("id", String.valueOf(othersId));
ack.setAttribute("type", type);
// create the string representation of the message
Transformer t = TransformerFactory.newInstance().newTransformer();
StringWriter writer = new StringWriter();
StreamResult r = new StreamResult(writer);
t.transform(new DOMSource(doc), r);
String message = writer.toString();
// send the message
chat.sendMessage(message);
Log.d("DEBUG", "Success: Sent message");
return true;
}catch (Exception e){
Log.e("ERROR", "Couldn't send message.");
Log.e("ERROR", e.toString());
return false;
}
}
Log.e("ERROR", "Sending failed: No connection.");
return false;
}
示例12: processMessage
import org.jivesoftware.smack.chat.Chat; //导入依赖的package包/类
@Override
public void processMessage(Chat chat, Message message) {
if (message.getType().equals(Message.Type.chat) || message.getType().equals(Message.Type.normal)) {
if (message.getBody() != null) {
saveMessage(message.getFrom(), message.getBody(), true);
}
}
}
示例13: setCurrentState
import org.jivesoftware.smack.chat.Chat; //导入依赖的package包/类
/**
* Sets the current state of the provided chat. This method will send an empty bodied Message
* stanza(/packet) with the state attached as a {@link org.jivesoftware.smack.packet.ExtensionElement}, if
* and only if the new chat state is different than the last state.
*
* @param newState the new state of the chat
* @param chat the chat.
* @throws NotConnectedException
*/
public void setCurrentState(ChatState newState, Chat chat) throws NotConnectedException {
if(chat == null || newState == null) {
throw new IllegalArgumentException("Arguments cannot be null.");
}
if(!updateChatState(chat, newState)) {
return;
}
Message message = new Message();
ChatStateExtension extension = new ChatStateExtension(newState);
message.addExtension(extension);
chat.sendMessage(message);
}
示例14: updateChatState
import org.jivesoftware.smack.chat.Chat; //导入依赖的package包/类
private synchronized boolean updateChatState(Chat chat, ChatState newState) {
ChatState lastChatState = chatStates.get(chat);
if (lastChatState != newState) {
chatStates.put(chat, newState);
return true;
}
return false;
}
示例15: fireNewChatState
import org.jivesoftware.smack.chat.Chat; //导入依赖的package包/类
private void fireNewChatState(Chat chat, ChatState state) {
for (ChatMessageListener listener : chat.getListeners()) {
if (listener instanceof ChatStateListener) {
((ChatStateListener) listener).stateChanged(chat, state);
}
}
}