分享

openfire–好友管理实现好友添加及分组管理

 日积月累-随意 2012-06-30

openfire–好友管理实现好友添加及分组管理

2012-02-15

openfire中实现好友添加及分组管理。

主要基于两张table实现:ofroster,ofrostergroups。

ofroster:用于记录好友关系(一对好友关系用两条记录来实现)

ofrostergroups:用于记录好友分组

特别说明:openfire中用户的主键是自然主键,也就是username。没有使用自增ID。

我们先来看一下官方(http://www./builds/openfire/docs/latest/documentation/database-guide.html)对 两张表的描述:

 

 

ofRoster (buddy rosters or lists)Column Name Type Length Description

rosterID NUMBER n/a ID of roster (Primary Key)
username VARCHAR 32 User Name
jid TEXT n/a The address of the roster entry
sub NUMBER n/a The subscription status of the entry
ask NUMBER n/a The ask status of the entry
recv NUMBER n/a Flag indicating the entry is a roster request that was received
nick VARCHAR 255 The nickname assigned to this roster entry

 

ofRosterGroups (Groups of buddy entries in a roster)Column Name Type Length Description

rosterID NUMBER n/a Roster ID (Primary Key)
rank NUMBER n/a Position of the entry (Primary Key)
groupName VARCHAR 255 The user defined name for this roster group

 

 

 

看不太明白?不要着急,我们慢慢分析。

假设有用户A,用户B。

当A申请加B为好友时(例如:A将B加入好亲人的分组中)。会在ofroster表中插入两条记录,

rosterID username jid sub ask recv nick

1 A http://www.360doc.com/mailto:B@192.168.1.102 0 0 -1 B
2 B http://www.360doc.com/mailto:A@192.168.1.102 0 -1 1 null

同时往ofrostergroups表中插入一条记录

rosterID rank groupName

1 0 亲人

 

这时B同意将A加为好友,并设置为家人分组中,那么会修改ofroster表中刚插入的两条记录,如下所示:

rosterID username jid sub ask recv nick

1 A http://www.360doc.com/mailto:B@192.168.1.102 1 -1 1 B
2 B http://www.360doc.com/mailto:A@192.168.1.102 2 0 -1 null

同时往ofrostergroups表中插入一条记录.

rosterID rank groupName

2 0 家人

 

到此为止,双方的好友关系便建立起来。

疑问:1.若B不同意呢?则不做任何操作。下一次,若B加A为好友,将等同于执行同意的操作。

2.如何查询某个人所有好友,和分组?

在ofroster中根据username便可获得某个用户的所有好友信息。然后根据每条记录的rosterid去ofrostergroups表中查找分组的名称即可。

3.当用户添加一个空的好友分组时,ofrostergroups表是否插入一条记录?

不插,测试发现并没有实质的插入一条记录,但用户可以看到这个分组名称,怎么回事?推测可能是存放在session中。测试发现当用户创建一个空的好友分组,然后下线,再上线时,发现该好友分组已消失。充分说明当好友分组为空时,并没有插库。

 

Notice the different status types? Here is a list of all of the different status types, witha brief description, also from the plugin’s readme file.

askstatus

-1—  没有挂起的添加好友请求。

     The roster item has no pending subscription requests.

 0— 有挂起的添加好友请求。

     The roster item has been asked for permission to subscribe to its presence but no response has been received.

1— 估计是有没有回复的删除请求吧

      The roster owner has asked the roster item to be unsubscribed from its presence notifications but hasn’t yet received confi rmation.

recvstatus

-1— 已经回复添加好友请求

       There are no subscriptions that have been received but not presented to the user.

1— 接收到好友请求但是没有给好友回复

       The server has received a subscribe request, but has not forwarded it to the user.

2— 估计是没有回复删除请求吧

      The server has received an unsubscribe request, but has not forwarded it to the user.

substatus

-1—  应该删除这个好友

         Indicates that the roster item should be removed.

0—  没有建立好友关系

        No subscription is established.

1—  用户已经发出好友请求

        The roster owner has a subscription to the roster item’s presence.

2—  收到好友请求并且加对方好友

       The roster item has a subscription to the roster owner’s presence.

3—  好友已经相互添加

       The roster item and the owner have a mutual subscription.

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多