Correctly display names in groupchat pms

Also show "Me" when no local alias is set instead of JID
This commit is contained in:
Marvin W 2020-01-09 14:28:08 +01:00
parent 5e1f646cbc
commit 3fc9bdab05
No known key found for this signature in database
GPG key ID: 072E9235DB996F2A
6 changed files with 29 additions and 20 deletions

View file

@ -9,7 +9,11 @@ public class Conversation : Object {
public enum Type { public enum Type {
CHAT, CHAT,
GROUPCHAT, GROUPCHAT,
GROUPCHAT_PM GROUPCHAT_PM;
public bool is_muc_semantic() {
return this == GROUPCHAT || this == GROUPCHAT_PM;
}
} }
public int id { get; set; } public int id { get; set; }

View file

@ -22,7 +22,11 @@ public class Message : Object {
CHAT, CHAT,
GROUPCHAT, GROUPCHAT,
GROUPCHAT_PM, GROUPCHAT_PM,
UNKNOWN UNKNOWN;
public bool is_muc_semantic() {
return this == GROUPCHAT || this == GROUPCHAT_PM;
}
} }
public int id { get; set; default = -1; } public int id { get; set; default = -1; }
@ -74,7 +78,7 @@ public class Message : Object {
if (counterpart_resource != null) counterpart = counterpart.with_resource(counterpart_resource); if (counterpart_resource != null) counterpart = counterpart.with_resource(counterpart_resource);
string our_resource = row[db.message.our_resource]; string our_resource = row[db.message.our_resource];
if (type_ == Type.GROUPCHAT && our_resource != null) { if (type_.is_muc_semantic() && our_resource != null) {
ourpart = counterpart.with_resource(our_resource); ourpart = counterpart.with_resource(our_resource);
} else if (our_resource != null) { } else if (our_resource != null) {
ourpart = account.bare_jid.with_resource(our_resource); ourpart = account.bare_jid.with_resource(our_resource);

View file

@ -68,7 +68,7 @@ public class ContentItemStore : StreamInteractionModule, Object {
try { try {
string storage_dir = FileManager.get_storage_dir(); string storage_dir = FileManager.get_storage_dir();
FileTransfer file_transfer = new FileTransfer.from_row(db, row_option.inner, storage_dir); FileTransfer file_transfer = new FileTransfer.from_row(db, row_option.inner, storage_dir);
if (conversation.type_ in new Conversation.Type[]{Conversation.Type.GROUPCHAT, Conversation.Type.GROUPCHAT_PM}) { if (conversation.type_.is_muc_semantic()) {
try { try {
// resourcepart wasn't set before, so we pick nickname instead (which isn't accurate if nickname is changed) // resourcepart wasn't set before, so we pick nickname instead (which isn't accurate if nickname is changed)
file_transfer.ourpart = conversation.counterpart.with_resource(file_transfer.ourpart.resourcepart ?? conversation.nickname); file_transfer.ourpart = conversation.counterpart.with_resource(file_transfer.ourpart.resourcepart ?? conversation.nickname);

View file

@ -42,7 +42,7 @@ public class FileManager : StreamInteractionModule, Object {
FileTransfer file_transfer = new FileTransfer(); FileTransfer file_transfer = new FileTransfer();
file_transfer.account = conversation.account; file_transfer.account = conversation.account;
file_transfer.counterpart = conversation.counterpart; file_transfer.counterpart = conversation.counterpart;
if (conversation.type_ in new Conversation.Type[]{Conversation.Type.GROUPCHAT, Conversation.Type.GROUPCHAT_PM}) { if (conversation.type_.is_muc_semantic()) {
file_transfer.ourpart = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account) ?? conversation.account.bare_jid; file_transfer.ourpart = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account) ?? conversation.account.bare_jid;
} else { } else {
file_transfer.ourpart = conversation.account.full_jid; file_transfer.ourpart = conversation.account.full_jid;
@ -292,7 +292,7 @@ public class FileManager : StreamInteractionModule, Object {
file_transfer.account = conversation.account; file_transfer.account = conversation.account;
file_transfer.direction = from.bare_jid.equals(conversation.account.bare_jid) ? FileTransfer.DIRECTION_SENT : FileTransfer.DIRECTION_RECEIVED; file_transfer.direction = from.bare_jid.equals(conversation.account.bare_jid) ? FileTransfer.DIRECTION_SENT : FileTransfer.DIRECTION_RECEIVED;
file_transfer.counterpart = file_transfer.direction == FileTransfer.DIRECTION_RECEIVED ? from : conversation.counterpart; file_transfer.counterpart = file_transfer.direction == FileTransfer.DIRECTION_RECEIVED ? from : conversation.counterpart;
if (conversation.type_ in new Conversation.Type[]{Conversation.Type.GROUPCHAT, Conversation.Type.GROUPCHAT_PM}) { if (conversation.type_.is_muc_semantic()) {
file_transfer.ourpart = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account) ?? conversation.account.bare_jid; file_transfer.ourpart = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account) ?? conversation.account.bare_jid;
} else { } else {
file_transfer.ourpart = conversation.account.full_jid; file_transfer.ourpart = conversation.account.full_jid;

View file

@ -530,7 +530,7 @@ public class MessageProcessor : StreamInteractionModule, Object {
message.local_time = now; message.local_time = now;
message.direction = Entities.Message.DIRECTION_SENT; message.direction = Entities.Message.DIRECTION_SENT;
message.counterpart = conversation.counterpart; message.counterpart = conversation.counterpart;
if (conversation.type_ in new Conversation.Type[]{Conversation.Type.GROUPCHAT, Conversation.Type.GROUPCHAT_PM}) { if (conversation.type_.is_muc_semantic()) {
message.ourpart = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account) ?? conversation.account.bare_jid; message.ourpart = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account) ?? conversation.account.bare_jid;
message.real_jid = conversation.account.bare_jid; message.real_jid = conversation.account.bare_jid;
} else { } else {

View file

@ -146,10 +146,10 @@ public static string get_participant_display_name(StreamInteractor stream_intera
} }
private static string? get_real_display_name(StreamInteractor stream_interactor, Account account, Jid jid, bool me_is_me = false) { private static string? get_real_display_name(StreamInteractor stream_interactor, Account account, Jid jid, bool me_is_me = false) {
if (me_is_me && jid.equals_bare(account.bare_jid)) { if (jid.equals_bare(account.bare_jid)) {
return _("Me"); if (me_is_me || account.alias == null || account.alias.length == 0) {
} return _("Me");
if (jid.equals_bare(account.bare_jid) && account.alias != null && account.alias.length != 0) { }
return account.alias; return account.alias;
} }
Roster.Item roster_item = stream_interactor.get_module(RosterManager.IDENTITY).get_roster_item(account, jid); Roster.Item roster_item = stream_interactor.get_module(RosterManager.IDENTITY).get_roster_item(account, jid);
@ -181,16 +181,17 @@ private static string get_groupchat_display_name(StreamInteractor stream_interac
return jid.to_string(); return jid.to_string();
} }
private static string get_occupant_display_name(StreamInteractor stream_interactor, Account account, Jid jid, bool me_is_me = false) { private static string get_occupant_display_name(StreamInteractor stream_interactor, Account account, Jid jid, bool me_is_me = false, bool muc_real_name = false) {
/* TODO: MUC Real JID if (muc_real_name) {
MucManager muc_manager = stream_interactor.get_module(MucManager.IDENTITY); MucManager muc_manager = stream_interactor.get_module(MucManager.IDENTITY);
if (muc_manager.is_private_room(account, jid.bare_jid)) { if (muc_manager.is_private_room(account, jid.bare_jid)) {
Jid? real_jid = muc_manager.get_real_jid(jid, account); Jid? real_jid = muc_manager.get_real_jid(jid, account);
if (real_jid != null) { if (real_jid != null) {
string? display_name = get_real_display_name(stream_interactor, account, real_jid, me_is_me); string? display_name = get_real_display_name(stream_interactor, account, real_jid, me_is_me);
if (display_name != null) return display_name; if (display_name != null) return display_name;
}
} }
}*/ }
return jid.resourcepart ?? jid.to_string(); return jid.resourcepart ?? jid.to_string();
} }