Mercurial Hosting > nabble
comparison src/nabble/view/web/user/OnlineStatus.java @ 19:18cf4872fd7f
remove anonymous posting
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 29 May 2020 22:58:25 -0600 |
parents | 7ecd1a4ef557 |
children |
comparison
equal
deleted
inserted
replaced
18:862b1ef23e75 | 19:18cf4872fd7f |
---|---|
1 package nabble.view.web.user; | 1 package nabble.view.web.user; |
2 | 2 |
3 import fschmidt.util.servlet.ServletUtils; | 3 import fschmidt.util.servlet.ServletUtils; |
4 import nabble.model.Executors; | 4 import nabble.model.Executors; |
5 import nabble.model.ModelHome; | 5 import nabble.model.ModelHome; |
6 import nabble.model.Person; | |
7 import nabble.model.Site; | 6 import nabble.model.Site; |
8 import nabble.model.User; | 7 import nabble.model.User; |
9 import nabble.view.lib.Jtp; | 8 import nabble.view.lib.Jtp; |
10 import org.slf4j.Logger; | 9 import org.slf4j.Logger; |
11 import org.slf4j.LoggerFactory; | 10 import org.slf4j.LoggerFactory; |
28 private static final String INVISIBLE = "invisible:"; | 27 private static final String INVISIBLE = "invisible:"; |
29 | 28 |
30 /** Maps a site ID to a map (Person-Source-ID > last time) */ | 29 /** Maps a site ID to a map (Person-Source-ID > last time) */ |
31 private static final Map<Long, Map<String, Long>> sitesMap = new HashMap<Long, Map<String, Long>>(); | 30 private static final Map<Long, Map<String, Long>> sitesMap = new HashMap<Long, Map<String, Long>>(); |
32 | 31 |
33 public static void setOnline(HttpServletRequest request, Person visitor, Site site) { | 32 public static void setOnline(HttpServletRequest request, User user, Site site) { |
34 setOnline(request,visitor.getSearchId(),site); | 33 if( user==null ) |
35 } | 34 return; |
36 | 35 String sourceId = user.getSearchId(); |
37 private static void setOnline(HttpServletRequest request, String sourceId, Site site) { | |
38 synchronized(sitesMap) { | 36 synchronized(sitesMap) { |
39 Map<String, Long> map = sitesMap.get(site.getId()); | 37 Map<String, Long> map = sitesMap.get(site.getId()); |
40 if (map == null) { | 38 if (map == null) { |
41 map = new HashMap<String, Long>(); | 39 map = new HashMap<String, Long>(); |
42 sitesMap.put(site.getId(), map); | 40 sitesMap.put(site.getId(), map); |
45 boolean isVisible = ServletUtils.getCookieValue(request, "visible") == null || !Jtp.isInteger(sourceId); | 43 boolean isVisible = ServletUtils.getCookieValue(request, "visible") == null || !Jtp.isInteger(sourceId); |
46 map.put(isVisible? sourceId : INVISIBLE+sourceId, System.currentTimeMillis()); | 44 map.put(isVisible? sourceId : INVISIBLE+sourceId, System.currentTimeMillis()); |
47 } | 45 } |
48 } | 46 } |
49 | 47 |
50 public static boolean isOnline(Person visitor, Site site) { | 48 public static boolean isOnline(User visitor, Site site) { |
51 return isOnline(visitor.getSearchId(),site); | 49 return isOnline(visitor.getSearchId(),site); |
52 } | 50 } |
53 | 51 |
54 public static boolean isOnline(String sourceId, Site site) { | 52 public static boolean isOnline(String sourceId, Site site) { |
55 synchronized(sitesMap) { | 53 synchronized(sitesMap) { |