org.jivesoftware.smackx.muc.DiscussionHistory Java Examples

The following examples show how to use org.jivesoftware.smackx.muc.DiscussionHistory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmppConnection.java    From weixin with Apache License 2.0 6 votes vote down vote up
/**
 * 加入会议室
 * 
 * @param user 昵称
 * @param password 会议室密码
 * @param roomsName 会议室名
 */
public MultiUserChat joinMultiUserChat(String user, String roomsName, String password) {
	if (getConnection() == null)
		return null;
	try {
		// 使用XMPPConnection创建一个MultiUserChat窗口
		MultiUserChat muc = new MultiUserChat(getConnection(), roomsName + "@conference." + getConnection().getServiceName());
		// 聊天室服务将会决定要接受的历史记录数量
		DiscussionHistory history = new DiscussionHistory();
		history.setMaxChars(0);
		// history.setSince(new Date());
		// 用户加入聊天室
		muc.join(user, password, history, SmackConfiguration.getPacketReplyTimeout());
		Log.i("MultiUserChat", "会议室【" + roomsName + "】加入成功........");
		return muc;
	} catch (XMPPException e) {
		e.printStackTrace();
		Log.i("MultiUserChat", "会议室【" + roomsName + "】加入失败........");
		return null;
	}
}
 
Example #2
Source File: XmppManager.java    From weixin with Apache License 2.0 6 votes vote down vote up
/**
 * 加入会议室
 * 
 * @param user 昵称
 * @param password 会议室密码
 * @param roomsName 会议室名
 */
public MultiUserChat joinMultiUserChat(String user, String password, String roomsName) {
	try {
		// 使用XMPPConnection创建一个MultiUserChat窗口  
		MultiUserChat muc = new MultiUserChat(getConnection(), roomsName + "@conference." + getConnection().getServiceName());
		// 聊天室服务将会决定要接受的历史记录数量  
		DiscussionHistory history = new DiscussionHistory();
		history.setMaxStanzas(0);
		//history.setSince(new Date());  
		// 用户加入聊天室  
		muc.join(user, password, history, SmackConfiguration.getPacketReplyTimeout());
		L.i(LOGTAG, "会议室加入成功........");
		return muc;
	} catch (XMPPException e) {
		e.printStackTrace();
		L.i(LOGTAG, "会议室加入失败........");
		return null;
	}
}
 
Example #3
Source File: XmppConnection.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
public void reconnectAll ()
{
    MultiUserChatManager mucMgr = MultiUserChatManager.getInstanceFor(mConnection);
    mucMgr.setAutoJoinOnReconnect(true);

    Enumeration<MultiUserChat> eMuc = mMUCs.elements();
    while (eMuc.hasMoreElements())
    {
        MultiUserChat muc = eMuc.nextElement();

        MultiUserChat reMuc = mucMgr.getMultiUserChat(muc.getRoom());

        try {
            DiscussionHistory history = new DiscussionHistory();
            history.setMaxStanzas(Integer.MAX_VALUE);
            reMuc.join(Resourcepart.from(mUser.getName()), null, history, SmackConfiguration.getDefaultPacketReplyTimeout());

            mMUCs.put(muc.getRoom().toString(),reMuc);
            ChatGroup group = mGroups.get(muc.getRoom().toString());

            addMucListeners(reMuc, group);
            loadMembers(muc, group);

            queryArchive(muc.getRoom());

        } catch (Exception e) {
            Log.w(TAG,"unable to join MUC: " + e.getMessage());
        }
    }
}
 
Example #4
Source File: XmppConnection.java    From Zom-Android-XMPP with GNU General Public License v3.0 4 votes vote down vote up
@Override
        public void joinChatGroupAsync(Address address, String reason) {

            String chatRoomJid = address.getBareAddress();
            String[] parts = chatRoomJid.split("@");
            String room = parts[0];

            try {

                if (mConnection == null || (!mConnection.isAuthenticated()))
                    return;

//                mBookmarkManager.addBookmarkedConference(address.getUser(),JidCreate.entityBareFrom(chatRoomJid),true,null,null);

                // Create a MultiUserChat using a Connection for a room
                MultiUserChatManager mucMgr = MultiUserChatManager.getInstanceFor(mConnection);
                mucMgr.setAutoJoinOnReconnect(true);
                EntityBareJid crJid = JidCreate.entityBareFrom(chatRoomJid);
                MultiUserChat muc = mucMgr.getMultiUserChat( crJid);

                DiscussionHistory history = new DiscussionHistory();
                history.setMaxStanzas(Integer.MAX_VALUE);
                muc.join(Resourcepart.from(mUser.getName()), null, history, SmackConfiguration.getDefaultPacketReplyTimeout());
                String subject = muc.getSubject();

                if (TextUtils.isEmpty(subject))
                    subject = room;

                ChatGroup chatGroup = mGroups.get(chatRoomJid);

                if (chatGroup == null) {
                    chatGroup = new ChatGroup(address, subject, this);
                    mGroups.put(chatRoomJid, chatGroup);
                }

                mMUCs.put(chatRoomJid, muc);

                addMucListeners(muc, chatGroup);
                loadMembers(muc, chatGroup);

                queryArchive(crJid);

            } catch (Exception e) {
                debug(TAG,"error joining MUC",e);
            }

        }
 
Example #5
Source File: YiIMUtils.java    From yiim_v2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 加入会议室
 * 
 * @param user
 *            昵称
 * @param password
 *            会议室密码
 * @param roomsName
 *            会议室名
 */
public static MultiUserChat joinMultiUserChat(Context context, String user,
		String roomJid, String password) throws Exception {
	XMPPConnection connection = XmppConnectionUtils.getInstance()
			.getRawConnection();
	if (connection == null || !connection.isConnected()
			|| !connection.isAuthenticated())
		throw new Exception("connection not ready");

	Cursor cursor = null;
	try {
		// 使用XMPPConnection创建一个MultiUserChat窗口
		MultiUserChat muc = new MultiUserChat(connection, roomJid);
		// 聊天室服务将会决定要接受的历史记录数量
		DiscussionHistory history = new DiscussionHistory();

		cursor = context.getContentResolver().query(
				MultiChatRoomColumns.CONTENT_URI,
				new String[] { MultiChatRoomColumns.LAST_MSG_TIME },
				MultiChatRoomColumns.ROOM_JID + "='" + roomJid + "' and "
						+ MultiChatRoomColumns.OWNER + "='"
						+ UserInfo.getUserInfo(context).getUser() + "'",
				null, null);
		if (cursor != null && cursor.getCount() == 1) {
			cursor.moveToFirst();
			history.setSince(new Date(cursor.getLong(0)));
		} else {
			history.setMaxStanzas(15);
		}
		// 用户加入聊天室
		muc.join(StringUtils.escapeUserHost(user), password, history,
				SmackConfiguration.getPacketReplyTimeout());
		return muc;
	} catch (Exception e) {
		throw e;
	} finally {
		if (cursor != null) {
			cursor.close();
			cursor = null;
		}
	}
}