mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	This is a prep commit to break dependencies. The sub_store module is a thin layer on top of our map of stream_id -> sub.
		
			
				
	
	
		
			41 lines
		
	
	
		
			936 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			936 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
import * as blueslip from "./blueslip";
 | 
						|
 | 
						|
const subs_by_stream_id = new Map();
 | 
						|
 | 
						|
export function get(stream_id) {
 | 
						|
    return subs_by_stream_id.get(stream_id);
 | 
						|
}
 | 
						|
 | 
						|
export function validate_stream_ids(stream_ids) {
 | 
						|
    const good_ids = [];
 | 
						|
    const bad_ids = [];
 | 
						|
 | 
						|
    for (const stream_id of stream_ids) {
 | 
						|
        if (subs_by_stream_id.has(stream_id)) {
 | 
						|
            good_ids.push(stream_id);
 | 
						|
        } else {
 | 
						|
            bad_ids.push(stream_id);
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    if (bad_ids.length > 0) {
 | 
						|
        blueslip.warn(`We have untracked stream_ids: ${bad_ids}`);
 | 
						|
    }
 | 
						|
 | 
						|
    return good_ids;
 | 
						|
}
 | 
						|
 | 
						|
export function clear() {
 | 
						|
    subs_by_stream_id.clear();
 | 
						|
}
 | 
						|
 | 
						|
export function delete_sub(stream_id) {
 | 
						|
    subs_by_stream_id.delete(stream_id);
 | 
						|
}
 | 
						|
 | 
						|
export function add_hydrated_sub(stream_id, sub) {
 | 
						|
    // The only code that should call this directly is
 | 
						|
    // in stream_data.js. Grep there to find callers.
 | 
						|
    subs_by_stream_id.set(stream_id, sub);
 | 
						|
}
 |