Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 7
- Log:
Initial import of RForum 0.2 sources from a downloaded Tarball.
RForum is a Ruby On Rails based forum and mail gateway service.
- Author:
- adh
- Date:
- Sat Jul 22 18:43:13 +0100 2006
- Size:
- 2011 Bytes
1 | # Topic is a collection of posts |
2 | class Topic < ActiveRecord::Base |
3 | has_many :posts, :exclusively_dependent => true |
4 | belongs_to :forum |
5 | has_many :topic_subscriptions, :exclusively_dependent => true |
6 | has_many :topic_reads, :exclusively_dependent => true |
7 | has_and_belongs_to_many :tags, :join_table => 'topics_tags' |
8 | |
9 | include ErrorRaising |
10 | |
11 | # CALLBACKS |
12 | |
13 | def before_create |
14 | self.deleted = 0 |
15 | end |
16 | |
17 | # NORMAL METHODS |
18 | |
19 | # Add a reply to the root post in this topic. |
20 | # TODO: transaction? |
21 | def add_reply(post) |
22 | root_post.add_reply(post) |
23 | end |
24 | |
25 | def hidden? |
26 | (self.deleted == 1) |
27 | end |
28 | |
29 | # Hide topic with all posts |
30 | def hide |
31 | self.update_attribute('deleted', 1) |
32 | self.root_post.hide(:recursive) |
33 | end |
34 | |
35 | # Unhide topic and root post; if recursive, unhide all posts |
36 | def unhide(recursive=false) |
37 | self.update_attribute('deleted', 0) |
38 | self.root_post.unhide(recursive) |
39 | end |
40 | |
41 | # Get the data needed for the topic view. |
42 | def posts_with_user_data(include_hidden = false) |
43 | self.posts.find( |
44 | :all, :include => [:user, :topic], |
45 | :conditions => (include_hidden ? nil : "posts.deleted = 0"), |
46 | :order => 'posts.created_at ASC, posts.id ASC' |
47 | ) |
48 | end |
49 | |
50 | # Get the root post of the topic. |
51 | def root_post |
52 | res = posts.find_all("parent_id IS NULL") |
53 | raise "Data integrity: topic #{} has #{res.size} root posts" if res.size > 1 |
54 | raise "Data integrity: topic #{} has no root posts" if res.empty? |
55 | res[0] |
56 | end |
57 | |
58 | def subscribed_by?(user) |
59 | return false if user.guest? |
60 | TopicSubscription.count("user_id = #{user.id} and topic_id = #{self.id}") > 0 |
61 | end |
62 | |
63 | def update_last_post_data(last_post=nil) |
64 | last_post ||= posts.find_first 'deleted=0', 'created_at DESC,id DESC' |
65 | if last_post |
66 | self.last_post_created_at = last_post.created_at |
67 | self.last_post_user_id = last_post.user_id |
68 | self.last_post_author = last_post.get_display_name |
69 | end |
70 | end |
71 | |
72 | def update_post_counter |
73 | self.post_counter = self.posts.count('deleted = 0') |
74 | end |
75 | end |