summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2023-05-06 18:14:23 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2023-05-06 18:54:24 +0200
commit0c790e6850f0575f4d5ba8182c580182869ad57d (patch)
tree6db32b28d0c473f4f81d9b2a42b49efe09038f33
parent25a1ba71e3cf4250489291f688423963aa603498 (diff)
Message: get self identity from server
-rw-r--r--include/erebos/message.h3
-rw-r--r--src/main.cpp1
-rw-r--r--src/message.cpp11
3 files changed, 8 insertions, 7 deletions
diff --git a/include/erebos/message.h b/include/erebos/message.h
index 436c0ed..497b536 100644
--- a/include/erebos/message.h
+++ b/include/erebos/message.h
@@ -94,10 +94,11 @@ public:
DirectMessageThread thread(const Identity &);
- DirectMessage send(const Identity &, const Peer &, const std::string &);
+ DirectMessage send(const Peer &, const std::string &);
private:
const Config config;
+ const Server & server;
};
}
diff --git a/src/main.cpp b/src/main.cpp
index 0052c8e..d0015c2 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -518,7 +518,6 @@ void contactSetName(const vector<string> & args)
void dmSendPeer(const vector<string> & args)
{
server->svc<DirectMessageService>().send(
- server->identity().finalOwner(),
getPeer(args.at(0)).peer,
args.at(1));
}
diff --git a/src/message.cpp b/src/message.cpp
index fd8e847..dd4f9d5 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -208,8 +208,9 @@ DirectMessageService::Config & DirectMessageService::Config::onUpdate(ThreadWatc
return *this;
}
-DirectMessageService::DirectMessageService(Config && c, const Server &):
- config(move(c))
+DirectMessageService::DirectMessageService(Config && c, const Server & s):
+ config(move(c)),
+ server(s)
{}
DirectMessageService::~DirectMessageService() = default;
@@ -245,7 +246,7 @@ DirectMessageThread DirectMessageService::thread(const Identity & peer)
return DirectMessageThread::Priv::getThreadLocked(peer.finalOwner());
}
-DirectMessage DirectMessageService::send(const Identity & from, const Peer & peer, const string & text)
+DirectMessage DirectMessageService::send(const Peer & peer, const string & text)
{
auto pid = peer.identity();
if (!pid)
@@ -254,9 +255,9 @@ DirectMessage DirectMessageService::send(const Identity & from, const Peer & pee
scoped_lock lock(threadLock);
- auto msg = from.ref()->storage().store(DirectMessageData {
+ auto msg = server.localHead().ref().storage().store(DirectMessageData {
.prev = DirectMessageThread::Priv::getThreadLocked(powner).p->head,
- .from = from.finalOwner(),
+ .from = server.identity().finalOwner(),
.time = ZonedTime::now(),
.text = text,
});