fix(transformers): Add signal mention support
This commit is contained in:
parent
9e247aa045
commit
9123e6fbe5
1 changed files with 17 additions and 4 deletions
|
@ -10,6 +10,7 @@ struct SignalMessageBuilder<'a> {
|
|||
from: Option<String>,
|
||||
message: Option<String>,
|
||||
attachments_urls: Vec<String>,
|
||||
mentions: Vec<(usize, usize, String)>, // TODO Add type
|
||||
target: Option<&'a String>,
|
||||
}
|
||||
|
||||
|
@ -22,16 +23,28 @@ impl<'b> SignalMessageBuilder<'b> {
|
|||
self.from = Some(from);
|
||||
}
|
||||
|
||||
pub fn attach(&mut self, attach: Vec<String>) {
|
||||
self.attachments_urls.extend_from_slice(&attach);
|
||||
pub fn attach(&mut self, attach: &Vec<String>) {
|
||||
self.attachments_urls.extend_from_slice(attach);
|
||||
}
|
||||
|
||||
pub fn mention(&mut self, mentions: &Vec<(usize, usize, String)>) {
|
||||
self.mentions.extend_from_slice(mentions);
|
||||
}
|
||||
|
||||
pub fn target(&mut self, channel: Option<&'b String>) {
|
||||
self.target = channel;
|
||||
}
|
||||
|
||||
pub fn build(self) -> Option<(&'b String, String)>
|
||||
pub fn build(mut self) -> Option<(&'b String, String)>
|
||||
{
|
||||
self.mentions.sort_by(|(pos1, _, _), (pos2, _, _)| pos1.cmp(pos2));
|
||||
self.message.as_mut().map(|message| {
|
||||
let mut offset: usize = 0;
|
||||
for (pos, len, name) in self.mentions.into_iter() {
|
||||
message.replace_range((pos + offset)..(pos + offset + len), &name);
|
||||
offset += len;
|
||||
}
|
||||
});
|
||||
let attachments_text = self.attachments_urls.join(", ");
|
||||
(match (&self.message, attachments_text.len()) {
|
||||
(None, 0) => None,
|
||||
|
@ -107,7 +120,7 @@ impl<'a> Bridge<'a> {
|
|||
log::warn!("droped attachment: {a}");
|
||||
}
|
||||
}
|
||||
result.attach(attachments_urls);
|
||||
result.attach(&attachments_urls);
|
||||
};
|
||||
if let Some(Value::String(text)) = message.get("message") {
|
||||
result.message(text.clone());
|
||||
|
|
Loading…
Reference in a new issue