use of com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance in project BiglyBT by BiglySoftware.
the class ChatView method dataSourceChanged.
private void dataSourceChanged(Object data) {
synchronized (this) {
if (data instanceof ChatInstance) {
ChatInstance chat = (ChatInstance) data;
current_chat = chat;
}
}
}
use of com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance in project BiglyBT by BiglySoftware.
the class BuddyPluginView method checkBetaInit.
private void checkBetaInit() {
if (plugin.isBetaEnabled() && plugin.getBeta().isAvailable()) {
synchronized (this) {
if (beta_init_done) {
return;
}
beta_init_done = true;
}
MenuManager menu_manager = plugin.getPluginInterface().getUIManager().getMenuManager();
MenuItem chat_item = menu_manager.addMenuItem(MenuManager.MENU_DOWNLOAD_CONTEXT, "label.chat");
chat_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
chat_item.setHeaderCategory(MenuItem.HEADER_SOCIAL);
final MenuItem mi_chat = MenuBuildUtils.addChatMenu(menu_manager, chat_item, new MenuBuildUtils.ChatKeyResolver() {
@Override
public String getChatKey(Object object) {
return (BuddyPluginUtils.getChatKey((Download) object));
}
});
addBetaSubviews(true);
beta_status = ui_instance.createStatusEntry();
beta_status.setImageEnabled(true);
beta_status.setVisible(true);
updateIdleTT(false);
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
ImageLoader imageLoader = ImageLoader.getInstance();
bs_chat_gray = imageLoader.getImage("dchat_gray");
bs_chat_gray_text = imageLoader.getImage("dchat_gray_text");
bs_chat_green = imageLoader.getImage("dchat_green");
bs_chat_red = imageLoader.getImage("dchat_red");
setBetaStatus(bs_chat_gray);
mi_chat.setGraphic(ui_instance.createGraphic(bs_chat_gray));
}
});
beta_status.setListener(new UISWTStatusEntryListener() {
@Override
public void entryClicked(UISWTStatusEntry entry) {
Set<ChatInstance> current_instances = menu_latest_instances;
for (ChatInstance chat : current_instances) {
if (chat.getMessageOutstanding()) {
try {
openChat(chat.getClone());
} catch (Throwable e) {
Debug.out(e);
}
}
}
}
});
periodicEventMsgCheck = SimpleTimer.addPeriodicEvent("msgcheck", 30 * 1000, new TimerEventPerformer() {
@Override
public void perform(TimerEvent event) {
List<ChatInstance> chats = plugin.getBeta().getChats();
synchronized (pending_msg_map) {
for (ChatInstance chat : chats) {
if (chat.isInvisible()) {
continue;
}
if (!chat_uis.containsKey(chat)) {
if (chat.isFavourite() || chat.isAutoNotify() || chat.isInteresting()) {
if (!chat.isStatistics()) {
ChatMessage last_msg = chat.getLastMessageRequiringAttention();
if (last_msg != null) {
ChatMessage last_handled = (ChatMessage) chat.getUserData(CHAT_LM_KEY);
long last_msg_time = last_msg.getTimeStamp();
if (last_handled == null || last_msg_time > last_handled.getTimeStamp()) {
chat.setUserData(CHAT_LM_KEY, last_msg);
betaMessagePending(chat, null, last_msg);
}
}
}
}
}
}
updateIdleTT(false);
}
}
});
}
}
use of com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance in project BiglyBT by BiglySoftware.
the class BuddyPluginView method betaMessagePending.
protected void betaMessagePending(ChatInstance chat, Control comp_maybe_null, ChatMessage pending_message) {
synchronized (columns) {
for (TableColumn column : columns) {
column.invalidateCells();
}
}
synchronized (pending_msg_map) {
String key = chat.getNetAndKey();
Object[] entry = pending_msg_map.get(key);
if (pending_message != null) {
if (chat.isOldOutstandingMessage(pending_message)) {
return;
}
chat.setMessageOutstanding(pending_message);
if (entry == null) {
entry = new Object[] { 1, new HashSet<Control>(), chat };
pending_msg_map.put(key, entry);
} else {
entry[0] = ((Integer) entry[0]) + 1;
}
HashSet<Control> controls = (HashSet<Control>) entry[1];
if (controls.contains(comp_maybe_null)) {
return;
}
controls.add(comp_maybe_null);
if (pending_msg_event == null) {
pending_msg_event = SimpleTimer.addPeriodicEvent("BPPM", 2500, new TimerEventPerformer() {
private int tick_count = 0;
private Set<ChatInstance> prev_instances = new HashSet<>();
@Override
public void perform(TimerEvent event) {
tick_count++;
synchronized (pending_msg_map) {
Set<ChatInstance> current_instances = new HashSet<>();
Map<ChatInstance, Object> instance_map = new HashMap<>();
Iterator<Map.Entry<String, Object[]>> it = pending_msg_map.entrySet().iterator();
boolean has_new = false;
boolean has_mine = false;
while (it.hasNext()) {
Map.Entry<String, Object[]> map_entry = it.next();
Object[] entry = map_entry.getValue();
ChatInstance chat = (ChatInstance) entry[2];
if (chat.isDestroyed()) {
it.remove();
} else {
if (chat.hasUnseenMessageWithNick()) {
has_mine = true;
}
HashSet<Control> comps = ((HashSet<Control>) entry[1]);
Iterator<Control> control_it = comps.iterator();
while (control_it.hasNext()) {
Control c = control_it.next();
if (c != null && c.isDisposed()) {
it.remove();
}
}
if (comps.size() == 0) {
it.remove();
} else {
if (!chat.getDisableNewMsgIndications()) {
current_instances.add(chat);
if (!prev_instances.contains(chat)) {
has_new = true;
}
instance_map.put(chat, entry[0]);
}
}
}
}
if (pending_msg_map.size() == 0) {
pending_msg_event.cancel();
pending_msg_event = null;
}
if (current_instances.size() == 0) {
updateIdleTT(true);
} else {
String tt_text = "";
for (ChatInstance chat : sortChats(current_instances)) {
String short_name = chat.getShortName();
tt_text += (tt_text.length() == 0 ? "" : "\n") + instance_map.get(chat) + " - " + short_name;
}
buildMenu(current_instances);
if (has_new) {
playSound();
}
beta_status.setTooltipText(tt_text);
Image image = has_mine ? bs_chat_red : bs_chat_green;
if (plugin.getBeta().getFlashEnabled() && tick_count % 2 == 0) {
image = bs_chat_gray_text;
}
setBetaStatus(image);
}
prev_instances = current_instances;
}
}
});
}
} else {
chat.setUserData(CHAT_LM_KEY, chat.getLastMessageRequiringAttention());
chat.setMessageOutstanding(null);
if (entry != null) {
pending_msg_map.remove(key);
if (pending_msg_event == null) {
Debug.out("eh?");
}
}
}
}
}
use of com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance in project BiglyBT by BiglySoftware.
the class SubscriptionManagerImpl method assocOK.
private void assocOK(final SubscriptionImpl subs, final SubscriptionImpl.association assoc) {
if (BuddyPluginUtils.isBetaChatAvailable()) {
chat_write_dispatcher.dispatch(new AERunnable() {
@Override
public void runSupport() {
try {
Download download = core.getPluginManager().getDefaultPluginInterface().getDownloadManager().getDownload(assoc.getHash());
if (download != null) {
if (TorrentUtils.isReallyPrivate(PluginCoreUtils.unwrap(download.getTorrent()))) {
return;
}
final ChatInstance chat = BuddyPluginUtils.getChat(download);
if (chat != null) {
String net = chat.getNetwork();
if (net == AENetworkClassifier.AT_PUBLIC || subs.isAnonymous()) {
synchronized (chat_assoc_done) {
if (!chat_assoc_done.contains(chat)) {
chat_assoc_done.add(chat);
if (chat_assoc_done.size() > 50) {
ChatInstance c = chat_assoc_done.removeFirst();
c.setInteresting(false);
c.destroy();
}
}
}
String name = subs.getName();
if (subs.isSearchTemplate()) {
int pos = name.indexOf(':');
if (pos != -1) {
name = name.substring(pos + 1).trim();
}
}
final String f_msg = (subs.isSearchTemplate() ? "Search Template" : "Subscription") + " " + subs.getURI() + "[[" + UrlUtils.encode(name) + "]]";
waitForChat(chat, new AERunnable() {
@Override
public void runSupport() {
List<ChatMessage> messages = chat.getMessages();
for (ChatMessage message : messages) {
if (message.getMessage().equals(f_msg)) {
synchronized (chat_assoc_done) {
if (chat_assoc_done.remove(chat)) {
chat.destroy();
}
}
return;
}
}
Map<String, Object> flags = new HashMap<>();
flags.put(BuddyPluginBeta.FLAGS_MSG_ORIGIN_KEY, BuddyPluginBeta.FLAGS_MSG_ORIGIN_SUBS);
Map<String, Object> options = new HashMap<>();
chat.sendMessage(f_msg, flags, options);
}
});
} else {
chat.destroy();
}
}
}
} catch (Throwable e) {
}
}
});
}
}
use of com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance in project BiglyBT by BiglySoftware.
the class BuddyPluginView method updateIdleTT.
private void updateIdleTT(boolean known_to_be_idle) {
Iterator<Map.Entry<String, Object[]>> it = pending_msg_map.entrySet().iterator();
boolean has_pending = false;
if (!known_to_be_idle) {
while (it.hasNext()) {
Map.Entry<String, Object[]> map_entry = it.next();
Object[] entry = map_entry.getValue();
ChatInstance chat = (ChatInstance) entry[2];
if (!chat.getDisableNewMsgIndications()) {
has_pending = true;
break;
}
}
}
if (!has_pending) {
Set<ChatInstance> instances = new HashSet<>();
if (chat_uis.size() > 0) {
for (ChatInstance chat : chat_uis.keySet()) {
instances.add(chat);
}
}
List<ChatInstance> chats = plugin.getBeta().getChats();
for (ChatInstance chat : chats) {
if (!chat_uis.containsKey(chat)) {
if (chat.isFavourite() || chat.isPrivateChat()) {
instances.add(chat);
}
}
}
String text = MessageText.getString("label.no.messages");
for (ChatInstance chat : sortChats(instances)) {
text += "\n " + chat.getShortName();
}
if (beta_status != null) {
beta_status.setTooltipText(text);
}
buildMenu(instances);
setBetaStatus(bs_chat_gray);
}
}
Aggregations