aboutsummaryrefslogtreecommitdiff
path: root/libdino
diff options
context:
space:
mode:
Diffstat (limited to 'libdino')
-rw-r--r--libdino/src/entity/message.vala35
-rw-r--r--libdino/src/service/message_processor.vala7
-rw-r--r--libdino/src/service/muc_manager.vala9
3 files changed, 30 insertions, 21 deletions
diff --git a/libdino/src/entity/message.vala b/libdino/src/entity/message.vala
index 3092627e..e5871f49 100644
--- a/libdino/src/entity/message.vala
+++ b/libdino/src/entity/message.vala
@@ -29,13 +29,13 @@ public class Message : Object {
public Jid? counterpart { get; set; }
public Jid? ourpart { get; set; }
public Jid? from {
- get { return direction == DIRECTION_SENT ? account.bare_jid : counterpart; }
+ get { return direction == DIRECTION_SENT ? ourpart : counterpart; }
}
public Jid? to {
- get { return direction == DIRECTION_SENT ? counterpart : account.bare_jid; }
+ get { return direction == DIRECTION_SENT ? counterpart : ourpart; }
}
public bool direction { get; set; }
- public string? real_jid { get; set; }
+ public Jid? real_jid { get; set; }
public Type type_ { get; set; default = Type.UNKNOWN; }
public string? body { get; set; }
public string? stanza_id { get; set; }
@@ -56,19 +56,30 @@ public class Message : Object {
this.db = db;
id = row[db.message.id];
+ account = db.get_account_by_id(row[db.message.account_id]); // TODO dont have to generate acc new
stanza_id = row[db.message.stanza_id];
- string from = db.get_jid_by_id(row[db.message.counterpart_id]);
- string from_resource = row[db.message.counterpart_resource];
- counterpart = from_resource != null ? new Jid(from + "/" + from_resource) : new Jid(from);
- direction = row[db.message.direction];
type_ = (Message.Type) row[db.message.type_];
+
+ string counterpart_jid = db.get_jid_by_id(row[db.message.counterpart_id]);
+ string counterpart_resource = row[db.message.counterpart_resource];
+ counterpart = counterpart_resource != null ? new Jid.with_resource(counterpart_jid, counterpart_resource) : new Jid(counterpart_jid);
+
+ string our_resource = row[db.message.our_resource];
+ if (type_ == Type.GROUPCHAT && our_resource != null) {
+ ourpart = new Jid.with_resource(counterpart_jid, our_resource);
+ } else if (our_resource != null) {
+ ourpart = new Jid.with_resource(account.bare_jid.to_string(), our_resource);
+ } else {
+ ourpart = account.bare_jid;
+ }
+ direction = row[db.message.direction];
time = new DateTime.from_unix_local(row[db.message.time]);
local_time = new DateTime.from_unix_local(row[db.message.time]);
body = row[db.message.body];
- account = db.get_account_by_id(row[db.message.account_id]); // TODO dont have to generate acc new
marked = (Message.Marked) row[db.message.marked];
encryption = (Encryption) row[db.message.encryption];
- real_jid = db.real_jid.select({db.real_jid.real_jid}).with(db.real_jid.message_id, "=", id)[db.real_jid.real_jid];
+ string? real_jid_str = db.real_jid.select({db.real_jid.real_jid}).with(db.real_jid.message_id, "=", id)[db.real_jid.real_jid];
+ if (real_jid_str != null) real_jid = new Jid(real_jid_str);
notify.connect(on_update);
}
@@ -95,7 +106,7 @@ public class Message : Object {
if (real_jid != null) {
db.real_jid.insert()
.value(db.real_jid.message_id, id)
- .value(db.real_jid.real_jid, real_jid)
+ .value(db.real_jid.real_jid, real_jid.to_string())
.perform();
}
notify.connect(on_update);
@@ -168,10 +179,10 @@ public class Message : Object {
if (sp.get_name() == "real-jid") {
db.real_jid.insert().or("REPLACE")
.value(db.real_jid.message_id, id)
- .value(db.real_jid.real_jid, real_jid)
+ .value(db.real_jid.real_jid, real_jid.to_string())
.perform();
}
}
}
-} \ No newline at end of file
+}
diff --git a/libdino/src/service/message_processor.vala b/libdino/src/service/message_processor.vala
index cc99bcc3..2bf3d615 100644
--- a/libdino/src/service/message_processor.vala
+++ b/libdino/src/service/message_processor.vala
@@ -167,7 +167,12 @@ public class MessageProcessor : StreamInteractionModule, Object {
message.local_time = new DateTime.now_local();
message.direction = Entities.Message.DIRECTION_SENT;
message.counterpart = conversation.counterpart;
- message.ourpart = new Jid(conversation.account.bare_jid.to_string() + "/" + conversation.account.resourcepart);
+ if (conversation.type_ in new Conversation.Type[]{Conversation.Type.GROUPCHAT, Conversation.Type.GROUPCHAT_PM}) {
+ message.ourpart = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account);
+ message.real_jid = conversation.account.bare_jid;
+ } else {
+ message.ourpart = new Jid.with_resource(conversation.account.bare_jid.to_string(), conversation.account.resourcepart);
+ }
message.marked = Entities.Message.Marked.UNSENT;
message.encryption = conversation.encryption;
diff --git a/libdino/src/service/muc_manager.vala b/libdino/src/service/muc_manager.vala
index ea261300..51b3822e 100644
--- a/libdino/src/service/muc_manager.vala
+++ b/libdino/src/service/muc_manager.vala
@@ -191,13 +191,6 @@ public class MucManager : StreamInteractionModule, Object {
return ret;
}
- public Jid? get_message_real_jid(Entities.Message message) {
- if (message.real_jid != null) {
- return new Jid(message.real_jid);
- }
- return null;
- }
-
public Jid? get_own_jid(Jid muc_jid, Account account) {
Core.XmppStream? stream = stream_interactor.get_stream(account);
if (stream != null) {
@@ -250,7 +243,7 @@ public class MucManager : StreamInteractionModule, Object {
if (Xep.DelayedDelivery.MessageFlag.get_flag(message.stanza) == null) {
string? real_jid = stream.get_flag(Xep.Muc.Flag.IDENTITY).get_real_jid(message.counterpart.to_string());
if (real_jid != null && real_jid != message.counterpart.to_string()) {
- message.real_jid = real_jid;
+ message.real_jid = new Jid(real_jid).bare_jid;
}
}
string? muc_nick = stream.get_flag(Xep.Muc.Flag.IDENTITY).get_muc_nick(conversation.counterpart.bare_jid.to_string());