好知网的小纸条功能,形式上参照了facebook的Message,以会话的方式组织。我把数据库的表结构发上来,你看看。表名中"ref"是引用的意思。
CREATE TABLE IF NOT EXISTS `message` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`threadId` int(10) unsigned NOT NULL,
`authorId` int(10) unsigned NOT NULL,
`message` text NOT NULL,
`createdTime` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `message_ref` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`userId` int(10) unsigned NOT NULL,
`threadId` int(10) unsigned NOT NULL,
`messageId` int(10) unsigned NOT NULL,
`createdTime` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `message_thread` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`members` text NOT NULL,
`hash` varchar(64) NOT NULL,
`multiple` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '是否为多人会话(2人以上)',
`latestReplyUserId` int(10) unsigned NOT NULL,
`latestReplyTime` int(10) unsigned NOT NULL,
`latestReplySummary` text NOT NULL,
`createdTime` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `pairId` (`hash`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `message_thread_member` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`threadId` int(10) unsigned NOT NULL,
`memberId` int(10) unsigned NOT NULL,
`status` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '0:已离开会话, 1:在会话中',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `message_thread_ref` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`userId` int(10) unsigned NOT NULL,
`threadId` int(10) unsigned NOT NULL,
`unread` int(10) unsigned NOT NULL DEFAULT '0',
`updatedTime` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;