mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	Extract exclude_muting_conditions() in messages.py
(imported from commit 97144097406377eb40383c7d1314c74dd713719c)
This commit is contained in:
		
				
					committed by
					
						
						Jessica McKellar
					
				
			
			
				
	
			
			
			
						parent
						
							f47a3c62e8
						
					
				
				
					commit
					9d21787cd7
				
			@@ -367,6 +367,26 @@ def ok_to_include_history(narrow, realm):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    return include_history
 | 
					    return include_history
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def exclude_muting_conditions(user_profile):
 | 
				
			||||||
 | 
					    muted_topics = ujson.loads(user_profile.muted_topics)
 | 
				
			||||||
 | 
					    if muted_topics:
 | 
				
			||||||
 | 
					        muted_streams = bulk_get_streams(user_profile.realm,
 | 
				
			||||||
 | 
					                                         [muted[0] for muted in muted_topics])
 | 
				
			||||||
 | 
					        muted_recipients = bulk_get_recipients(Recipient.STREAM,
 | 
				
			||||||
 | 
					                                               [stream.id for stream in muted_streams.itervalues()])
 | 
				
			||||||
 | 
					        recipient_map = dict((s.name.lower(), muted_recipients[s.id].id)
 | 
				
			||||||
 | 
					                             for s in muted_streams.itervalues())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        def mute_cond(muted):
 | 
				
			||||||
 | 
					            stream_cond = column("recipient_id") == recipient_map[muted[0].lower()]
 | 
				
			||||||
 | 
					            topic_cond = func.upper(column("subject")) == func.upper(muted[1])
 | 
				
			||||||
 | 
					            return and_(stream_cond, topic_cond)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        condition = not_(or_(*map(mute_cond, muted_topics)))
 | 
				
			||||||
 | 
					        return [condition]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@has_request_variables
 | 
					@has_request_variables
 | 
				
			||||||
def get_old_messages_backend(request, user_profile,
 | 
					def get_old_messages_backend(request, user_profile,
 | 
				
			||||||
                             anchor = REQ(converter=int),
 | 
					                             anchor = REQ(converter=int),
 | 
				
			||||||
@@ -432,18 +452,9 @@ def get_old_messages_backend(request, user_profile,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        # We exclude messages on muted topics when finding the first unread
 | 
					        # We exclude messages on muted topics when finding the first unread
 | 
				
			||||||
        # message in this narrow
 | 
					        # message in this narrow
 | 
				
			||||||
        muted_topics = ujson.loads(user_profile.muted_topics)
 | 
					        muting_conditions = exclude_muting_conditions(user_profile)
 | 
				
			||||||
        if muted_topics:
 | 
					        if muting_conditions:
 | 
				
			||||||
            muted_streams = bulk_get_streams(user_profile.realm,
 | 
					            condition = and_(condition, *muting_conditions)
 | 
				
			||||||
                                             [muted[0] for muted in muted_topics])
 | 
					 | 
				
			||||||
            muted_recipients = bulk_get_recipients(Recipient.STREAM,
 | 
					 | 
				
			||||||
                                                   [stream.id for stream in muted_streams.itervalues()])
 | 
					 | 
				
			||||||
            recipient_map = dict((s.name.lower(), muted_recipients[s.id].id)
 | 
					 | 
				
			||||||
                                 for s in muted_streams.itervalues())
 | 
					 | 
				
			||||||
            condition = and_(condition,
 | 
					 | 
				
			||||||
                             not_(or_(*[and_(column("recipient_id") == recipient_map[muted[0].lower()],
 | 
					 | 
				
			||||||
                                             func.upper(column("subject")) == func.upper(muted[1]))
 | 
					 | 
				
			||||||
                                        for muted in muted_topics])))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        first_unread_query = query.where(condition)
 | 
					        first_unread_query = query.where(condition)
 | 
				
			||||||
        first_unread_query = first_unread_query.order_by(inner_msg_id_col.asc()).limit(1)
 | 
					        first_unread_query = first_unread_query.order_by(inner_msg_id_col.asc()).limit(1)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user