|
99 | 99 | end |
100 | 100 |
|
101 | 101 | context "unread counts" do |
102 | | - it "should increment when creating a conversation" do |
| 102 | + it "should increment for recipients when sending the first message in a conversation" do |
103 | 103 | sender = user |
104 | 104 | recipient = user |
105 | 105 | root_convo = Conversation.initiate([sender.id, recipient.id], false) |
| 106 | + ConversationParticipant.unread.size.should eql 0 # only once the first message is added |
106 | 107 | root_convo.add_message(sender, 'test') |
107 | 108 | sender.reload.unread_conversations_count.should eql 0 |
108 | 109 | sender.conversations.unread.size.should eql 0 |
|
117 | 118 | unsubscribed_guy = user |
118 | 119 | root_convo = Conversation.initiate([sender.id, unread_guy.id, subscribed_guy.id, unsubscribed_guy.id], false) |
119 | 120 | root_convo.add_message(sender, 'test') |
120 | | - |
| 121 | + |
121 | 122 | unread_guy.reload.unread_conversations_count.should eql 1 |
122 | 123 | unread_guy.conversations.unread.size.should eql 1 |
123 | 124 | subscribed_guy.conversations.first.mark_as_read |
|
142 | 143 | unread_guy = user |
143 | 144 | root_convo = Conversation.initiate([sender.id, unread_guy.id], false) |
144 | 145 | root_convo.add_message(sender, 'test') |
145 | | - |
| 146 | + |
146 | 147 | unread_guy.reload.unread_conversations_count.should eql 1 |
147 | 148 | unread_guy.conversations.unread.size.should eql 1 |
148 | 149 | unread_guy.conversations.first.remove_messages(:all) |
|
155 | 156 | unread_guy = user |
156 | 157 | root_convo = Conversation.initiate([sender.id, unread_guy.id], false) |
157 | 158 | root_convo.add_message(sender, 'test') |
158 | | - |
| 159 | + |
159 | 160 | unread_guy.reload.unread_conversations_count.should eql 1 |
160 | 161 | unread_guy.conversations.unread.size.should eql 1 |
161 | 162 | unread_guy.conversations.first.mark_as_read |
|
169 | 170 | root_convo = Conversation.initiate([sender.id, unread_guy.id], false) |
170 | 171 | root_convo.add_message(sender, 'test') |
171 | 172 | unread_guy.conversations.first.mark_as_read |
172 | | - |
| 173 | + |
173 | 174 | unread_guy.reload.unread_conversations_count.should eql 0 |
174 | 175 | unread_guy.conversations.unread.size.should eql 0 |
175 | 176 | unread_guy.conversations.first.mark_as_unread |
|
178 | 179 | end |
179 | 180 | end |
180 | 181 |
|
| 182 | + context "subscription" do |
| 183 | + it "should mark-as-read when unsubscribing iff it was unread" do |
| 184 | + sender = user |
| 185 | + subscription_guy = user |
| 186 | + archive_guy = user |
| 187 | + root_convo = Conversation.initiate([sender.id, archive_guy.id, subscription_guy.id], false) |
| 188 | + root_convo.add_message(sender, 'test') |
| 189 | + |
| 190 | + subscription_guy.reload.unread_conversations_count.should eql 1 |
| 191 | + subscription_guy.conversations.unread.size.should eql 1 |
| 192 | + |
| 193 | + subscription_guy.conversations.first.update_attributes(:subscribed => false) |
| 194 | + subscription_guy.reload.unread_conversations_count.should eql 0 |
| 195 | + subscription_guy.conversations.unread.size.should eql 0 |
| 196 | + |
| 197 | + archive_guy.conversations.first.archive! |
| 198 | + archive_guy.conversations.first.update_attributes(:subscribed => false) |
| 199 | + archive_guy.conversations.archived.size.should eql 1 |
| 200 | + end |
| 201 | + |
| 202 | + it "should mark-as-unread when re-subscribing iff there are newer messages" do |
| 203 | + sender = user |
| 204 | + flip_flopper_guy = user |
| 205 | + subscription_guy = user |
| 206 | + archive_guy = user |
| 207 | + root_convo = Conversation.initiate([sender.id, flip_flopper_guy.id, archive_guy.id, subscription_guy.id], false) |
| 208 | + root_convo.add_message(sender, 'test') |
| 209 | + |
| 210 | + flip_flopper_guy.conversations.first.update_attributes(:subscribed => false) |
| 211 | + flip_flopper_guy.reload.unread_conversations_count.should eql 0 |
| 212 | + flip_flopper_guy.conversations.unread.size.should eql 0 |
| 213 | + # no new messages in the interim, he should stay "marked-as-read" |
| 214 | + flip_flopper_guy.conversations.first.update_attributes(:subscribed => true) |
| 215 | + flip_flopper_guy.reload.unread_conversations_count.should eql 0 |
| 216 | + flip_flopper_guy.conversations.unread.size.should eql 0 |
| 217 | + |
| 218 | + subscription_guy.conversations.first.update_attributes(:subscribed => false) |
| 219 | + archive_guy.conversations.first.archive! |
| 220 | + archive_guy.conversations.first.update_attributes(:subscribed => false) |
| 221 | + |
| 222 | + message = root_convo.add_message(sender, 'you wish you were subscribed!') |
| 223 | + message.update_attribute(:created_at, Time.now.utc + 1.minute) |
| 224 | + last_message_at = message.reload.created_at |
| 225 | + |
| 226 | + subscription_guy.conversations.first.update_attributes(:subscribed => true) |
| 227 | + archive_guy.conversations.first.update_attributes(:subscribed => true) |
| 228 | + |
| 229 | + subscription_guy.reload.unread_conversations_count.should eql 1 |
| 230 | + subscription_guy.conversations.unread.size.should eql 1 |
| 231 | + subscription_guy.conversations.first.last_message_at.should eql last_message_at |
| 232 | + |
| 233 | + archive_guy.reload.unread_conversations_count.should eql 1 |
| 234 | + archive_guy.conversations.unread.size.should eql 1 |
| 235 | + subscription_guy.conversations.first.last_message_at.should eql last_message_at |
| 236 | + end |
| 237 | + |
| 238 | + it "should not toggle read/unread until the subscription change is saved" do |
| 239 | + sender = user |
| 240 | + subscription_guy = user |
| 241 | + root_convo = Conversation.initiate([sender.id, user.id, subscription_guy.id], false) |
| 242 | + root_convo.add_message(sender, 'test') |
| 243 | + |
| 244 | + subscription_guy.reload.unread_conversations_count.should eql 1 |
| 245 | + subscription_guy.conversations.unread.size.should eql 1 |
| 246 | + |
| 247 | + subscription_guy.conversations.first.subscribed = false |
| 248 | + subscription_guy.reload.unread_conversations_count.should eql 1 |
| 249 | + subscription_guy.conversations.unread.size.should eql 1 |
| 250 | + |
| 251 | + subscription_guy.conversations.first.subscribed = true |
| 252 | + subscription_guy.reload.unread_conversations_count.should eql 1 |
| 253 | + subscription_guy.conversations.unread.size.should eql 1 |
| 254 | + end |
| 255 | + end |
| 256 | + |
181 | 257 | context "adding messages" do |
182 | 258 | it "should deliver the message to all participants" do |
183 | 259 | sender = user |
|
195 | 271 | end |
196 | 272 | end |
197 | 273 |
|
198 | | - it "should not auto mark it as read for the sender" do |
| 274 | + it "should never change the workflow_state for the sender" do |
199 | 275 | sender = user |
200 | | - recipients = 5.times.map{ user } |
201 | | - Conversation.initiate([sender.id] + recipients.map(&:id), false).add_message(sender, 'test') |
| 276 | + Conversation.initiate([sender.id, user.id], true).add_message(sender, 'test') |
202 | 277 | convo = sender.conversations.first |
203 | 278 | convo.mark_as_unread! |
204 | 279 | convo.add_message('another test') |
205 | 280 | convo.reload.unread?.should be_true |
| 281 | + |
| 282 | + convo.archive! |
| 283 | + convo.add_message('one more test') |
| 284 | + convo.reload.archived?.should be_true |
| 285 | + |
| 286 | + convo.unarchive! |
| 287 | + convo.mark_as_unread! |
| 288 | + convo.add_message('and another test', :update_for_sender => true) # overrides subscribed-ness and updates timestamps |
| 289 | + convo.reload.unread?.should be_true |
| 290 | + |
| 291 | + convo.archive! |
| 292 | + convo.add_message('last one', :update_for_sender => true) |
| 293 | + convo.reload.archived?.should be_true |
| 294 | + |
| 295 | + convo.remove_messages(:all) |
| 296 | + convo.add_message('for reals', :update_for_sender => true) |
| 297 | + convo.reload.archived?.should be_true |
206 | 298 | end |
207 | 299 |
|
208 | 300 | it "should deliver the message to unsubscribed participants but not alert them" do |
|
217 | 309 | rconvo.unread?.should be_false |
218 | 310 |
|
219 | 311 | convo = sender.conversations.first |
220 | | - convo.add_message('another test') |
| 312 | + message = convo.add_message('another test') |
| 313 | + message.update_attribute(:created_at, Time.now.utc + 1.minute) |
221 | 314 |
|
222 | 315 | rconvo.reload.unread?.should be_false |
223 | 316 | rconvo.update_attributes(:subscribed => true) |
|
0 commit comments