Code cleanup

This commit is contained in:
fiaxh 2020-05-28 01:52:12 +02:00
parent d01af5b520
commit a9e6a9c3d5
2 changed files with 6 additions and 27 deletions

View file

@ -108,16 +108,6 @@ public class MessageStorage : StreamInteractionModule, Object {
return null; return null;
} }
public Conversation? get_conversation_for_stanza_id(Account account, string stanza_id) {
foreach (Conversation conversation in messages.keys) {
if (!conversation.account.equals(account)) continue;
foreach (Message message in messages[conversation]) {
if (message.stanza_id == stanza_id) return conversation;
}
}
return null;
}
private void init_conversation(Conversation conversation) { private void init_conversation(Conversation conversation) {
if (!messages.has_key(conversation)) { if (!messages.has_key(conversation)) {
messages[conversation] = new Gee.TreeSet<Message>((a, b) => { messages[conversation] = new Gee.TreeSet<Message>((a, b) => {

View file

@ -86,13 +86,14 @@ public class OccupantsTabCompletor {
} }
} }
private Gee.List<string> generate_completions_from_messages() { private Gee.List<string> generate_completions_from_messages(string? prefix = null) {
Gee.List<string> ret = new ArrayList<string>(); Gee.List<string> ret = new ArrayList<string>();
Gee.List<Message> messages = stream_interactor.get_module(MessageStorage.IDENTITY).get_messages(conversation, 10); Gee.List<ContentItem> content_items = stream_interactor.get_module(ContentItemStore.IDENTITY).get_n_latest(conversation, 10);
for (int i = messages.size - 1; i > 0; i--) { for (int i = content_items.size - 1; i > 0; i--) {
string resourcepart = messages[i].from.resourcepart; string resourcepart = content_items[i].jid.resourcepart;
Jid? own_nick = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account); Jid? own_nick = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account);
if (resourcepart != null && resourcepart != "" && (own_nick == null || resourcepart != own_nick.resourcepart) && !ret.contains(resourcepart)) { if (resourcepart != null && resourcepart != "" && (own_nick == null || resourcepart != own_nick.resourcepart) && !ret.contains(resourcepart)) {
if (prefix != null && !resourcepart.to_string().down().has_prefix(prefix.down())) continue;
ret.add(resourcepart); ret.add(resourcepart);
} }
} }
@ -100,20 +101,8 @@ public class OccupantsTabCompletor {
} }
private Gee.List<string> generate_completions_from_occupants(string prefix) { private Gee.List<string> generate_completions_from_occupants(string prefix) {
Gee.List<string> ret = new ArrayList<string>();
// First suggest nicks that have recently writen something // First suggest nicks that have recently writen something
Gee.List<Message> messages = stream_interactor.get_module(MessageStorage.IDENTITY).get_messages(conversation, 50); Gee.List<string> ret = generate_completions_from_messages(prefix);
for (int i = messages.size - 1; i > 0; i--) {
string resourcepart = messages[i].from.resourcepart;
Jid? own_nick = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account);
if (resourcepart != null && resourcepart != "" &&
resourcepart.to_string().down().has_prefix(prefix.down()) &&
(own_nick == null || resourcepart != own_nick.resourcepart) &&
!ret.contains(resourcepart)) {
ret.add(resourcepart.to_string());
}
}
// Then, suggest other nicks in alphabetical order // Then, suggest other nicks in alphabetical order
Gee.List<Jid>? occupants = stream_interactor.get_module(MucManager.IDENTITY).get_other_occupants(conversation.counterpart, conversation.account); Gee.List<Jid>? occupants = stream_interactor.get_module(MucManager.IDENTITY).get_other_occupants(conversation.counterpart, conversation.account);