use of com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatMessage 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.ChatMessage in project BiglyBT by BiglySoftware.
the class SubscriptionManagerImpl method searchTemplateOK.
private void searchTemplateOK(final SubscriptionImpl subs, final Download download) {
if (BuddyPluginUtils.isBetaChatAvailable()) {
chat_write_dispatcher.dispatch(new AERunnable() {
@Override
public void runSupport() {
DHTPluginInterface dht = selectDHTPlugin(download);
if (dht == null) {
return;
}
String target_net = dht.getNetwork();
if (target_net != AENetworkClassifier.AT_PUBLIC) {
if (!BuddyPluginUtils.isBetaChatAnonAvailable()) {
return;
}
target_net = AENetworkClassifier.AT_I2P;
}
String name = subs.getName();
int pos = name.indexOf(':');
if (pos != -1) {
name = name.substring(pos + 1).trim();
}
if (chat_st_done.contains(name)) {
return;
}
chat_st_done.add(name);
final BuddyPluginBeta.ChatInstance chat = BuddyPluginUtils.getChat(target_net, "Search Templates");
if (chat != null) {
chat.setSharedNickname(false);
chat.setSaveMessages(false);
final String f_msg = subs.getURI() + "[[" + UrlUtils.encode(name) + "]]";
final Runnable do_write = new Runnable() {
@Override
public void run() {
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);
}
};
waitForChat(chat, new AERunnable() {
@Override
public void runSupport() {
List<ChatMessage> messages = chat.getMessages();
for (ChatMessage message : messages) {
if (message.getMessage().equals(f_msg)) {
return;
}
}
do_write.run();
}
});
}
}
});
}
}
use of com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatMessage 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) {
}
}
});
}
}
Aggregations