openfire-好友管理实现好友添加及分组管理
(2015-04-17 08:16:16) 标签: 杂谈 |
openfire中实现好友添加及分组管理。
主要基于两张table实现:ofroster,ofrostergroups。
ofroster:用于记录好友关系(一对好友关系用两条记录来实现)
ofrostergroups:用于记录好友分组
特别说明:openfire中用户的主键是自然主键,也就是username。没有使用自增ID。
我们先来看一下官方(http://www.igniterealtime.org/builds/openfire/docs/latest/documentation/database-guide.html)对 两张表的描述:
ofRoster (buddy rosters or lists)Column Name Type Length Description
rosterIDNUMBERn/aID of roster (Primary Key)usernameVARCHAR32User NamejidTEXTn/aThe address of the roster entrysubNUMBERn/aThe subscription status of the entryaskNUMBERn/aThe ask status of the entryrecvNUMBERn/aFlag indicating the entry is a roster request that was receivednickVARCHAR255Th
ofRosterGroups (Groups of buddy entries in a roster)Column Name Type Length Description
rosterIDNUMBERn/aRoster ID (Primary Key)rankNUMBERn/aPosition of the entry (Primary Key)groupNameVARCHAR255The user defined name for this roster group
看不太明白?不要着急,我们慢慢分析。
假设有用户A,用户B。
当A申请加B为好友时(例如:A将B加入好亲人的分组中)。会在ofroster表中插入两条记录,
rosterID
1
2
同时往ofrostergroups表中插入一条记录
rosterID
1
这时B同意将A加为好友,并设置为Friends分组中,那么会修改ofroster表中刚插入的两条记录,如下所示:
rosterID
1
2
同时往ofrostergroups表中插入一条记录.
rosterID
2
此时,ofrostergroups表中的记录是:
rosterID
1
2
到此为止,双方的好友关系便建立起来。
疑问: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, with a brief description, also from the plugin’s readme file.
askstatus
-1--
1-- 估计是有没有回复的删除请求吧
recvstatus
-1-- 已经回复添加好友请求
1-- 接收到好友请求但是没有给好友回复
2-- 估计是没有回复删除请求吧
substatus
-1--
0--
1--
2--
3--